Add scalar typehints/return types on final/internal/private code

This commit is contained in:
Robin Chalas 2017-08-05 16:43:05 +02:00
parent 79cd7069a3
commit 6ce70e4bf9
86 changed files with 311 additions and 744 deletions

View File

@ -82,7 +82,7 @@ class IdReader
* @return bool Returns `true` if the class has a single-column ID and
* `false` otherwise.
*/
public function isSingleId()
public function isSingleId(): bool
{
return $this->singleId;
}
@ -93,7 +93,7 @@ class IdReader
* @return bool Returns `true` if the class has a single-column integer ID
* and `false` otherwise.
*/
public function isIntId()
public function isIntId(): bool
{
return $this->intId;
}
@ -138,7 +138,7 @@ class IdReader
*
* @return string The name of the ID field
*/
public function getIdField()
public function getIdField(): string
{
return $this->idField;
}

View File

@ -56,12 +56,12 @@ final class WrappedListener implements ListenerInterface
return call_user_func_array(array($this->listener, $method), $arguments);
}
public function getWrappedListener()
public function getWrappedListener(): ListenerInterface
{
return $this->listener;
}
public function getInfo()
public function getInfo(): array
{
if (null === $this->stub) {
$this->stub = self::$hasVarDumper ? new ClassStub(get_class($this->listener)) : get_class($this->listener);

View File

@ -29,21 +29,7 @@ final class FirewallConfig
private $listeners;
private $switchUser;
/**
* @param string $name
* @param string $userChecker
* @param string|null $requestMatcher
* @param bool $securityEnabled
* @param bool $stateless
* @param string|null $provider
* @param string|null $context
* @param string|null $entryPoint
* @param string|null $accessDeniedHandler
* @param string|null $accessDeniedUrl
* @param string[] $listeners
* @param array|null $switchUser
*/
public function __construct($name, $userChecker, $requestMatcher = null, $securityEnabled = true, $stateless = false, $provider = null, $context = null, $entryPoint = null, $accessDeniedHandler = null, $accessDeniedUrl = null, $listeners = array(), $switchUser = null)
public function __construct(string $name, string $userChecker, string $requestMatcher = null, bool $securityEnabled = true, bool $stateless = false, string $provider = null, string $context = null, string $entryPoint = null, string $accessDeniedHandler = null, string $accessDeniedUrl = null, array $listeners = array(), $switchUser = null)
{
$this->name = $name;
$this->userChecker = $userChecker;
@ -59,7 +45,7 @@ final class FirewallConfig
$this->switchUser = $switchUser;
}
public function getName()
public function getName(): string
{
return $this->name;
}
@ -68,30 +54,27 @@ final class FirewallConfig
* @return string|null The request matcher service id or null if neither the request matcher, pattern or host
* options were provided
*/
public function getRequestMatcher()
public function getRequestMatcher(): ?string
{
return $this->requestMatcher;
}
public function isSecurityEnabled()
public function isSecurityEnabled(): bool
{
return $this->securityEnabled;
}
public function allowsAnonymous()
public function allowsAnonymous(): bool
{
return in_array('anonymous', $this->listeners, true);
}
public function isStateless()
public function isStateless(): bool
{
return $this->stateless;
}
/**
* @return string|null The provider service id
*/
public function getProvider()
public function getProvider(): ?string
{
return $this->provider;
}
@ -99,55 +82,37 @@ final class FirewallConfig
/**
* @return string|null The context key (will be null if the firewall is stateless)
*/
public function getContext()
public function getContext(): ?string
{
return $this->context;
}
/**
* @return string|null The entry_point service id if configured, null otherwise
*/
public function getEntryPoint()
public function getEntryPoint(): ?string
{
return $this->entryPoint;
}
/**
* @return string The user_checker service id
*/
public function getUserChecker()
public function getUserChecker(): string
{
return $this->userChecker;
}
/**
* @return string|null The access_denied_handler service id if configured, null otherwise
*/
public function getAccessDeniedHandler()
public function getAccessDeniedHandler(): ?string
{
return $this->accessDeniedHandler;
}
/**
* @return string|null The access_denied_handler URL if configured, null otherwise
*/
public function getAccessDeniedUrl()
public function getAccessDeniedUrl(): ?string
{
return $this->accessDeniedUrl;
}
/**
* @return string[] An array of listener keys
*/
public function getListeners()
public function getListeners(): array
{
return $this->listeners;
}
/**
* @return array|null The switch_user parameters if configured, null otherwise
*/
public function getSwitchUser()
public function getSwitchUser(): ?array
{
return $this->switchUser;
}

View File

@ -18,7 +18,6 @@ use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;
@ -63,7 +62,7 @@ class FirewallMapTest extends TestCase
$firewallContext = $this->getMockBuilder(FirewallContext::class)->disableOriginalConstructor()->getMock();
$firewallConfig = new FirewallConfig('main', $this->getMockBuilder(UserCheckerInterface::class)->getMock());
$firewallConfig = new FirewallConfig('main', 'user_checker');
$firewallContext->expects($this->once())->method('getConfig')->willReturn($firewallConfig);
$listener = $this->getMockBuilder(ListenerInterface::class)->getMock();

View File

@ -81,7 +81,7 @@ abstract class FileLoader extends Loader
* @throws FileLoaderImportCircularReferenceException
* @throws FileLocatorFileNotFoundException
*/
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
public function import($resource, $type = null, bool $ignoreErrors = false, $sourceResource = null)
{
if (is_string($resource) && strlen($resource) !== $i = strcspn($resource, '*?{[')) {
$ret = array();
@ -104,7 +104,7 @@ abstract class FileLoader extends Loader
/**
* @internal
*/
protected function glob($pattern, $recursive, &$resource = null, $ignoreErrors = false)
protected function glob(string $pattern, bool $recursive, &$resource = null, bool $ignoreErrors = false)
{
if (strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
$prefix = $pattern;
@ -138,7 +138,7 @@ abstract class FileLoader extends Loader
}
}
private function doImport($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
private function doImport($resource, $type = null, bool $ignoreErrors = false, $sourceResource = null)
{
try {
$loader = $this->resolve($resource, $type);

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\Console\Event;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
@ -26,57 +25,33 @@ final class ConsoleErrorEvent extends ConsoleEvent
private $error;
private $exitCode;
public function __construct(InputInterface $input, OutputInterface $output, $error, Command $command = null)
public function __construct(InputInterface $input, OutputInterface $output, \Throwable $error, Command $command = null)
{
parent::__construct($command, $input, $output);
$this->setError($error);
}
/**
* Returns the thrown error/exception.
*
* @return \Throwable
*/
public function getError()
{
return $this->error;
}
/**
* Replaces the thrown error/exception.
*
* @param \Throwable $error
*/
public function setError($error)
{
if (!$error instanceof \Throwable && !$error instanceof \Exception) {
throw new InvalidArgumentException(sprintf('The error passed to ConsoleErrorEvent must be an instance of \Throwable or \Exception, "%s" was passed instead.', is_object($error) ? get_class($error) : gettype($error)));
}
$this->error = $error;
}
/**
* Sets the exit code.
*
* @param int $exitCode The command exit code
*/
public function setExitCode($exitCode)
public function getError(): \Throwable
{
$this->exitCode = (int) $exitCode;
return $this->error;
}
public function setError(\Throwable $error): void
{
$this->error = $error;
}
public function setExitCode(int $exitCode): void
{
$this->exitCode = $exitCode;
$r = new \ReflectionProperty($this->error, 'code');
$r->setAccessible(true);
$r->setValue($this->error, $this->exitCode);
}
/**
* Gets the exit code.
*
* @return int The command exit code
*/
public function getExitCode()
public function getExitCode(): int
{
return null !== $this->exitCode ? $this->exitCode : ($this->error->getCode() ?: 1);
}

View File

@ -55,7 +55,7 @@ final class ProgressBar
* @param OutputInterface $output An OutputInterface instance
* @param int $max Maximum steps (0 if unknown)
*/
public function __construct(OutputInterface $output, $max = 0)
public function __construct(OutputInterface $output, int $max = 0)
{
if ($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
@ -84,7 +84,7 @@ final class ProgressBar
* @param string $name The placeholder name (including the delimiter char like %)
* @param callable $callable A PHP callable
*/
public static function setPlaceholderFormatterDefinition($name, callable $callable)
public static function setPlaceholderFormatterDefinition(string $name, callable $callable): void
{
if (!self::$formatters) {
self::$formatters = self::initPlaceholderFormatters();
@ -100,7 +100,7 @@ final class ProgressBar
*
* @return callable|null A PHP callable
*/
public static function getPlaceholderFormatterDefinition($name)
public static function getPlaceholderFormatterDefinition(string $name): ?callable
{
if (!self::$formatters) {
self::$formatters = self::initPlaceholderFormatters();
@ -117,7 +117,7 @@ final class ProgressBar
* @param string $name The format name
* @param string $format A format string
*/
public static function setFormatDefinition($name, $format)
public static function setFormatDefinition(string $name, string $format): void
{
if (!self::$formats) {
self::$formats = self::initFormats();
@ -133,7 +133,7 @@ final class ProgressBar
*
* @return string|null A format string
*/
public static function getFormatDefinition($name)
public static function getFormatDefinition(string $name): ?string
{
if (!self::$formats) {
self::$formats = self::initFormats();
@ -152,102 +152,57 @@ final class ProgressBar
* @param string $message The text to associate with the placeholder
* @param string $name The name of the placeholder
*/
public function setMessage($message, $name = 'message')
public function setMessage(string $message, string $name = 'message')
{
$this->messages[$name] = $message;
}
public function getMessage($name = 'message')
public function getMessage(string $name = 'message')
{
return $this->messages[$name];
}
/**
* Gets the progress bar start time.
*
* @return int The progress bar start time
*/
public function getStartTime()
public function getStartTime(): int
{
return $this->startTime;
}
/**
* Gets the progress bar maximal steps.
*
* @return int The progress bar max steps
*/
public function getMaxSteps()
public function getMaxSteps(): int
{
return $this->max;
}
/**
* Gets the current step position.
*
* @return int The progress bar step
*/
public function getProgress()
public function getProgress(): int
{
return $this->step;
}
/**
* Gets the progress bar step width.
*
* @return int The progress bar step width
*/
private function getStepWidth()
private function getStepWidth(): int
{
return $this->stepWidth;
}
/**
* Gets the current progress bar percent.
*
* @return float The current progress bar percent
*/
public function getProgressPercent()
public function getProgressPercent(): float
{
return $this->percent;
}
/**
* Sets the progress bar width.
*
* @param int $size The progress bar size
*/
public function setBarWidth($size)
public function setBarWidth(int $size)
{
$this->barWidth = max(1, (int) $size);
$this->barWidth = max(1, $size);
}
/**
* Gets the progress bar width.
*
* @return int The progress bar size
*/
public function getBarWidth()
public function getBarWidth(): int
{
return $this->barWidth;
}
/**
* Sets the bar character.
*
* @param string $char A character
*/
public function setBarCharacter($char)
public function setBarCharacter(string $char)
{
$this->barChar = $char;
}
/**
* Gets the bar character.
*
* @return string A character
*/
public function getBarCharacter()
public function getBarCharacter(): string
{
if (null === $this->barChar) {
return $this->max ? '=' : $this->emptyBarChar;
@ -256,52 +211,27 @@ final class ProgressBar
return $this->barChar;
}
/**
* Sets the empty bar character.
*
* @param string $char A character
*/
public function setEmptyBarCharacter($char)
public function setEmptyBarCharacter(string $char)
{
$this->emptyBarChar = $char;
}
/**
* Gets the empty bar character.
*
* @return string A character
*/
public function getEmptyBarCharacter()
public function getEmptyBarCharacter(): string
{
return $this->emptyBarChar;
}
/**
* Sets the progress bar character.
*
* @param string $char A character
*/
public function setProgressCharacter($char)
public function setProgressCharacter(string $char)
{
$this->progressChar = $char;
}
/**
* Gets the progress bar character.
*
* @return string A character
*/
public function getProgressCharacter()
public function getProgressCharacter(): string
{
return $this->progressChar;
}
/**
* Sets the progress bar format.
*
* @param string $format The format
*/
public function setFormat($format)
public function setFormat(string $format)
{
$this->format = null;
$this->internalFormat = $format;
@ -312,9 +242,9 @@ final class ProgressBar
*
* @param int|float $freq The frequency in steps
*/
public function setRedrawFrequency($freq)
public function setRedrawFrequency(int $freq)
{
$this->redrawFreq = max((int) $freq, 1);
$this->redrawFreq = max($freq, 1);
}
/**
@ -322,7 +252,7 @@ final class ProgressBar
*
* @param int|null $max Number of steps to complete the bar (0 if indeterminate), null to leave unchanged
*/
public function start($max = null)
public function start(int $max = null)
{
$this->startTime = time();
$this->step = 0;
@ -340,7 +270,7 @@ final class ProgressBar
*
* @param int $step Number of steps to advance
*/
public function advance($step = 1)
public function advance(int $step = 1)
{
$this->setProgress($this->step + $step);
}
@ -350,20 +280,13 @@ final class ProgressBar
*
* @param bool $overwrite
*/
public function setOverwrite($overwrite)
public function setOverwrite(bool $overwrite)
{
$this->overwrite = (bool) $overwrite;
$this->overwrite = $overwrite;
}
/**
* Sets the current progress.
*
* @param int $step The current progress
*/
public function setProgress($step)
public function setProgress(int $step)
{
$step = (int) $step;
if ($this->max && $step > $this->max) {
$this->max = $step;
} elseif ($step < 0) {
@ -382,7 +305,7 @@ final class ProgressBar
/**
* Finishes the progress output.
*/
public function finish()
public function finish(): void
{
if (!$this->max) {
$this->max = $this->step;
@ -399,7 +322,7 @@ final class ProgressBar
/**
* Outputs the current progress string.
*/
public function display()
public function display(): void
{
if (OutputInterface::VERBOSITY_QUIET === $this->output->getVerbosity()) {
return;
@ -419,7 +342,7 @@ final class ProgressBar
* while a progress bar is running.
* Call display() to show the progress bar again.
*/
public function clear()
public function clear(): void
{
if (!$this->overwrite) {
return;
@ -432,12 +355,7 @@ final class ProgressBar
$this->overwrite('');
}
/**
* Sets the progress bar format.
*
* @param string $format The format
*/
private function setRealFormat($format)
private function setRealFormat(string $format)
{
// try to use the _nomax variant if available
if (!$this->max && null !== self::getFormatDefinition($format.'_nomax')) {
@ -451,15 +369,10 @@ final class ProgressBar
$this->formatLineCount = substr_count($this->format, "\n");
}
/**
* Sets the progress bar maximal steps.
*
* @param int $max The progress bar max steps
*/
private function setMaxSteps($max)
private function setMaxSteps(int $max)
{
$this->max = max(0, (int) $max);
$this->stepWidth = $this->max ? Helper::strlen($this->max) : 4;
$this->max = max(0, $max);
$this->stepWidth = $this->max ? Helper::strlen((string) $this->max) : 4;
}
/**
@ -467,7 +380,7 @@ final class ProgressBar
*
* @param string $message The message
*/
private function overwrite($message)
private function overwrite(string $message): void
{
if ($this->overwrite) {
if (!$this->firstRun) {
@ -491,7 +404,7 @@ final class ProgressBar
$this->output->write($message);
}
private function determineBestFormat()
private function determineBestFormat(): string
{
switch ($this->output->getVerbosity()) {
// OutputInterface::VERBOSITY_QUIET: display is disabled anyway
@ -506,7 +419,7 @@ final class ProgressBar
}
}
private static function initPlaceholderFormatters()
private static function initPlaceholderFormatters(): array
{
return array(
'bar' => function (ProgressBar $bar, OutputInterface $output) {
@ -563,7 +476,7 @@ final class ProgressBar
);
}
private static function initFormats()
private static function initFormats(): array
{
return array(
'normal' => ' %current%/%max% [%bar%] %percent:3s%%',
@ -580,10 +493,7 @@ final class ProgressBar
);
}
/**
* @return string
*/
private function buildLine()
private function buildLine(): string
{
$regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i";
$callback = function ($matches) {

View File

@ -344,10 +344,7 @@ class SymfonyStyle extends OutputStyle
return new self($this->input, $this->getErrorOutput());
}
/**
* @return ProgressBar
*/
private function getProgressBar()
private function getProgressBar(): ProgressBar
{
if (!$this->progressBar) {
throw new RuntimeException('The ProgressBar is not started.');
@ -356,18 +353,20 @@ class SymfonyStyle extends OutputStyle
return $this->progressBar;
}
private function autoPrependBlock()
private function autoPrependBlock(): void
{
$chars = substr(str_replace(PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2);
if (!isset($chars[0])) {
return $this->newLine(); //empty history, so we should start with a new line.
$this->newLine(); //empty history, so we should start with a new line.
return;
}
//Prepend new line for each non LF chars (This means no blank line was output before)
$this->newLine(2 - substr_count($chars, "\n"));
}
private function autoPrependText()
private function autoPrependText(): void
{
$fetched = $this->bufferedOutput->fetch();
//Prepend new line if last char isn't EOL:
@ -376,7 +375,7 @@ class SymfonyStyle extends OutputStyle
}
}
private function reduceBuffer($messages)
private function reduceBuffer($messages): array
{
// We need to know if the two last chars are PHP_EOL
// Preserve the last 4 chars inserted (PHP_EOL on windows is two chars) in the history buffer
@ -385,7 +384,7 @@ class SymfonyStyle extends OutputStyle
}, array_merge(array($this->bufferedOutput->fetch()), (array) $messages));
}
private function createBlock($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = false)
private function createBlock(iterable $messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = false)
{
$indentLength = 0;
$prefixLength = Helper::strlenWithoutDecoration($this->getFormatter(), $prefix);

View File

@ -31,7 +31,7 @@ abstract class AbstractNode implements NodeInterface
/**
* @return string
*/
public function getNodeName()
public function getNodeName(): string
{
if (null === $this->nodeName) {
$this->nodeName = preg_replace('~.*\\\\([^\\\\]+)Node$~', '$1', get_called_class());

View File

@ -107,7 +107,7 @@ class AttributeNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function getSpecificity()
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
}
@ -115,7 +115,7 @@ class AttributeNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function __toString()
public function __toString(): string
{
$attribute = $this->namespace ? $this->namespace.'|'.$this->attribute : $this->attribute;

View File

@ -62,7 +62,7 @@ class ClassNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function getSpecificity()
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
}
@ -70,7 +70,7 @@ class ClassNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function __toString()
public function __toString(): string
{
return sprintf('%s[%s.%s]', $this->getNodeName(), $this->selector, $this->name);
}

View File

@ -77,7 +77,7 @@ class CombinedSelectorNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function getSpecificity()
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());
}
@ -85,7 +85,7 @@ class CombinedSelectorNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function __toString()
public function __toString(): string
{
$combinator = ' ' === $this->combinator ? '<followed>' : $this->combinator;

View File

@ -62,7 +62,7 @@ class ElementNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function getSpecificity()
public function getSpecificity(): Specificity
{
return new Specificity(0, 0, $this->element ? 1 : 0);
}
@ -70,7 +70,7 @@ class ElementNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function __toString()
public function __toString(): string
{
$element = $this->element ?: '*';

View File

@ -79,7 +79,7 @@ class FunctionNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function getSpecificity()
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
}
@ -87,7 +87,7 @@ class FunctionNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function __toString()
public function __toString(): string
{
$arguments = implode(', ', array_map(function (Token $token) {
return "'".$token->getValue()."'";

View File

@ -62,7 +62,7 @@ class HashNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function getSpecificity()
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus(new Specificity(1, 0, 0));
}
@ -70,7 +70,7 @@ class HashNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function __toString()
public function __toString(): string
{
return sprintf('%s[%s#%s]', $this->getNodeName(), $this->selector, $this->id);
}

View File

@ -62,7 +62,7 @@ class NegationNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function getSpecificity()
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus($this->subSelector->getSpecificity());
}
@ -70,7 +70,7 @@ class NegationNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function __toString()
public function __toString(): string
{
return sprintf('%s[%s:not(%s)]', $this->getNodeName(), $this->selector, $this->subSelector);
}

View File

@ -23,24 +23,9 @@ namespace Symfony\Component\CssSelector\Node;
*/
interface NodeInterface
{
/**
* Returns node's name.
*
* @return string
*/
public function getNodeName();
public function getNodeName(): string;
/**
* Returns node's specificity.
*
* @return Specificity
*/
public function getSpecificity();
public function getSpecificity(): Specificity;
/**
* Returns node's string representation.
*
* @return string
*/
public function __toString();
public function __toString(): string;
}

View File

@ -62,7 +62,7 @@ class PseudoNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function getSpecificity()
public function getSpecificity(): Specificity
{
return $this->selector->getSpecificity()->plus(new Specificity(0, 1, 0));
}
@ -70,7 +70,7 @@ class PseudoNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function __toString()
public function __toString(): string
{
return sprintf('%s[%s:%s]', $this->getNodeName(), $this->selector, $this->identifier);
}

View File

@ -62,7 +62,7 @@ class SelectorNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function getSpecificity()
public function getSpecificity(): Specificity
{
return $this->tree->getSpecificity()->plus(new Specificity(0, 0, $this->pseudoElement ? 1 : 0));
}
@ -70,7 +70,7 @@ class SelectorNode extends AbstractNode
/**
* {@inheritdoc}
*/
public function __toString()
public function __toString(): string
{
return sprintf('%s[%s%s]', $this->getNodeName(), $this->tree, $this->pseudoElement ? '::'.$this->pseudoElement : '');
}

View File

@ -44,36 +44,19 @@ class Specificity
*/
private $c;
/**
* Constructor.
*
* @param int $a
* @param int $b
* @param int $c
*/
public function __construct($a, $b, $c)
public function __construct(int $a, int $b, int $c)
{
$this->a = $a;
$this->b = $b;
$this->c = $c;
}
/**
* @param Specificity $specificity
*
* @return self
*/
public function plus(Specificity $specificity)
public function plus(Specificity $specificity): Specificity
{
return new self($this->a + $specificity->a, $this->b + $specificity->b, $this->c + $specificity->c);
}
/**
* Returns global specificity value.
*
* @return int
*/
public function getValue()
public function getValue(): int
{
return $this->a * self::A_FACTOR + $this->b * self::B_FACTOR + $this->c * self::C_FACTOR;
}

View File

@ -29,7 +29,7 @@ class CommentHandler implements HandlerInterface
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream)
public function handle(Reader $reader, TokenStream $stream): bool
{
if ('/*' !== $reader->getSubstring(2)) {
return false;

View File

@ -32,5 +32,5 @@ interface HandlerInterface
*
* @return bool
*/
public function handle(Reader $reader, TokenStream $stream);
public function handle(Reader $reader, TokenStream $stream): bool;
}

View File

@ -52,7 +52,7 @@ class HashHandler implements HandlerInterface
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream)
public function handle(Reader $reader, TokenStream $stream): bool
{
$match = $reader->findPattern($this->patterns->getHashPattern());

View File

@ -52,7 +52,7 @@ class IdentifierHandler implements HandlerInterface
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream)
public function handle(Reader $reader, TokenStream $stream): bool
{
$match = $reader->findPattern($this->patterns->getIdentifierPattern());

View File

@ -44,7 +44,7 @@ class NumberHandler implements HandlerInterface
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream)
public function handle(Reader $reader, TokenStream $stream): bool
{
$match = $reader->findPattern($this->patterns->getNumberPattern());

View File

@ -54,7 +54,7 @@ class StringHandler implements HandlerInterface
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream)
public function handle(Reader $reader, TokenStream $stream): bool
{
$quote = $reader->getSubstring(1);

View File

@ -30,7 +30,7 @@ class WhitespaceHandler implements HandlerInterface
/**
* {@inheritdoc}
*/
public function handle(Reader $reader, TokenStream $stream)
public function handle(Reader $reader, TokenStream $stream): bool
{
$match = $reader->findPattern('~^[ \t\r\n\f]+~');

View File

@ -45,7 +45,7 @@ class Parser implements ParserInterface
/**
* {@inheritdoc}
*/
public function parse($source)
public function parse(string $source): array
{
$reader = new Reader($source);
$stream = $this->tokenizer->tokenize($reader);
@ -102,14 +102,7 @@ class Parser implements ParserInterface
);
}
/**
* Parses selector nodes.
*
* @param TokenStream $stream
*
* @return array
*/
private function parseSelectorList(TokenStream $stream)
private function parseSelectorList(TokenStream $stream): array
{
$stream->skipWhitespace();
$selectors = array();
@ -128,16 +121,7 @@ class Parser implements ParserInterface
return $selectors;
}
/**
* Parses next selector or combined node.
*
* @param TokenStream $stream
*
* @return Node\SelectorNode
*
* @throws SyntaxErrorException
*/
private function parserSelectorNode(TokenStream $stream)
private function parserSelectorNode(TokenStream $stream): Node\SelectorNode
{
list($result, $pseudoElement) = $this->parseSimpleSelector($stream);
@ -291,14 +275,7 @@ class Parser implements ParserInterface
return array($result, $pseudoElement);
}
/**
* Parses next element node.
*
* @param TokenStream $stream
*
* @return Node\ElementNode
*/
private function parseElementNode(TokenStream $stream)
private function parseElementNode(TokenStream $stream): Node\ElementNode
{
$peek = $stream->getPeek();
@ -324,17 +301,7 @@ class Parser implements ParserInterface
return new Node\ElementNode($namespace, $element);
}
/**
* Parses next attribute node.
*
* @param Node\NodeInterface $selector
* @param TokenStream $stream
*
* @return Node\AttributeNode
*
* @throws SyntaxErrorException
*/
private function parseAttributeNode(Node\NodeInterface $selector, TokenStream $stream)
private function parseAttributeNode(Node\NodeInterface $selector, TokenStream $stream): Node\AttributeNode
{
$stream->skipWhitespace();
$attribute = $stream->getNextIdentifierOrStar();

View File

@ -32,5 +32,5 @@ interface ParserInterface
*
* @return SelectorNode[]
*/
public function parse($source);
public function parse(string $source): array;
}

View File

@ -31,7 +31,7 @@ class ClassParser implements ParserInterface
/**
* {@inheritdoc}
*/
public function parse($source)
public function parse(string $source): array
{
// Matches an optional namespace, optional element, and required class
// $source = 'test|input.ab6bd_field';

View File

@ -30,7 +30,7 @@ class ElementParser implements ParserInterface
/**
* {@inheritdoc}
*/
public function parse($source)
public function parse(string $source): array
{
// Matches an optional namespace, required element or `*`
// $source = 'testns|testel';

View File

@ -34,7 +34,7 @@ class EmptyStringParser implements ParserInterface
/**
* {@inheritdoc}
*/
public function parse($source)
public function parse(string $source): array
{
// Matches an empty string
if ($source == '') {

View File

@ -31,7 +31,7 @@ class HashParser implements ParserInterface
/**
* {@inheritdoc}
*/
public function parse($source)
public function parse(string $source): array
{
// Matches an optional namespace, optional element, and required id
// $source = 'test|input#ab6bd_field';

View File

@ -47,7 +47,7 @@ class Token
private $position;
/**
* @param int $type
* @param string $type
* @param string $value
* @param int $position
*/
@ -82,20 +82,12 @@ class Token
return $this->position;
}
/**
* @return bool
*/
public function isFileEnd()
public function isFileEnd(): bool
{
return self::TYPE_FILE_END === $this->type;
}
/**
* @param array $values
*
* @return bool
*/
public function isDelimiter(array $values = array())
public function isDelimiter(array $values = array()): bool
{
if (self::TYPE_DELIMITER !== $this->type) {
return false;
@ -108,50 +100,32 @@ class Token
return in_array($this->value, $values);
}
/**
* @return bool
*/
public function isWhitespace()
public function isWhitespace(): bool
{
return self::TYPE_WHITESPACE === $this->type;
}
/**
* @return bool
*/
public function isIdentifier()
public function isIdentifier(): bool
{
return self::TYPE_IDENTIFIER === $this->type;
}
/**
* @return bool
*/
public function isHash()
public function isHash(): bool
{
return self::TYPE_HASH === $this->type;
}
/**
* @return bool
*/
public function isNumber()
public function isNumber(): bool
{
return self::TYPE_NUMBER === $this->type;
}
/**
* @return bool
*/
public function isString()
public function isString(): bool
{
return self::TYPE_STRING === $this->type;
}
/**
* @return string
*/
public function __toString()
public function __toString(): string
{
if ($this->value) {
return sprintf('<%s "%s" at %s>', $this->type, $this->value, $this->position);

View File

@ -28,44 +28,26 @@ class TokenizerEscaping
*/
private $patterns;
/**
* @param TokenizerPatterns $patterns
*/
public function __construct(TokenizerPatterns $patterns)
{
$this->patterns = $patterns;
}
/**
* @param string $value
*
* @return string
*/
public function escapeUnicode($value)
public function escapeUnicode(string $value): string
{
$value = $this->replaceUnicodeSequences($value);
return preg_replace($this->patterns->getSimpleEscapePattern(), '$1', $value);
}
/**
* @param string $value
*
* @return string
*/
public function escapeUnicodeAndNewLine($value)
public function escapeUnicodeAndNewLine(string $value): string
{
$value = preg_replace($this->patterns->getNewLineEscapePattern(), '', $value);
return $this->escapeUnicode($value);
}
/**
* @param string $value
*
* @return string
*/
private function replaceUnicodeSequences($value)
private function replaceUnicodeSequences(string $value): string
{
return preg_replace_callback($this->patterns->getUnicodeEscapePattern(), function ($match) {
$c = hexdec($match[1]);

View File

@ -28,7 +28,7 @@ class CombinationExtension extends AbstractExtension
/**
* {@inheritdoc}
*/
public function getCombinationTranslators()
public function getCombinationTranslators(): array
{
return array(
' ' => array($this, 'translateDescendant'),
@ -44,7 +44,7 @@ class CombinationExtension extends AbstractExtension
*
* @return XPathExpr
*/
public function translateDescendant(XPathExpr $xpath, XPathExpr $combinedXpath)
public function translateDescendant(XPathExpr $xpath, XPathExpr $combinedXpath): XPathExpr
{
return $xpath->join('/descendant-or-self::*/', $combinedXpath);
}

View File

@ -83,12 +83,7 @@ class Translator implements TranslatorInterface
;
}
/**
* @param string $element
*
* @return string
*/
public static function getXpathLiteral($element)
public static function getXpathLiteral(string $element): string
{
if (false === strpos($element, "'")) {
return "'".$element."'";
@ -117,7 +112,7 @@ class Translator implements TranslatorInterface
/**
* {@inheritdoc}
*/
public function cssToXPath($cssExpr, $prefix = 'descendant-or-self::')
public function cssToXPath(string $cssExpr, string $prefix = 'descendant-or-self::'): string
{
$selectors = $this->parseSelectors($cssExpr);
@ -136,19 +131,12 @@ class Translator implements TranslatorInterface
/**
* {@inheritdoc}
*/
public function selectorToXPath(SelectorNode $selector, $prefix = 'descendant-or-self::')
public function selectorToXPath(SelectorNode $selector, string $prefix = 'descendant-or-self::'): string
{
return ($prefix ?: '').$this->nodeToXPath($selector);
}
/**
* Registers an extension.
*
* @param Extension\ExtensionInterface $extension
*
* @return $this
*/
public function registerExtension(Extension\ExtensionInterface $extension)
public function registerExtension(Extension\ExtensionInterface $extension): Translator
{
$this->extensions[$extension->getName()] = $extension;
@ -162,13 +150,9 @@ class Translator implements TranslatorInterface
}
/**
* @param string $name
*
* @return Extension\ExtensionInterface
*
* @throws ExpressionErrorException
*/
public function getExtension($name)
public function getExtension(string $name): Extension\ExtensionInterface
{
if (!isset($this->extensions[$name])) {
throw new ExpressionErrorException(sprintf('Extension "%s" not registered.', $name));
@ -177,14 +161,7 @@ class Translator implements TranslatorInterface
return $this->extensions[$name];
}
/**
* Registers a shortcut parser.
*
* @param ParserInterface $shortcut
*
* @return $this
*/
public function registerParserShortcut(ParserInterface $shortcut)
public function registerParserShortcut(ParserInterface $shortcut): Translator
{
$this->shortcutParsers[] = $shortcut;
@ -192,13 +169,9 @@ class Translator implements TranslatorInterface
}
/**
* @param NodeInterface $node
*
* @return XPathExpr
*
* @throws ExpressionErrorException
*/
public function nodeToXPath(NodeInterface $node)
public function nodeToXPath(NodeInterface $node): XPathExpr
{
if (!isset($this->nodeTranslators[$node->getNodeName()])) {
throw new ExpressionErrorException(sprintf('Node "%s" not supported.', $node->getNodeName()));
@ -208,15 +181,9 @@ class Translator implements TranslatorInterface
}
/**
* @param string $combiner
* @param NodeInterface $xpath
* @param NodeInterface $combinedXpath
*
* @return XPathExpr
*
* @throws ExpressionErrorException
*/
public function addCombination($combiner, NodeInterface $xpath, NodeInterface $combinedXpath)
public function addCombination(string $combiner, NodeInterface $xpath, NodeInterface $combinedXpath): XPathExpr
{
if (!isset($this->combinationTranslators[$combiner])) {
throw new ExpressionErrorException(sprintf('Combiner "%s" not supported.', $combiner));
@ -226,14 +193,9 @@ class Translator implements TranslatorInterface
}
/**
* @param XPathExpr $xpath
* @param FunctionNode $function
*
* @return XPathExpr
*
* @throws ExpressionErrorException
*/
public function addFunction(XPathExpr $xpath, FunctionNode $function)
public function addFunction(XPathExpr $xpath, FunctionNode $function): XPathExpr
{
if (!isset($this->functionTranslators[$function->getName()])) {
throw new ExpressionErrorException(sprintf('Function "%s" not supported.', $function->getName()));
@ -243,14 +205,9 @@ class Translator implements TranslatorInterface
}
/**
* @param XPathExpr $xpath
* @param string $pseudoClass
*
* @return XPathExpr
*
* @throws ExpressionErrorException
*/
public function addPseudoClass(XPathExpr $xpath, $pseudoClass)
public function addPseudoClass(XPathExpr $xpath, string $pseudoClass): XPathExpr
{
if (!isset($this->pseudoClassTranslators[$pseudoClass])) {
throw new ExpressionErrorException(sprintf('Pseudo-class "%s" not supported.', $pseudoClass));
@ -260,16 +217,9 @@ class Translator implements TranslatorInterface
}
/**
* @param XPathExpr $xpath
* @param string $operator
* @param string $attribute
* @param string $value
*
* @return XPathExpr
*
* @throws ExpressionErrorException
*/
public function addAttributeMatching(XPathExpr $xpath, $operator, $attribute, $value)
public function addAttributeMatching(XPathExpr $xpath, string $operator, string $attribute, $value): XPathExpr
{
if (!isset($this->attributeMatchingTranslators[$operator])) {
throw new ExpressionErrorException(sprintf('Attribute matcher operator "%s" not supported.', $operator));

View File

@ -33,7 +33,7 @@ interface TranslatorInterface
*
* @return string
*/
public function cssToXPath($cssExpr, $prefix = 'descendant-or-self::');
public function cssToXPath(string $cssExpr, string $prefix = 'descendant-or-self::'): string;
/**
* Translates a parsed selector node to an XPath expression.
@ -43,5 +43,5 @@ interface TranslatorInterface
*
* @return string
*/
public function selectorToXPath(SelectorNode $selector, $prefix = 'descendant-or-self::');
public function selectorToXPath(SelectorNode $selector, string $prefix = 'descendant-or-self::'): string;
}

View File

@ -38,13 +38,7 @@ class XPathExpr
*/
private $condition;
/**
* @param string $path
* @param string $element
* @param string $condition
* @param bool $starPrefix
*/
public function __construct($path = '', $element = '*', $condition = '', $starPrefix = false)
public function __construct(string $path = '', string $element = '*', string $condition = '', bool $starPrefix = false)
{
$this->path = $path;
$this->element = $element;
@ -55,20 +49,12 @@ class XPathExpr
}
}
/**
* @return string
*/
public function getElement()
public function getElement(): string
{
return $this->element;
}
/**
* @param $condition
*
* @return $this
*/
public function addCondition($condition)
public function addCondition(string $condition): XPathExpr
{
$this->condition = $this->condition ? sprintf('%s and (%s)', $this->condition, $condition) : $condition;
@ -78,15 +64,12 @@ class XPathExpr
/**
* @return string
*/
public function getCondition()
public function getCondition(): string
{
return $this->condition;
}
/**
* @return $this
*/
public function addNameTest()
public function addNameTest(): XPathExpr
{
if ('*' !== $this->element) {
$this->addCondition('name() = '.Translator::getXpathLiteral($this->element));
@ -96,10 +79,7 @@ class XPathExpr
return $this;
}
/**
* @return $this
*/
public function addStarPrefix()
public function addStarPrefix(): XPathExpr
{
$this->path .= '*/';
@ -114,7 +94,7 @@ class XPathExpr
*
* @return $this
*/
public function join($combiner, XPathExpr $expr)
public function join(string $combiner, XPathExpr $expr): XPathExpr
{
$path = $this->__toString().$combiner;
@ -129,10 +109,7 @@ class XPathExpr
return $this;
}
/**
* @return string
*/
public function __toString()
public function __toString(): string
{
$path = $this->path.$this->element;
$condition = null === $this->condition || '' === $this->condition ? '' : '['.$this->condition.']';

View File

@ -45,7 +45,7 @@ final class Dotenv
* @throws FormatException when a file has a syntax error
* @throws PathException when a file does not exist or is not readable
*/
public function load($path, ...$paths)
public function load(string $path, string ...$paths): void
{
array_unshift($paths, $path);
@ -65,7 +65,7 @@ final class Dotenv
*
* @param array $values An array of env variables
*/
public function populate($values)
public function populate(array $values): void
{
$loadedVars = array_flip(explode(',', getenv('SYMFONY_DOTENV_VARS')));
unset($loadedVars['']);
@ -104,7 +104,7 @@ final class Dotenv
*
* @throws FormatException when a file has a syntax error
*/
public function parse($data, $path = '.env')
public function parse(string $data, string $path = '.env'): array
{
$this->path = $path;
$this->data = str_replace(array("\r\n", "\r"), "\n", $data);

View File

@ -141,7 +141,7 @@ class ExpressionLanguage
$this->addFunction(ExpressionFunction::fromPhp('constant'));
}
private function getLexer()
private function getLexer(): Lexer
{
if (null === $this->lexer) {
$this->lexer = new Lexer();
@ -150,7 +150,7 @@ class ExpressionLanguage
return $this->lexer;
}
private function getParser()
private function getParser(): Parser
{
if (null === $this->parser) {
$this->parser = new Parser($this->functions);
@ -159,7 +159,7 @@ class ExpressionLanguage
return $this->parser;
}
private function getCompiler()
private function getCompiler(): Compiler
{
if (null === $this->compiler) {
$this->compiler = new Compiler($this->functions);

View File

@ -27,7 +27,7 @@ class UnaryNode extends Node
'-' => '-',
);
public function __construct($operator, Node $node)
public function __construct(string $operator, Node $node)
{
parent::__construct(
array('node' => $node),
@ -59,7 +59,7 @@ class UnaryNode extends Node
return $value;
}
public function toArray()
public function toArray(): array
{
return array('(', $this->attributes['operator'].' ', $this->nodes['node'], ')');
}

View File

@ -105,7 +105,7 @@ final class Forms
*
* @return FormFactoryInterface The form factory
*/
public static function createFormFactory()
public static function createFormFactory(): FormFactoryInterface
{
return self::createFormFactoryBuilder()->getFormFactory();
}
@ -115,7 +115,7 @@ final class Forms
*
* @return FormFactoryBuilderInterface The form factory builder
*/
public static function createFormFactoryBuilder()
public static function createFormFactoryBuilder(): FormFactoryBuilderInterface
{
$builder = new FormFactoryBuilder();
$builder->addExtension(new CoreExtension());

View File

@ -34,7 +34,7 @@ final class ArgumentResolver implements ArgumentResolverInterface
*/
private $argumentValueResolvers;
public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, $argumentValueResolvers = array())
public function __construct(ArgumentMetadataFactoryInterface $argumentMetadataFactory = null, iterable $argumentValueResolvers = array())
{
$this->argumentMetadataFactory = $argumentMetadataFactory ?: new ArgumentMetadataFactory();
$this->argumentValueResolvers = $argumentValueResolvers ?: self::getDefaultArgumentValueResolvers();
@ -81,7 +81,7 @@ final class ArgumentResolver implements ArgumentResolverInterface
return $arguments;
}
public static function getDefaultArgumentValueResolvers()
public static function getDefaultArgumentValueResolvers(): iterable
{
return array(
new RequestAttributeValueResolver(),

View File

@ -85,7 +85,7 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
return new Response($tag);
}
private function generateSignedFragmentUri($uri, Request $request)
private function generateSignedFragmentUri($uri, Request $request): string
{
if (null === $this->signer) {
throw new \LogicException('You must use a URI when using the ESI rendering strategy or set a URL signer.');
@ -97,7 +97,7 @@ abstract class AbstractSurrogateFragmentRenderer extends RoutableFragmentRendere
return substr($fragmentUri, strlen($request->getSchemeAndHttpHost()));
}
private function containsNonScalars(array $values)
private function containsNonScalars(array $values): bool
{
foreach ($values as $value) {
if (is_array($value) && $this->containsNonScalars($value)) {

View File

@ -123,12 +123,7 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
return new Response(sprintf('<hx:include src="%s"%s>%s</hx:include>', $uri, $renderedAttributes, $content));
}
/**
* @param string $template
*
* @return bool
*/
private function templateExists($template)
private function templateExists(string $template): bool
{
if ($this->templating instanceof EngineInterface) {
try {

View File

@ -118,7 +118,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
* @throws \LogicException If one of the listener does not behave as expected
* @throws NotFoundHttpException When controller cannot be found
*/
private function handleRaw(Request $request, $type = self::MASTER_REQUEST)
private function handleRaw(Request $request, int $type = self::MASTER_REQUEST)
{
$this->requestStack->push($request);
@ -184,7 +184,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
*
* @throws \RuntimeException if the passed object is not a Response instance
*/
private function filterResponse(Response $response, Request $request, $type)
private function filterResponse(Response $response, Request $request, int $type)
{
$event = new FilterResponseEvent($this, $request, $type, $response);
@ -205,7 +205,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
* @param Request $request
* @param int $type
*/
private function finishRequest(Request $request, $type)
private function finishRequest(Request $request, int $type)
{
$this->dispatcher->dispatch(KernelEvents::FINISH_REQUEST, new FinishRequestEvent($this, $request, $type));
$this->requestStack->pop();
@ -222,7 +222,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
*
* @throws \Exception
*/
private function handleException(\Exception $e, $request, $type)
private function handleException(\Exception $e, Request $request, int $type)
{
$event = new GetResponseForExceptionEvent($this, $request, $type, $e);
$this->dispatcher->dispatch(KernelEvents::EXCEPTION, $event);
@ -257,7 +257,7 @@ class HttpKernel implements HttpKernelInterface, TerminableInterface
}
}
private function varToString($var)
private function varToString($var): string
{
if (is_object($var)) {
return sprintf('Object(%s)', get_class($var));

View File

@ -91,7 +91,7 @@ final class Inflector
// accesses (access), addresses (address), kisses (kiss)
array('sess', 4, true, false, 'ss'),
// analyses (analysis), ellipses (ellipsis), funguses (fungus),
// analyses (analysis), ellipses (ellipsis), fungi (fungus),
// neuroses (neurosis), theses (thesis), emphases (emphasis),
// oases (oasis), crises (crisis), houses (house), bases (base),
// atlases (atlas)
@ -159,7 +159,7 @@ final class Inflector
*
* @internal
*/
public static function singularize($plural)
public static function singularize(string $plural)
{
$pluralRev = strrev($plural);
$lowerPluralRev = strtolower($pluralRev);

View File

@ -41,7 +41,7 @@ class LanguageDataProvider
* @param BundleEntryReaderInterface $reader The reader for reading the .res
* files.
*/
public function __construct($path, BundleEntryReaderInterface $reader)
public function __construct(string $path, BundleEntryReaderInterface $reader)
{
$this->path = $path;
$this->reader = $reader;

View File

@ -23,7 +23,7 @@ class AmPmTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
return $dateTime->format('A');
}
@ -31,7 +31,7 @@ class AmPmTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
return 'AM|PM';
}
@ -39,7 +39,7 @@ class AmPmTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array(
'marker' => $matched,

View File

@ -23,7 +23,7 @@ class DayOfWeekTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
$dayOfWeek = $dateTime->format('l');
switch ($length) {
@ -41,7 +41,7 @@ class DayOfWeekTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
switch ($length) {
case 4:
@ -58,7 +58,7 @@ class DayOfWeekTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array();
}

View File

@ -23,7 +23,7 @@ class DayOfYearTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
$dayOfYear = $dateTime->format('z') + 1;
@ -33,7 +33,7 @@ class DayOfYearTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
return '\d{'.$length.'}';
}
@ -41,7 +41,7 @@ class DayOfYearTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array();
}

View File

@ -23,7 +23,7 @@ class DayTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
return $this->padLeft($dateTime->format('j'), $length);
}
@ -31,7 +31,7 @@ class DayTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
}
@ -39,7 +39,7 @@ class DayTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array(
'day' => (int) $matched,

View File

@ -23,7 +23,7 @@ class Hour1200Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
$hourOfDay = $dateTime->format('g');
$hourOfDay = '12' == $hourOfDay ? '0' : $hourOfDay;
@ -34,7 +34,7 @@ class Hour1200Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function normalizeHour($hour, $marker = null)
public function normalizeHour(int $hour, string $marker = null): int
{
if ('PM' === $marker) {
$hour += 12;
@ -46,7 +46,7 @@ class Hour1200Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
return '\d{1,2}';
}
@ -54,7 +54,7 @@ class Hour1200Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array(
'hour' => (int) $matched,

View File

@ -23,7 +23,7 @@ class Hour1201Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
return $this->padLeft($dateTime->format('g'), $length);
}
@ -31,7 +31,7 @@ class Hour1201Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function normalizeHour($hour, $marker = null)
public function normalizeHour(int $hour, string $marker = null): int
{
if ('PM' !== $marker && 12 === $hour) {
$hour = 0;
@ -46,7 +46,7 @@ class Hour1201Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
return '\d{1,2}';
}
@ -54,7 +54,7 @@ class Hour1201Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array(
'hour' => (int) $matched,

View File

@ -23,7 +23,7 @@ class Hour2400Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
return $this->padLeft($dateTime->format('G'), $length);
}
@ -31,7 +31,7 @@ class Hour2400Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function normalizeHour($hour, $marker = null)
public function normalizeHour(int $hour, string $marker = null): int
{
if ('AM' == $marker) {
$hour = 0;
@ -45,7 +45,7 @@ class Hour2400Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
return '\d{1,2}';
}
@ -53,7 +53,7 @@ class Hour2400Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array(
'hour' => (int) $matched,

View File

@ -23,7 +23,7 @@ class Hour2401Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
$hourOfDay = $dateTime->format('G');
$hourOfDay = ('0' == $hourOfDay) ? '24' : $hourOfDay;
@ -34,7 +34,7 @@ class Hour2401Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function normalizeHour($hour, $marker = null)
public function normalizeHour(int $hour, string $marker = null): int
{
if ((null === $marker && 24 === $hour) || 'AM' == $marker) {
$hour = 0;
@ -48,7 +48,7 @@ class Hour2401Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
return '\d{1,2}';
}
@ -56,7 +56,7 @@ class Hour2401Transformer extends HourTransformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array(
'hour' => (int) $matched,

View File

@ -28,5 +28,5 @@ abstract class HourTransformer extends Transformer
*
* @return int The normalized hour value
*/
abstract public function normalizeHour($hour, $marker = null);
abstract public function normalizeHour(int $hour, string $marker = null): int;
}

View File

@ -23,7 +23,7 @@ class MinuteTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
$minuteOfHour = (int) $dateTime->format('i');
@ -33,7 +33,7 @@ class MinuteTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
}
@ -41,7 +41,7 @@ class MinuteTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array(
'minute' => (int) $matched,

View File

@ -77,7 +77,7 @@ class MonthTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
$matchLengthMap = array(
1 => 'n',
@ -100,7 +100,7 @@ class MonthTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
switch ($length) {
case 1:
@ -126,7 +126,7 @@ class MonthTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
if (!is_numeric($matched)) {
if (3 === $length) {

View File

@ -23,7 +23,7 @@ class QuarterTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
$month = (int) $dateTime->format('n');
$quarter = (int) floor(($month - 1) / 3) + 1;
@ -43,7 +43,7 @@ class QuarterTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
switch ($length) {
case 1:
@ -59,7 +59,7 @@ class QuarterTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array();
}

View File

@ -23,7 +23,7 @@ class SecondTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
$secondOfMinute = (int) $dateTime->format('s');
@ -33,7 +33,7 @@ class SecondTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
return 1 === $length ? '\d{1,2}' : '\d{'.$length.'}';
}
@ -41,7 +41,7 @@ class SecondTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array(
'second' => (int) $matched,

View File

@ -27,7 +27,7 @@ class TimezoneTransformer extends Transformer
*
* @throws NotImplementedException When time zone is different than UTC or GMT (Etc/GMT)
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
$timeZone = substr($dateTime->getTimezone()->getName(), 0, 3);
@ -63,7 +63,7 @@ class TimezoneTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
return 'GMT[+-]\d{2}:?\d{2}';
}
@ -71,7 +71,7 @@ class TimezoneTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array(
'timezone' => self::getEtcTimeZoneId($matched),

View File

@ -29,7 +29,7 @@ abstract class Transformer
*
* @return string The formatted value
*/
abstract public function format(\DateTime $dateTime, $length);
abstract public function format(\DateTime $dateTime, int $length): string;
/**
* Returns a reverse matching regular expression of a string generated by format().
@ -38,7 +38,7 @@ abstract class Transformer
*
* @return string The reverse matching regular expression
*/
abstract public function getReverseMatchingRegExp($length);
abstract public function getReverseMatchingRegExp(int $length): string;
/**
* Extract date options from a matched value returned by the processing of the reverse matching
@ -49,7 +49,7 @@ abstract class Transformer
*
* @return array An associative array
*/
abstract public function extractDateOptions($matched, $length);
abstract public function extractDateOptions(string $matched, int $length): array;
/**
* Pad a string with zeros to the left.
@ -59,7 +59,7 @@ abstract class Transformer
*
* @return string The padded string
*/
protected function padLeft($value, $length)
protected function padLeft(string $value, int $length): string
{
return str_pad($value, $length, '0', STR_PAD_LEFT);
}

View File

@ -23,7 +23,7 @@ class YearTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function format(\DateTime $dateTime, $length)
public function format(\DateTime $dateTime, int $length): string
{
if (2 === $length) {
return $dateTime->format('y');
@ -35,7 +35,7 @@ class YearTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function getReverseMatchingRegExp($length)
public function getReverseMatchingRegExp(int $length): string
{
return 2 === $length ? '\d{2}' : '\d{4}';
}
@ -43,7 +43,7 @@ class YearTransformer extends Transformer
/**
* {@inheritdoc}
*/
public function extractDateOptions($matched, $length)
public function extractDateOptions(string $matched, int $length): array
{
return array(
'year' => (int) $matched,

View File

@ -35,7 +35,7 @@ final class Locale extends \Locale
*
* @see getFallback()
*/
public static function setDefaultFallback($locale)
public static function setDefaultFallback(string $locale)
{
self::$defaultFallback = $locale;
}
@ -48,7 +48,7 @@ final class Locale extends \Locale
* @see setDefaultFallback()
* @see getFallback()
*/
public static function getDefaultFallback()
public static function getDefaultFallback(): string
{
return self::$defaultFallback;
}
@ -65,7 +65,7 @@ final class Locale extends \Locale
* @return string|null The ICU locale code of the fallback locale, or null
* if no fallback exists
*/
public static function getFallback($locale)
public static function getFallback($locale): ?string
{
if (false === $pos = strrpos($locale, '_')) {
if (self::$defaultFallback === $locale) {
@ -78,7 +78,7 @@ final class Locale extends \Locale
return self::$defaultFallback;
}
return;
return null;
}
return substr($locale, 0, $pos);

View File

@ -36,15 +36,7 @@ class LanguageBundle extends LanguageDataProvider implements LanguageBundleInter
*/
private $scriptProvider;
/**
* Creates a new language bundle.
*
* @param string $path
* @param BundleEntryReaderInterface $reader
* @param LocaleDataProvider $localeProvider
* @param ScriptDataProvider $scriptProvider
*/
public function __construct($path, BundleEntryReaderInterface $reader, LocaleDataProvider $localeProvider, ScriptDataProvider $scriptProvider)
public function __construct(string $path, BundleEntryReaderInterface $reader, LocaleDataProvider $localeProvider, ScriptDataProvider $scriptProvider)
{
parent::__construct($path, $reader);

View File

@ -70,7 +70,7 @@ final class Ldap implements LdapInterface
*
* @return static
*/
public static function create($adapter, array $config = array())
public static function create($adapter, array $config = array()): Ldap
{
if (!isset(self::$adapterMap[$adapter])) {
throw new DriverNotFoundException(sprintf(

View File

@ -25,9 +25,9 @@ final class Key
/**
* @param string $resource
*/
public function __construct($resource)
public function __construct(string $resource)
{
$this->resource = (string) $resource;
$this->resource = $resource;
}
public function __toString()
@ -35,39 +35,22 @@ final class Key
return $this->resource;
}
/**
* @param string $stateKey
*
* @return bool
*/
public function hasState($stateKey)
public function hasState(string $stateKey): bool
{
return isset($this->state[$stateKey]);
}
/**
* @param string $stateKey
* @param mixed $state
*/
public function setState($stateKey, $state)
public function setState(string $stateKey, $state): void
{
$this->state[$stateKey] = $state;
}
/**
* @param string $stateKey
*/
public function removeState($stateKey)
public function removeState(string $stateKey): void
{
unset($this->state[$stateKey]);
}
/**
* @param $stateKey
*
* @return mixed
*/
public function getState($stateKey)
public function getState(string $stateKey)
{
return $this->state[$stateKey];
}

View File

@ -23,17 +23,12 @@ final class PropertyAccess
*
* @return PropertyAccessor
*/
public static function createPropertyAccessor()
public static function createPropertyAccessor(): PropertyAccessor
{
return self::createPropertyAccessorBuilder()->getPropertyAccessor();
}
/**
* Creates a property accessor builder.
*
* @return PropertyAccessorBuilder
*/
public static function createPropertyAccessorBuilder()
public static function createPropertyAccessorBuilder(): PropertyAccessorBuilder
{
return new PropertyAccessorBuilder();
}

View File

@ -162,18 +162,18 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
*
* @return Type[]|null
*/
private function extractFromMutator($class, $property)
private function extractFromMutator(string $class, string $property): ?array
{
list($reflectionMethod, $prefix) = $this->getMutatorMethod($class, $property);
if (null === $reflectionMethod) {
return;
return null;
}
$reflectionParameters = $reflectionMethod->getParameters();
$reflectionParameter = $reflectionParameters[0];
if (!$reflectionType = $reflectionParameter->getType()) {
return;
return null;
}
$type = $this->extractFromReflectionType($reflectionType);
@ -192,11 +192,11 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
*
* @return Type[]|null
*/
private function extractFromAccessor($class, $property)
private function extractFromAccessor(string $class, string $property): ?array
{
list($reflectionMethod, $prefix) = $this->getAccessorMethod($class, $property);
if (null === $reflectionMethod) {
return;
return null;
}
if ($reflectionType = $reflectionMethod->getReturnType()) {
@ -206,6 +206,8 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
if (in_array($prefix, array('is', 'can'))) {
return array(new Type(Type::BUILTIN_TYPE_BOOL));
}
return null;
}
/**
@ -215,7 +217,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
*
* @return Type
*/
private function extractFromReflectionType(\ReflectionType $reflectionType)
private function extractFromReflectionType(\ReflectionType $reflectionType): Type
{
$phpTypeOrClass = $reflectionType->getName();
$nullable = $reflectionType->allowsNull();
@ -241,7 +243,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
*
* @return bool
*/
private function isPublicProperty($class, $property)
private function isPublicProperty(string $class, string $property): bool
{
try {
$reflectionProperty = new \ReflectionProperty($class, $property);
@ -265,7 +267,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
*
* @return array|null
*/
private function getAccessorMethod($class, $property)
private function getAccessorMethod(string $class, string $property): ?array
{
$ucProperty = ucfirst($property);
@ -283,6 +285,8 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
// Return null if the property doesn't exist
}
}
return null;
}
/**
@ -296,7 +300,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
*
* @return array
*/
private function getMutatorMethod($class, $property)
private function getMutatorMethod(string $class, string $property)
{
$ucProperty = ucfirst($property);
$ucSingulars = (array) Inflector::singularize($ucProperty);
@ -333,7 +337,7 @@ class ReflectionExtractor implements PropertyListExtractorInterface, PropertyTyp
*
* @return string
*/
private function getPropertyName($methodName, array $reflectionProperties)
private function getPropertyName(string $methodName, array $reflectionProperties)
{
$pattern = implode('|', array_merge($this->accessorPrefixes, $this->mutatorPrefixes));

View File

@ -27,9 +27,9 @@ final class PhpDocTypeHelper
/**
* Creates a {@see Type} from a PHPDoc type.
*
* @return Type
* @return Type[]
*/
public function getTypes(DocType $varType)
public function getTypes(DocType $varType): array
{
$types = array();
$nullable = false;
@ -79,11 +79,11 @@ final class PhpDocTypeHelper
*
* @return Type|null
*/
private function createType($docType, $nullable)
private function createType(string $docType, bool $nullable): ?Type
{
// Cannot guess
if (!$docType || 'mixed' === $docType) {
return;
return null;
}
if ($collection = '[]' === substr($docType, -2)) {
@ -110,14 +110,7 @@ final class PhpDocTypeHelper
return new Type($phpType, $nullable, $class);
}
/**
* Normalizes the type.
*
* @param string $docType
*
* @return string
*/
private function normalizeType($docType)
private function normalizeType(string $docType): string
{
switch ($docType) {
case 'integer':
@ -141,14 +134,7 @@ final class PhpDocTypeHelper
}
}
/**
* Gets an array containing the PHP type and the class.
*
* @param string $docType
*
* @return array
*/
private function getPhpTypeAndClass($docType)
private function getPhpTypeAndClass(string $docType): array
{
if (in_array($docType, Type::$builtinTypes)) {
return array($docType, null);

View File

@ -32,34 +32,18 @@ class DumperRoute
*/
private $route;
/**
* Constructor.
*
* @param string $name The route name
* @param Route $route The route
*/
public function __construct($name, Route $route)
public function __construct(string $name, Route $route)
{
$this->name = $name;
$this->route = $route;
}
/**
* Returns the route name.
*
* @return string The route name
*/
public function getName()
public function getName(): string
{
return $this->name;
}
/**
* Returns the route.
*
* @return Route The route
*/
public function getRoute()
public function getRoute(): Route
{
return $this->route;
}

View File

@ -35,12 +35,12 @@ class StaticPrefixCollection
*/
private $matchStart = 0;
public function __construct($prefix = '')
public function __construct(string $prefix = '')
{
$this->prefix = $prefix;
}
public function getPrefix()
public function getPrefix(): string
{
return $this->prefix;
}
@ -48,7 +48,7 @@ class StaticPrefixCollection
/**
* @return mixed[]|StaticPrefixCollection[]
*/
public function getItems()
public function getItems(): array
{
return $this->items;
}
@ -59,7 +59,7 @@ class StaticPrefixCollection
* @param string $prefix
* @param mixed $route
*/
public function addRoute($prefix, $route)
public function addRoute(string $prefix, $route)
{
$prefix = '/' === $prefix ? $prefix : rtrim($prefix, '/');
$this->guardAgainstAddingNotAcceptedRoutes($prefix);
@ -108,7 +108,7 @@ class StaticPrefixCollection
*
* @return null|StaticPrefixCollection
*/
private function groupWithItem($item, $prefix, $route)
private function groupWithItem($item, string $prefix, $route)
{
$itemPrefix = $item instanceof self ? $item->prefix : $item[0];
$commonPrefix = $this->detectCommonPrefix($prefix, $itemPrefix);
@ -137,7 +137,7 @@ class StaticPrefixCollection
*
* @return bool Whether a prefix could belong in a given group
*/
private function accepts($prefix)
private function accepts(string $prefix): bool
{
return '' === $this->prefix || strpos($prefix, $this->prefix) === 0;
}
@ -150,7 +150,7 @@ class StaticPrefixCollection
*
* @return false|string A common prefix, longer than the base/group prefix, or false when none available
*/
private function detectCommonPrefix($prefix, $anotherPrefix)
private function detectCommonPrefix(string $prefix, string $anotherPrefix)
{
$baseLength = strlen($this->prefix);
$commonLength = $baseLength;
@ -176,7 +176,7 @@ class StaticPrefixCollection
/**
* Optimizes the tree by inlining items from groups with less than 3 items.
*/
public function optimizeGroups()
public function optimizeGroups(): void
{
$index = -1;
@ -199,7 +199,7 @@ class StaticPrefixCollection
}
}
private function shouldBeInlined()
private function shouldBeInlined(): bool
{
if (count($this->items) >= 3) {
return false;
@ -227,7 +227,7 @@ class StaticPrefixCollection
*
* @throws \LogicException When a prefix does not belong in a group.
*/
private function guardAgainstAddingNotAcceptedRoutes($prefix)
private function guardAgainstAddingNotAcceptedRoutes(string $prefix)
{
if (!$this->accepts($prefix)) {
$message = sprintf('Could not add route with prefix %s to collection with prefix %s', $prefix, $this->prefix);

View File

@ -258,7 +258,7 @@ class RouteCollectionBuilder
*
* @return $this
*/
private function addResource(ResourceInterface $resource)
private function addResource(ResourceInterface $resource): RouteCollectionBuilder
{
$this->resources[] = $resource;
@ -356,7 +356,7 @@ class RouteCollectionBuilder
*
* @throws FileLoaderLoadException If no loader is found
*/
private function load($resource, $type = null)
private function load($resource, string $type = null): array
{
if (null === $this->loader) {
throw new \BadMethodCallException('Cannot import other routing resources: you must pass a LoaderInterface when constructing RouteCollectionBuilder.');

View File

@ -24,18 +24,7 @@ final class PersistentToken implements PersistentTokenInterface
private $tokenValue;
private $lastUsed;
/**
* Constructor.
*
* @param string $class
* @param string $username
* @param string $series
* @param string $tokenValue
* @param \DateTime $lastUsed
*
* @throws \InvalidArgumentException
*/
public function __construct($class, $username, $series, $tokenValue, \DateTime $lastUsed)
public function __construct(string $class, string $username, string $series, string $tokenValue, \DateTime $lastUsed)
{
if (empty($class)) {
throw new \InvalidArgumentException('$class must not be empty.');

View File

@ -104,7 +104,7 @@ class ExceptionListener
} while (null !== $exception = $exception->getPrevious());
}
private function handleAuthenticationException(GetResponseForExceptionEvent $event, AuthenticationException $exception)
private function handleAuthenticationException(GetResponseForExceptionEvent $event, AuthenticationException $exception): void
{
if (null !== $this->logger) {
$this->logger->info('An AuthenticationException was thrown; redirecting to authentication entry point.', array('exception' => $exception));
@ -167,22 +167,14 @@ class ExceptionListener
}
}
private function handleLogoutException(LogoutException $exception)
private function handleLogoutException(LogoutException $exception): void
{
if (null !== $this->logger) {
$this->logger->info('A LogoutException was thrown.', array('exception' => $exception));
}
}
/**
* @param Request $request
* @param AuthenticationException $authException
*
* @return Response
*
* @throws AuthenticationException
*/
private function startAuthentication(Request $request, AuthenticationException $authException)
private function startAuthentication(Request $request, AuthenticationException $authException): Response
{
if (null === $this->authenticationEntryPoint) {
throw $authException;
@ -216,9 +208,6 @@ class ExceptionListener
return $response;
}
/**
* @param Request $request
*/
protected function setTargetPath(Request $request)
{
// session isn't required when using HTTP basic authentication mechanism for example

View File

@ -280,10 +280,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
$this->loadFallbackCatalogues($locale);
}
/**
* @param string $locale
*/
private function initializeCacheCatalogue($locale)
private function initializeCacheCatalogue(string $locale): void
{
if (isset($this->catalogues[$locale])) {
/* Catalogue already initialized. */
@ -306,7 +303,7 @@ class Translator implements TranslatorInterface, TranslatorBagInterface
$this->catalogues[$locale] = include $cache->getPath();
}
private function dumpCatalogue($locale, ConfigCacheInterface $cache)
private function dumpCatalogue($locale, ConfigCacheInterface $cache): void
{
$this->initializeCatalogue($locale);
$fallbackContent = $this->getFallbackContent($this->catalogues[$locale]);
@ -331,7 +328,7 @@ EOF
$cache->write($content, $this->catalogues[$locale]->getResources());
}
private function getFallbackContent(MessageCatalogue $catalogue)
private function getFallbackContent(MessageCatalogue $catalogue): string
{
$fallbackContent = '';
$current = '';
@ -366,7 +363,7 @@ EOF
return $this->cacheDir.'/catalogue.'.$locale.'.'.strtr(substr(base64_encode(hash('sha256', serialize($this->fallbackLocales), true)), 0, 7), '/', '_').'.php';
}
private function doLoadCatalogue($locale)
private function doLoadCatalogue($locale): void
{
$this->catalogues[$locale] = new MessageCatalogue($locale);
@ -380,7 +377,7 @@ EOF
}
}
private function loadFallbackCatalogues($locale)
private function loadFallbackCatalogues($locale): void
{
$current = $this->catalogues[$locale];
@ -436,7 +433,7 @@ EOF
*
* @return ConfigCacheFactoryInterface $configCacheFactory
*/
private function getConfigCacheFactory()
private function getConfigCacheFactory(): ConfigCacheFactoryInterface
{
if (!$this->configCacheFactory) {
$this->configCacheFactory = new ConfigCacheFactory($this->debug);

View File

@ -28,7 +28,7 @@ final class Validation
*
* @return ValidatorInterface The new validator
*/
public static function createValidator()
public static function createValidator(): ValidatorInterface
{
return self::createValidatorBuilder()->getValidator();
}
@ -38,7 +38,7 @@ final class Validation
*
* @return ValidatorBuilderInterface The new builder
*/
public static function createValidatorBuilder()
public static function createValidatorBuilder(): ValidatorBuilder
{
return new ValidatorBuilder();
}

View File

@ -29,7 +29,7 @@ final class HttpHeaderSerializer
*
* @return string|null
*/
public function serialize($links)
public function serialize(iterable $links)
{
$elements = array();
foreach ($links as $link) {

View File

@ -30,7 +30,7 @@ final class Definition
* @param Transition[] $transitions
* @param string|null $initialPlace
*/
public function __construct(array $places, array $transitions, $initialPlace = null)
public function __construct(array $places, array $transitions, string $initialPlace = null)
{
foreach ($places as $place) {
$this->addPlace($place);
@ -54,7 +54,7 @@ final class Definition
/**
* @return string[]
*/
public function getPlaces()
public function getPlaces(): array
{
return $this->places;
}
@ -62,12 +62,12 @@ final class Definition
/**
* @return Transition[]
*/
public function getTransitions()
public function getTransitions(): array
{
return $this->transitions;
}
private function setInitialPlace($place)
private function setInitialPlace(string $place = null)
{
if (null === $place) {
return;
@ -80,7 +80,7 @@ final class Definition
$this->initialPlace = $place;
}
private function addPlace($place)
private function addPlace(string $place)
{
if (!preg_match('{^[\w\d_-]+$}', $place)) {
throw new InvalidArgumentException(sprintf('The place "%s" contains invalid characters.', $place));

View File

@ -201,7 +201,7 @@ class GraphvizDumper implements DumperInterface
return strtolower(preg_replace('/[^\w]/i', '_', $id));
}
private function addAttributes(array $attributes)
private function addAttributes(array $attributes): string
{
$code = array();
@ -212,7 +212,7 @@ class GraphvizDumper implements DumperInterface
return $code ? ', '.implode(', ', $code) : '';
}
private function addOptions(array $options)
private function addOptions(array $options): string
{
$code = array();

View File

@ -51,7 +51,7 @@ class GuardListener
}
// code should be sync with Symfony\Component\Security\Core\Authorization\Voter\ExpressionVoter
private function getVariables(GuardEvent $event)
private function getVariables(GuardEvent $event): array
{
$token = $this->tokenStorage->getToken();

View File

@ -61,7 +61,7 @@ class Registry
return $matched;
}
private function supports(Workflow $workflow, SupportStrategyInterface $supportStrategy, $subject, $workflowName)
private function supports(Workflow $workflow, SupportStrategyInterface $supportStrategy, $subject, $workflowName): bool
{
if (null !== $workflowName && $workflowName !== $workflow->getName()) {
return false;

View File

@ -11,10 +11,7 @@ final class ClassInstanceSupportStrategy implements SupportStrategyInterface
{
private $className;
/**
* @param string $className a FQCN
*/
public function __construct($className)
public function __construct(string $className)
{
$this->className = $className;
}

View File

@ -20,27 +20,17 @@ final class TaggedValue
private $tag;
private $value;
/**
* @param string $tag
* @param mixed $value
*/
public function __construct($tag, $value)
public function __construct(string $tag, $value)
{
$this->tag = $tag;
$this->value = $value;
}
/**
* @return string
*/
public function getTag()
public function getTag(): string
{
return $this->tag;
}
/**
* @return mixed
*/
public function getValue()
{
return $this->value;