8000 Add scalar typehints/return types on final/internal/private code · symfony/symfony@6ce70e4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6ce70e4

Browse files
author
Robin Chalas
committed
Add scalar typehints/return types on final/internal/private code
1 parent 79cd706 commit 6ce70e4
  • XPath
  • Dotenv
  • ExpressionLanguage
  • Form
  • HttpKernel
  • Inflector
  • Intl
  • Ldap
  • Lock
  • PropertyAccess
  • PropertyInfo
  • Routing
  • Security
  • Translation
  • Validator
  • Workflow
  • Yaml/Tag
  • Some content is hidden

    Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

    86 files changed

    +304
    -737
    lines changed

    src/Symfony/Bridge/Doctrine/Form/ChoiceList/IdReader.php

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -82,7 +82,7 @@ public function __construct(ObjectManager $om, ClassMetadata $classMetadata)
    8282
    * @return bool Returns `true` if the class has a single-column ID and
    8383
    * `false` otherwise.
    8484
    */
    85-
    public function isSingleId()
    85+
    public function isSingleId(): bool
    8686
    {
    8787
    return $this->singleId;
    8888
    }
    @@ -93,7 +93,7 @@ public function isSingleId()
    9393
    * @return bool Returns `true` if the class has a single-column integer ID
    9494
    * and `false` otherwise.
    9595
    */
    96-
    public function isIntId()
    96+
    public function isIntId(): bool
    9797
    {
    9898
    return $this->intId;
    9999
    }
    @@ -138,7 +138,7 @@ public function getIdValue($object)
    138138
    *
    139139
    * @return string The name of the ID field
    140140
    */
    141-
    public function getIdField()
    141+
    public function getIdField(): string
    142142
    {
    143143
    return $this->idField;
    144144
    }

    src/Symfony/Bundle/SecurityBundle/Debug/WrappedListener.php

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -56,12 +56,12 @@ public function __call($method, $arguments)
    5656
    return call_user_func_array(array($this->listener, $method), $arguments);
    5757
    }
    5858

    59-
    public function getWrappedListener()
    59+
    public function getWrappedListener(): ListenerInterface
    6060
    {
    6161
    return $this->listener;
    6262
    }
    6363

    64-
    public function getInfo()
    64+
    public function getInfo(): array
    6565
    {
    6666
    if (null === $this->stub) {
    6767
    $this->stub = self::$hasVarDumper ? new ClassStub(get_class($this->listener)) : get_class($this->listener);

    src/Symfony/Bundle/SecurityBundle/Security/FirewallConfig.php

    Lines changed: 14 additions & 49 deletions
    Original file line numberDiff line numberDiff line change
    @@ -29,21 +29,7 @@ final class FirewallConfig
    2929
    private $listeners;
    3030
    private $switchUser;
    3131

    32-
    /**
    33-
    * @param string $name
    34-
    * @param string $userChecker
    35-
    * @param string|null $requestMatcher
    36-
    * @param bool $securityEnabled
    37-
    * @param bool $stateless
    38-
    * @param string|null $provider
    39-
    * @param string|null $context
    40-
    * @param string|null $entryPoint
    41-
    * @param string|null $accessDeniedHandler
    42-
    * @param string|null $accessDeniedUrl
    43-
    * @param string[] $listeners
    44-
    * @param array|null $switchUser
    45-
    */
    46-
    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)
    32+
    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)
    4733
    {
    4834
    $this->name = $name;
    4935
    $this->userChecker = $userChecker;
    @@ -59,7 +45,7 @@ public function __construct($name, $userChecker, $requestMatcher = null, $securi
    5945
    $this->switchUser = $switchUser;
    6046
    }
    6147

    62-
    public function getName()
    48+
    public function getName(): string
    6349
    {
    6450
    return $this->name;
    6551
    }
    @@ -68,86 +54,65 @@ public function getName()
    6854
    * @return string|null The request matcher service id or null if neither the request matcher, pattern or host
    6955
    * options were provided
    7056
    */
    71-
    public function getRequestMatcher()
    57+
    public function getRequestMatcher(): ?string
    7258
    {
    7359
    return $this->requestMatcher;
    7460
    }
    7561

    76-
    public function isSecurityEnabled()
    62+
    public function isSecurityEnabled(): bool
    7763
    {
    7864
    return $this->securityEnabled;
    7965
    }
    8066

    81-
    public function allowsAnonymous()
    67+
    public function allowsAnonymous(): bool
    8268
    {
    8369
    return in_array('anonymous', $this->listeners, true);
    8470
    }
    8571

    86-
    public function isStateless()
    72+
    public function isStateless(): bool
    8773
    {
    8874
    return $this->stateless;
    8975
    }
    9076

    91-
    /**
    92-
    * @return string|null The provider service id
    93-
    */
    94-
    public function getProvider()
    77+
    public function getProvider(): ?string
    9578
    {
    9679
    return $this->provider;
    9780
    }
    9881

    9982
    /**
    10083
    * @return string|null The context key (will be null if the firewall is stateless)
    10184
    */
    102-
    public function getContext()
    85+
    public function getContext(): ?string
    10386
    {
    10487
    return $this->context;
    10588
    }
    10689

    107-
    /**
    108-
    * @return string|null The entry_point service id if configured, null otherwise
    109-
    */
    110-
    public function getEntryPoint()
    90+
    public function getEntryPoint(): ?string
    11191
    {
    11292
    return $this->entryPoint;
    11393
    }
    11494

    115-
    /**
    116-
    * @return string The user_checker service id
    117-
    */
    118-
    public function getUserChecker()
    95+
    public function getUserChecker(): string
    11996
    {
    12097
    return $this->userChecker;
    12198
    }
    12299

    123-
    /**
    124-
    * @return string|null The access_denied_handler service id if configured, null otherwise
    125-
    */
    126-
    public function getAccessDeniedHandler()
    100+
    public function getAccessDeniedHandler(): ?string
    127101
    {
    128102
    return $this->accessDeniedHandler;
    129103
    }
    130104

    131-
    /**
    132-
    * @return string|null The access_denied_handler URL if configured, null otherwise
    133-
    */
    134-
    public function getAccessDeniedUrl()
    105+
    public function getAccessDeniedUrl(): ?string
    135106
    {
    136107
    return $this->accessDeniedUrl;
    137108
    }
    138109

    139-
    /**
    140-
    * @return string[] An array of listener keys
    141-
    */
    142-
    public function getListeners()
    110+
    public function getListeners(): array
    143111
    {
    144112
    return $this->listeners;
    145113
    }
    146114

    147-
    /**
    148-
    * @return array|null The switch_user parameters if configured, null otherwise
    149-
    */
    150-
    public function getSwitchUser()
    115+
    public function getSwitchUser(): ?array
    151116
    {
    152117
    return $this->switchUser;
    153118
    }

    src/Symfony/Bundle/SecurityBundle/Tests/Security/FirewallMapTest.php

    Lines changed: 1 addition & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -18,7 +18,6 @@
    1818
    use Symfony\Component\DependencyInjection\Container;
    1919
    use Symfony\Component\HttpFoundation\Request;
    2020
    use Symfony\Component\HttpFoundation\RequestMatcherInterface;
    21-
    use Symfony\Component\Security\Core\User\UserCheckerInterface;
    2221
    use Symfony\Component\Security\Http\Firewall\ExceptionListener;
    2322
    use Symfony\Component\Security\Http\Firewall\ListenerInterface;
    2423

    @@ -63,7 +62,7 @@ public function testGetListeners()
    6362

    6463
    $firewallContext = $this->getMockBuilder(FirewallContext::class)->disableOriginalConstructor()->getMock();
    6564

    66-
    $firewallConfig = new FirewallConfig('main', $this->getMockBuilder(UserCheckerInterface::class)->getMock());
    65+
    $firewallConfig = new FirewallConfig('main', 'user_checker');
    6766
    $firewallContext->expects($this->once())->method('getConfig')->willReturn($firewallConfig);
    6867

    6968
    $listener = $this->getMockBuilder(ListenerInterface::class)->getMock();

    src/Symfony/Component/Config/Loader/FileLoader.php

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -81,7 +81,7 @@ public function getLocator()
    8181
    * @throws FileLoaderImportCircularReferenceException
    8282
    * @throws FileLocatorFileNotFoundException
    8383
    */
    84-
    public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
    84+
    public function import($resource, $type = null, bool $ignoreErrors = false, $sourceResource = null)
    8585
    {
    8686
    if (is_string($resource) && strlen($resource) !== $i = strcspn($resource, '*?{[')) {
    8787
    $ret = array();
    @@ -104,7 +104,7 @@ public function import($resource, $type = null, $ignoreErrors = false, $sourceRe
    104104
    /**
    105105
    * @internal
    106106
    */
    107-
    protected function glob($pattern, $recursive, &$resource = null, $ignoreErrors = false)
    107+
    protected function glob(string $pattern, bool $recursive, &$resource = null, bool $ignoreErrors = false)
    108108
    {
    109109
    if (strlen($pattern) === $i = strcspn($pattern, '*?{[')) {
    110110
    $prefix = $pattern;
    @@ -138,7 +138,7 @@ protected function glob($pattern, $recursive, &$resource = null, $ignoreErrors =
    138138
    }
    139139
    }
    140140

    141-
    private function doImport($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
    141+
    private function doImport($resource, $type = null, bool $ignoreErrors = false, $sourceResource = null)
    142142
    {
    143143
    try {
    144144
    $loader = $this->resolve($resource, $type);

    src/Symfony/Component/Console/Event/ConsoleErrorEvent.php

    Lines changed: 7 additions & 32 deletions
    Original file line numberDiff line numberDiff line change
    @@ -12,7 +12,6 @@
    1212
    namespace Symfony\Component\Console\Event;
    1313

    1414
    use Symfony\Component\Console\Command\Command;
    15-
    use Symfony\Component\Console\Exception\In 10000 validArgumentException;
    1615
    use Symfony\Component\Console\Input\InputInterface;
    1716
    use Symfony\Component\Console\Output\OutputInterface;
    1817

    @@ -26,57 +25,33 @@ final class ConsoleErrorEvent extends ConsoleEvent
    2625
    private $error;
    2726
    private $exitCode;
    2827

    29-
    public function __construct(InputInterface $input, OutputInterface $output, $error, Command $command = null)
    28+
    public function __construct(InputInterface $input, OutputInterface $output, \Throwable $error, Command $command = null)
    3029
    {
    3130
    parent::__construct($command, $input, $output);
    3231

    33-
    $this->setError($error);
    32+
    $this->error = $error;
    3433
    }
    3534

    36-
    /**
    37-
    * Returns the thrown error/exception.
    38-
    *
    39-
    * @return \Throwable
    40-
    */
    41-
    public function getError()
    35+
    public function getError(): \Throwable
    4236
    {
    4337
    return $this->error;
    4438
    }
    4539

    46-
    /**
    47-
    * Replaces the thrown error/exception.
    48-
    *
    49-
    * @param \Throwable $error
    50-
    */
    51-
    public function setError($error)
    40+
    public function setError(\Throwable $error): void
    5241
    {
    53-
    if (!$error instanceof \Throwable && !$error instanceof \Exception) {
    54-
    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)));
    55-
    }
    56-
    5742
    $this->error = $error;
    5843
    }
    5944

    60-
    /**
    61-
    * Sets the exit code.
    62-
    *
    63-
    * @param int $exitCode The command exit code
    64-
    */
    65-
    public function setExitCode($exitCode)
    45+
    public function setExitCode(int $exitCode): void
    6646
    {
    67-
    $this->exitCode = (int) $exitCode;
    47+
    $this->exitCode = $exitCode;
    6848

    6949
    $r = new \ReflectionProperty($this->error, 'code');
    7050
    $r->setAccessible(true);
    7151
    $r->setValue($this->error, $this->exitCode);
    7252
    }
    7353

    74-
    /**
    75-
    * Gets the exit code.
    76-
    *
    77-
    * @return int The command exit code
    78-
    */
    79-
    public function getExitCode()
    54+
    public function getExitCode(): int
    8055
    {
    8156
    return null !== $this->exitCode ? $this->exitCode : ($this->error->getCode() ?: 1);
    8257
    }

    0 commit comments

    Comments
     (0)
    0