Skip to content

[Security] add return types #42513

New issue

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

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

Already on GitHub? Sign in to your account

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public function __construct(iterable $expressions, ExpressionLanguage $expressio
$this->expressionLanguage = $expressionLanguage;
}

public function isOptional()
public function isOptional(): bool
{
return true;
}

/**
* @return string[]
*/
public function warmUp(string $cacheDir)
public function warmUp(string $cacheDir): array
{
foreach ($this->expressions as $expression) {
$this->expressionLanguage->parse($expression, ['token', 'user', 'object', 'subject', 'role_names', 'request', 'trust_resolver']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,20 +230,16 @@ public function getUser(): string

/**
* Gets the roles of the user.
*
* @return array|Data
*/
public function getRoles()
public function getRoles(): array|Data
{
return $this->data['roles'];
}

/**
* Gets the inherited roles of the user.
*
* @return array|Data
*/
public function getInheritedRoles()
public function getInheritedRoles(): array|Data
{
return $this->data['inherited_roles'];
}
Expand Down Expand Up @@ -282,10 +278,8 @@ public function getImpersonationExitPath(): ?string

/**
* Get the class name of the security token.
*
* @return string|Data|null
*/
public function getTokenClass()
public function getTokenClass(): string|Data|null
{
return $this->data['token_class'];
}
Expand All @@ -305,7 +299,7 @@ public function getLogoutUrl(): ?string
*
* @return string[]|Data
*/
public function getVoters()
public function getVoters(): array|Data
{
return $this->data['voters'];
}
Expand All @@ -317,28 +311,21 @@ public function getVoterStrategy(): string

/**
* Returns the log of the security decisions made by the access decision manager.
*
* @return array|Data
*/
public function getAccessDecisionLog()
public function getAccessDecisionLog(): array|Data
{
return $this->data['access_decision_log'];
}

/**
* Returns the configuration of the current firewall context.
*
* @return array|Data|null
*/
public function getFirewall()
public function getFirewall(): array|Data|null
{
return $this->data['firewall'];
}

/**
* @return array|Data
*/
public function getListeners()
public function getListeners(): array|Data
{
return $this->data['listeners'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ public function __construct(array $factories, array $userProviderFactories)

/**
* Generates the configuration tree builder.
*
* @return TreeBuilder
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$tb = new TreeBuilder('security');
$rootNode = $tb->getRootNode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ abstract class AbstractFactory implements AuthenticatorFactoryInterface
'failure_path_parameter' => '_failure_path',
];

final public function addOption(string $name, mixed $default = null)
final public function addOption(string $name, mixed $default = null): void
{
$this->options[$name] = $default;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ public function getPriority(): int;
/**
* Defines the configuration key used to reference the provider
* in the firewall configuration.
*
* @return string
*/
public function getKey();
public function getKey(): string;

public function addConfiguration(NodeDefinition $builder);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\AuthenticatorFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\Factory\FirewallListenerFactoryInterface;
use Symfony\Bundle\SecurityBundle\DependencyInjection\Security\UserProvider\UserProviderFactoryInterface;
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\Console\Application;
Expand Down Expand Up @@ -847,17 +848,17 @@ public function addUserProviderFactory(UserProviderFactoryInterface $factory)
/**
* {@inheritdoc}
*/
public function getXsdValidationBasePath()
public function getXsdValidationBasePath(): string|false
{
return __DIR__.'/../Resources/config/schema';
}

public function getNamespace()
public function getNamespace(): string
{
return 'http://symfony.com/schema/dic/security';
}

public function getConfiguration(array $config, ContainerBuilder $container)
public function getConfiguration(array $config, ContainerBuilder $container): ?ConfigurationInterface
{
// first assemble the factories
return new MainConfiguration($this->getSortedFactories(), $this->userProviderFactories);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function onKernelFinishRequest(FinishRequestEvent $event)
/**
* {@inheritdoc}
*/
public static function getSubscribedEvents()
public static function getSubscribedEvents(): array
{
return [
KernelEvents::REQUEST => [
Expand Down
7 changes: 2 additions & 5 deletions src/Symfony/Bundle/SecurityBundle/Security/FirewallMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(ContainerInterface $container, iterable $map)
$this->map = $map;
}

public function getListeners(Request $request)
public function getListeners(Request $request): array
{
$context = $this->getFirewallContext($request);

Expand All @@ -44,10 +44,7 @@ public function getListeners(Request $request)
return [$context->getListeners(), $context->getExceptionListener(), $context->getLogoutListener()];
}

/**
* @return FirewallConfig|null
*/
public function getFirewallConfig(Request $request)
public function getFirewallConfig(Request $request): ?FirewallConfig
{
$context = $this->getFirewallContext($request);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public function isAuthenticated(TokenInterface $token = null): bool
/**
* {@inheritdoc}
*/
public function isRememberMe(TokenInterface $token = null)
public function isRememberMe(TokenInterface $token = null): bool
{
return $token && $token instanceof RememberMeToken;
}

/**
* {@inheritdoc}
*/
public function isFullFledged(TokenInterface $token = null)
public function isFullFledged(TokenInterface $token = null): bool
{
return $this->isAuthenticated($token) && !$this->isRememberMe($token);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class InMemoryTokenProvider implements TokenProviderInterface
/**
* {@inheritdoc}
*/
public function loadTokenBySeries(string $series)
public function loadTokenBySeries(string $series): PersistentTokenInterface
{
if (!isset($this->tokens[$series])) {
throw new TokenNotFoundException('No token found.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,31 +21,23 @@ interface PersistentTokenInterface
{
/**
* Returns the class of the user.
*
* @return string
*/
public function getClass();
public function getClass(): string;

/**
* Returns the series.
*
* @return string
*/
public function getSeries();
public function getSeries(): string;

/**
* Returns the token value.
*
* @return string
*/
public function getTokenValue();
public function getTokenValue(): string;

/**
* Returns the time the token was last used.
*
* @return \DateTime
*/
public function getLastUsed();
public function getLastUsed(): \DateTime;

/**
* Returns the identifier used to authenticate (e.g. their email address or username).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

namespace Symfony\Component\Security\Core\Authentication\Token;

use Symfony\Component\Security\Core\User\EquatableInterface;
use Symfony\Component\Security\Core\User\LegacyPasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
use Symfony\Component\Security\Core\User\UserInterface;

/**
Expand Down Expand Up @@ -56,7 +53,7 @@ public function getUserIdentifier(): string
/**
* {@inheritdoc}
*/
public function getUser()
public function getUser(): ?UserInterface
{
return $this->user;
}
Expand Down Expand Up @@ -123,7 +120,7 @@ public function __unserialize(array $data): void
/**
* {@inheritdoc}
*/
public function getAttributes()
public function getAttributes(): array
{
return $this->attributes;
}
Expand All @@ -139,15 +136,15 @@ public function setAttributes(array $attributes)
/**
* {@inheritdoc}
*/
public function hasAttribute(string $name)
public function hasAttribute(string $name): bool
{
return \array_key_exists($name, $this->attributes);
}

/**
* {@inheritdoc}
*/
public function getAttribute(string $name)
public function getAttribute(string $name): mixed
{
if (!\array_key_exists($name, $this->attributes)) {
throw new \InvalidArgumentException(sprintf('This token has no "%s" attribute.', $name));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getRoleNames(): array
return [];
}

public function getUser()
public function getUser(): ?UserInterface
{
return null;
}
Expand All @@ -47,7 +47,7 @@ public function eraseCredentials()
{
}

public function getAttributes()
public function getAttributes(): array
{
return [];
}
Expand All @@ -57,12 +57,12 @@ public function setAttributes(array $attributes)
throw new \BadMethodCallException('Cannot set attributes of NullToken.');
}

public function hasAttribute(string $name)
public function hasAttribute(string $name): bool
{
return false;
}

public function getAttribute(string $name)
public function getAttribute(string $name): mixed
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public function getFirewallName(): string
return $this->firewallName;
}

/**
* @return string
*/
public function getSecret()
public function getSecret(): string
{
return $this->secret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class TokenStorage implements TokenStorageInterface, ResetInterface
/**
* {@inheritdoc}
*/
public function getToken()
public function getToken(): ?TokenInterface
{
if ($initializer = $this->initializer) {
$this->initializer = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ interface TokenStorageInterface
{
/**
* Returns the current security token.
*
* @return TokenInterface|null
*/
public function getToken();
public function getToken(): ?TokenInterface;

/**
* Sets the authentication token.
Expand Down
Loading