Skip to content

Add return types - batch 5/n #42509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add return types - batch 5/n
  • Loading branch information
nicolas-grekas committed Aug 13, 2021
commit 00f08e4b9d88a23ae162e3b8c58df9e56e577e34
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ public function removeSubscriber(EventSubscriberInterface $subscriber)
/**
* {@inheritdoc}
*/
public function getListeners(string $eventName = null)
public function getListeners(string $eventName = null): array
{
return $this->dispatcher->getListeners($eventName);
}

/**
* {@inheritdoc}
*/
public function getListenerPriority(string $eventName, callable|array $listener)
public function getListenerPriority(string $eventName, callable|array $listener): ?int
{
// we might have wrapped listeners for the event (if called while dispatching)
// in that case get the priority by wrapper
Expand All @@ -118,7 +118,7 @@ public function getListenerPriority(string $eventName, callable|array $listener)
/**
* {@inheritdoc}
*/
public function hasListeners(string $eventName = null)
public function hasListeners(string $eventName = null): bool
{
return $this->dispatcher->hasListeners($eventName);
}
Expand Down Expand Up @@ -163,10 +163,7 @@ public function dispatch(object $event, string $eventName = null): object
return $event;
}

/**
* @return array
*/
public function getCalledListeners(Request $request = null)
public function getCalledListeners(Request $request = null): array
{
if (null === $this->callStack) {
return [];
Expand All @@ -184,10 +181,7 @@ public function getCalledListeners(Request $request = null)
return $called;
}

/**
* @return array
*/
public function getNotCalledListeners(Request $request = null)
public function getNotCalledListeners(Request $request = null): array
{
try {
$allListeners = $this->getListeners();
Expand Down Expand Up @@ -255,10 +249,8 @@ public function reset()
*
* @param string $method The method name
* @param array $arguments The method arguments
*
* @return mixed
*/
public function __call(string $method, array $arguments)
public function __call(string $method, array $arguments): mixed
{
return $this->dispatcher->{$method}(...$arguments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RegisterListenersPass implements CompilerPassInterface
/**
* @return $this
*/
public function setHotPathEvents(array $hotPathEvents)
public function setHotPathEvents(array $hotPathEvents): static
{
$this->hotPathEvents = array_flip($hotPathEvents);

Expand All @@ -41,7 +41,7 @@ public function setHotPathEvents(array $hotPathEvents)
/**
* @return $this
*/
public function setNoPreloadEvents(array $noPreloadEvents): self
public function setNoPreloadEvents(array $noPreloadEvents): static
{
$this->noPreloadEvents = array_flip($noPreloadEvents);

Expand Down
6 changes: 3 additions & 3 deletions src/Symfony/Component/EventDispatcher/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function dispatch(object $event, string $eventName = null): object
/**
* {@inheritdoc}
*/
public function getListeners(string $eventName = null)
public function getListeners(string $eventName = null): array
{
if (null !== $eventName) {
if (empty($this->listeners[$eventName])) {
Expand All @@ -91,7 +91,7 @@ public function getListeners(string $eventName = null)
/**
* {@inheritdoc}
*/
public function getListenerPriority(string $eventName, callable|array $listener)
public function getListenerPriority(string $eventName, callable|array $listener): ?int
{
if (empty($this->listeners[$eventName])) {
return null;
Expand Down Expand Up @@ -120,7 +120,7 @@ public function getListenerPriority(string $eventName, callable|array $listener)
/**
* {@inheritdoc}
*/
public function hasListeners(string $eventName = null)
public function hasListeners(string $eventName = null): bool
{
if (null !== $eventName) {
return !empty($this->listeners[$eventName]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function removeSubscriber(EventSubscriberInterface $subscriber);
*
* @return array The event listeners for the specified event, or all event listeners by event name
*/
public function getListeners(string $eventName = null);
public function getListeners(string $eventName = null): array;

/**
* Gets the listener priority for a specific event.
Expand All @@ -59,12 +59,12 @@ public function getListeners(string $eventName = null);
*
* @return int|null The event listener priority
*/
public function getListenerPriority(string $eventName, callable $listener);
public function getListenerPriority(string $eventName, callable $listener): ?int;

/**
* Checks whether an event has any registered listeners.
*
* @return bool true if the specified event has any listeners, false otherwise
*/
public function hasListeners(string $eventName = null);
public function hasListeners(string $eventName = null): bool;
}
16 changes: 6 additions & 10 deletions src/Symfony/Component/EventDispatcher/GenericEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(mixed $subject = null, array $arguments = [])
*
* @return mixed The observer subject
*/
public function getSubject()
public function getSubject(): mixed
{
return $this->subject;
}
Expand All @@ -54,7 +54,7 @@ public function getSubject()
*
* @throws \InvalidArgumentException if key is not found
*/
public function getArgument(string $key)
public function getArgument(string $key): mixed
{
if ($this->hasArgument($key)) {
return $this->arguments[$key];
Expand All @@ -68,7 +68,7 @@ public function getArgument(string $key)
*
* @return $this
*/
public function setArgument(string $key, mixed $value)
public function setArgument(string $key, mixed $value): static
{
$this->arguments[$key] = $value;

Expand All @@ -77,10 +77,8 @@ public function setArgument(string $key, mixed $value)

/**
* Getter for all arguments.
*
* @return array
*/
public function getArguments()
public function getArguments(): array
{
return $this->arguments;
}
Expand All @@ -90,7 +88,7 @@ public function getArguments()
*
* @return $this
*/
public function setArguments(array $args = [])
public function setArguments(array $args = []): static
{
$this->arguments = $args;

Expand All @@ -99,10 +97,8 @@ public function setArguments(array $args = [])

/**
* Has argument.
*
* @return bool
*/
public function hasArgument(string $key)
public function hasArgument(string $key): bool
{
return \array_key_exists($key, $this->arguments);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,23 @@ public function removeSubscriber(EventSubscriberInterface $subscriber)
/**
* {@inheritdoc}
*/
public function getListeners(string $eventName = null)
public function getListeners(string $eventName = null): array
{
return $this->dispatcher->getListeners($eventName);
}

/**
* {@inheritdoc}
*/
public function getListenerPriority(string $eventName, callable|array $listener)
public function getListenerPriority(string $eventName, callable|array $listener): ?int
{
return $this->dispatcher->getListenerPriority($eventName, $listener);
}

/**
* {@inheritdoc}
*/
public function hasListeners(string $eventName = null)
public function hasListeners(string $eventName = null): bool
{
return $this->dispatcher->hasListeners($eventName);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Symfony/Component/ExpressionLanguage/Compiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function getFunction(string $name)
*
* @return string The PHP code
*/
public function getSource()
public function getSource(): string
{
return $this->source;
}
Expand All @@ -55,7 +55,7 @@ public function reset()
*
* @return $this
*/
public function compile(Node\Node $node)
public function compile(Node\Node $node): static
{
$node->compile($this);

Expand All @@ -80,7 +80,7 @@ public function subcompile(Node\Node $node)
*
* @return $this
*/
public function raw(string $string)
public function raw(string $string): static
{
$this->source .= $string;

Expand All @@ -92,7 +92,7 @@ public function raw(string $string)
*
* @return $this
*/
public function string(string $value)
public function string(string $value): static
{
$this->source .= sprintf('"%s"', addcslashes($value, "\0\t\"\$\\"));

Expand All @@ -104,7 +104,7 @@ public function string(string $value)
*
* @return $this
*/
public function repr(mixed $value)
public function repr(mixed $value): static
{
if (\is_int($value) || \is_float($value)) {
if (false !== $locale = setlocale(\LC_NUMERIC, 0)) {
Expand Down
19 changes: 4 additions & 15 deletions src/Symfony/Component/ExpressionLanguage/ExpressionFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,17 @@ public function __construct(string $name, callable $compiler, callable $evaluato
$this->evaluator = $evaluator instanceof \Closure ? $evaluator : \Closure::fromCallable($evaluator);
}

/**
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}

/**
* @return \Closure
*/
public function getCompiler()
public function getCompiler(): \Closure
{
return $this->compiler;
}

/**
* @return \Closure
*/
public function getEvaluator()
public function getEvaluator(): \Closure
{
return $this->evaluator;
}
Expand All @@ -75,13 +66,11 @@ public function getEvaluator()
*
* @param string|null $expressionFunctionName The expression function name (default: same than the PHP function name)
*
* @return self
*
* @throws \InvalidArgumentException if given PHP function name does not exist
* @throws \InvalidArgumentException if given PHP function name is in namespace
* and expression function name is not defined
*/
public static function fromPhp(string $phpFunctionName, string $expressionFunctionName = null)
public static function fromPhp(string $phpFunctionName, string $expressionFunctionName = null): self
{
$phpFunctionName = ltrim($phpFunctionName, '\\');
if (!\function_exists($phpFunctionName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(CacheItemPoolInterface $cache = null, array $provide
*
* @return string The compiled PHP source code
*/
public function compile(Expression|string $expression, array $names = [])
public function compile(Expression|string $expression, array $names = []): string
{
return $this->getCompiler()->compile($this->parse($expression, $names)->getNodes())->getSource();
}
Expand All @@ -58,17 +58,15 @@ public function compile(Expression|string $expression, array $names = [])
*
* @return mixed The result of the evaluation of the expression
*/
public function evaluate(Expression|string $expression, array $values = [])
public function evaluate(Expression|string $expression, array $values = []): mixed
{
return $this->parse($expression, array_keys($values))->getNodes()->evaluate($this->functions, $values);
}

/**
* Parses an expression.
*
* @return ParsedExpression
*/
public function parse(Expression|string $expression, array $names)
public function parse(Expression|string $expression, array $names): ParsedExpression
{
if ($expression instanceof ParsedExpression) {
return $expression;
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/ExpressionLanguage/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ class Lexer
/**
* Tokenizes an expression.
*
* @return TokenStream
*
* @throws SyntaxError
*/
public function tokenize(string $expression)
public function tokenize(string $expression): TokenStream
{
$expression = str_replace(["\r", "\n", "\t", "\v", "\f"], ' ', $expression);
$cursor = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/ExpressionLanguage/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function __construct(array $functions)
*
* @throws SyntaxError
*/
public function parse(TokenStream $stream, array $names = [])
public function parse(TokenStream $stream, array $names = []): Node\Node
{
$this->lint = false;

Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/ExpressionLanguage/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@ public function __toString(): string

/**
* Tests the current token for a type and/or a value.
*
* @return bool
*/
public function test(string $type, string $value = null)
public function test(string $type, string $value = null): bool
{
return $this->type === $type && (null === $value || $this->value == $value);
}
Expand Down
4 changes: 1 addition & 3 deletions src/Symfony/Component/ExpressionLanguage/TokenStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,8 @@ public function expect(string $type, string $value = null, string $message = nul

/**
* Checks if end of stream was reached.
*
* @return bool
*/
public function isEOF()
public function isEOF(): bool
{
return Token::EOF_TYPE === $this->current->type;
}
Expand Down
Loading