From 1e5f4687948cec59ec0186f7e3540cc41eaf1d11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20Eugon=C3=A9?= Date: Wed, 3 Dec 2025 11:06:18 +0100 Subject: [PATCH] Updated ECS & checkstyle rules to latest standard --- composer.json | 2 +- ecs.php | 94 ++++++++++++++----- src/Archive/DeleteArchivist.php | 4 +- src/Command/ArchiveTokenCommand.php | 4 +- src/Configuration/TokenConfiguration.php | 4 +- .../TokenConfigurationRegistry.php | 4 +- src/DependencyInjection/Configuration.php | 2 +- .../Factory/TokenConfigurationFactory.php | 14 +-- .../YokaiSecurityTokenExtension.php | 8 +- src/Entity/Token.php | 8 +- src/Entity/TokenUsage.php | 2 +- src/Event/ConsumeTokenEvent.php | 6 +- src/Event/CreateTokenEvent.php | 4 +- src/Event/TokenAlreadyConsumedEvent.php | 2 +- src/Event/TokenConsumedEvent.php | 2 +- src/Event/TokenCreatedEvent.php | 2 +- src/Event/TokenExpiredEvent.php | 2 +- src/Event/TokenNotFoundEvent.php | 2 +- src/Event/TokenRetrievedEvent.php | 2 +- src/Event/TokenTotallyConsumedEvent.php | 2 +- src/EventDispatcher.php | 20 ++-- src/Exception/InvalidTokenException.php | 2 +- src/Exception/TokenConsumedException.php | 8 +- src/Exception/TokenExpiredException.php | 8 +- src/Exception/TokenNotFoundException.php | 8 +- src/Factory/TokenFactory.php | 4 +- src/Generator/OpenSslTokenGenerator.php | 6 +- src/InformationGuesser/InformationGuesser.php | 4 +- src/Manager/ChainUserManager.php | 28 +++--- src/Manager/DoctrineUserManager.php | 18 ++-- src/Manager/TokenManager.php | 4 +- src/Repository/DoctrineORMTokenRepository.php | 6 +- src/Repository/TokenRepositoryInterface.php | 2 +- src/YokaiSecurityTokenBundle.php | 10 +- tests/Command/ArchiveTokenCommandTest.php | 14 +-- .../DependencyInjectionTest.php | 15 ++- tests/Entity/TokenTest.php | 12 +-- tests/Factory/TokenFactoryTest.php | 13 +-- tests/Generator/OpenSslTokenGeneratorTest.php | 9 +- .../InformationGuesserTest.php | 12 +-- tests/Kernel.php | 6 +- tests/Manager/ChainUserManagerTest.php | 44 ++------- tests/Manager/DoctrineUserManagerTest.php | 49 ++++------ tests/Manager/Mock/UserDocument.php | 2 +- tests/Manager/Mock/UserEntity.php | 2 +- tests/Manager/TokenManagerTest.php | 43 +++------ .../DoctrineORMTokenRepositoryTest.php | 39 ++------ 47 files changed, 247 insertions(+), 311 deletions(-) diff --git a/composer.json b/composer.json index 6cffae7..3990831 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "phpunit/phpunit": "^9.5", "symfony/yaml": "^6.4|^7.4|^8.0", "phpstan/phpstan": "^1.7", - "symplify/easy-coding-standard": "^11.3" + "symplify/easy-coding-standard": "^13.0" }, "autoload": { "psr-4": { "Yokai\\SecurityTokenBundle\\": "src/" } diff --git a/ecs.php b/ecs.php index d763c4e..2429706 100644 --- a/ecs.php +++ b/ecs.php @@ -3,39 +3,81 @@ declare(strict_types=1); use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff; +use PhpCsFixer\Fixer\Basic\SingleLineEmptyBodyFixer; +use PhpCsFixer\Fixer\CastNotation\CastSpacesFixer; +use PhpCsFixer\Fixer\ClassNotation\ClassDefinitionFixer; +use PhpCsFixer\Fixer\ClassNotation\FinalClassFixer; +use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer; use PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer; +use PhpCsFixer\Fixer\FunctionNotation\NativeFunctionInvocationFixer; +use PhpCsFixer\Fixer\LanguageConstruct\NullableTypeDeclarationFixer; +use PhpCsFixer\Fixer\StringNotation\ExplicitStringVariableFixer; +use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer; use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayListItemNewlineFixer; use Symplify\CodingStandard\Fixer\ArrayNotation\ArrayOpenerAndCloserNewlineFixer; use Symplify\CodingStandard\Fixer\ArrayNotation\StandaloneLineInMultilineArrayFixer; +use Symplify\CodingStandard\Fixer\LineLength\LineLengthFixer; use Symplify\EasyCodingStandard\Config\ECSConfig; -use Symplify\EasyCodingStandard\ValueObject\Set\SetList; -return function (ECSConfig $ecsConfig): void { - $ecsConfig->paths([ +return ECSConfig::configure() + ->withPaths([ __DIR__ . '/src', __DIR__ . '/tests', - ]); - - $ecsConfig->sets([ - SetList::ARRAY, - SetList::DOCBLOCK, - SetList::NAMESPACES, - SetList::COMMENTS, - SetList::STRICT, - SetList::PSR_12, - ]); - - $ecsConfig->skip([ - /* Do not force array on multiple lines : ['foo' => $foo, 'bar' => $bar] */ - ArrayOpenerAndCloserNewlineFixer::class, - ArrayListItemNewlineFixer::class, - StandaloneLineInMultilineArrayFixer::class, - ]); - - $ecsConfig->ruleWithConfiguration(ForbiddenFunctionsSniff::class, [ + ]) + ->withPhpCsFixerSets( + // https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/PER-CS2.0.rst + perCS20: true, + ) + ->withPreparedSets( + arrays: true, + comments: true, + docblocks: true, + namespaces: true, + phpunit: true, + strict: true, + ) + ->withRules([ + FinalClassFixer::class, + ]) + ->withConfiguredRule(BlankLineBeforeStatementFixer::class, [ + 'statements' => ['case', 'continue', 'declare', 'default', 'return', 'throw', 'try'], + ]) + ->withConfiguredRule(CastSpacesFixer::class, [ + 'space' => 'none', + ]) + ->withConfiguredRule(ForbiddenFunctionsSniff::class, [ 'forbiddenFunctions' => ['dump' => null, 'dd' => null, 'var_dump' => null, 'die' => null], - ]); - $ecsConfig->ruleWithConfiguration(FunctionDeclarationFixer::class, [ + ]) + ->withConfiguredRule(FunctionDeclarationFixer::class, [ 'closure_fn_spacing' => 'none', - ]); -}; + ]) + ->withConfiguredRule(LineLengthFixer::class, [ + LineLengthFixer::INLINE_SHORT_LINES => false, + ]) + ->withConfiguredRule(NativeFunctionInvocationFixer::class, [ + 'scope' => 'namespaced', + 'include' => ['@all'], + ]) + ->withConfiguredRule(NullableTypeDeclarationFixer::class, [ + 'syntax' => 'union', + ]) + ->withConfiguredRule(YodaStyleFixer::class, [ + 'equal' => false, + 'identical' => false, + 'less_and_greater' => false, + ]) + ->withConfiguredRule(ClassDefinitionFixer::class, [ + 'inline_constructor_arguments' => false, + 'space_before_parenthesis' => false, + ]) + ->withSkip([ + ArrayListItemNewlineFixer::class, + ArrayOpenerAndCloserNewlineFixer::class, + ExplicitStringVariableFixer::class, + SingleLineEmptyBodyFixer::class, + StandaloneLineInMultilineArrayFixer::class, + FinalClassFixer::class => [ + 'src/Entity/', + ], + ]) +; diff --git a/src/Archive/DeleteArchivist.php b/src/Archive/DeleteArchivist.php index 7c99b6a..fcd2f52 100644 --- a/src/Archive/DeleteArchivist.php +++ b/src/Archive/DeleteArchivist.php @@ -12,7 +12,7 @@ * * @author Yann Eugoné */ -class DeleteArchivist implements ArchivistInterface +final class DeleteArchivist implements ArchivistInterface { /** * @var EntityRepository @@ -47,6 +47,6 @@ public function archive(string|null $purpose = null): int /** @var int|string $result */ $result = $builder->getQuery()->execute(); - return intval($result); + return \intval($result); } } diff --git a/src/Command/ArchiveTokenCommand.php b/src/Command/ArchiveTokenCommand.php index d453fe6..3530815 100644 --- a/src/Command/ArchiveTokenCommand.php +++ b/src/Command/ArchiveTokenCommand.php @@ -13,7 +13,7 @@ /** * @author Yann Eugoné */ -class ArchiveTokenCommand extends Command +final class ArchiveTokenCommand extends Command { /** * @var ArchivistInterface @@ -42,7 +42,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $count = $this->archivist->archive($purpose); $output->writeln( - sprintf('Successfully archived %d security token(s).', $count) + \sprintf('Successfully archived %d security token(s).', $count), ); return 0; diff --git a/src/Configuration/TokenConfiguration.php b/src/Configuration/TokenConfiguration.php index 14259e5..a674878 100644 --- a/src/Configuration/TokenConfiguration.php +++ b/src/Configuration/TokenConfiguration.php @@ -9,7 +9,7 @@ /** * @author Yann Eugoné */ -class TokenConfiguration +final class TokenConfiguration { /** * @var string @@ -47,7 +47,7 @@ public function __construct( string $duration, int $usages, string $keep, - bool $unique + bool $unique, ) { $this->purpose = $purpose; $this->generator = $generator; diff --git a/src/Configuration/TokenConfigurationRegistry.php b/src/Configuration/TokenConfigurationRegistry.php index 78218a6..5568eaa 100644 --- a/src/Configuration/TokenConfigurationRegistry.php +++ b/src/Configuration/TokenConfigurationRegistry.php @@ -9,7 +9,7 @@ /** * @author Yann Eugoné */ -class TokenConfigurationRegistry +final class TokenConfigurationRegistry { /** * @var array @@ -38,7 +38,7 @@ public function get(string $purpose): TokenConfiguration { if (!isset($this->configurations[$purpose])) { throw new BadMethodCallException( - sprintf('There is no configured security token on "%s" purpose.', $purpose) + \sprintf('There is no configured security token on "%s" purpose.', $purpose), ); } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index d261276..aa37a13 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -11,7 +11,7 @@ /** * @author Yann Eugoné */ -class Configuration implements ConfigurationInterface +final class Configuration implements ConfigurationInterface { public function getConfigTreeBuilder(): TreeBuilder { diff --git a/src/DependencyInjection/Factory/TokenConfigurationFactory.php b/src/DependencyInjection/Factory/TokenConfigurationFactory.php index 1c065f5..2ef4b15 100644 --- a/src/DependencyInjection/Factory/TokenConfigurationFactory.php +++ b/src/DependencyInjection/Factory/TokenConfigurationFactory.php @@ -13,7 +13,7 @@ /** * @author Yann Eugoné */ -class TokenConfigurationFactory +final class TokenConfigurationFactory { public static function create( string $purpose, @@ -22,18 +22,18 @@ public static function create( int $usages, string $keep, bool $unique, - ContainerBuilder $container + ContainerBuilder $container, ): void { - $id = sprintf('yokai_security_token.configuration.%s', $purpose); + $id = \sprintf('yokai_security_token.configuration.%s', $purpose); if ($container->hasDefinition($id)) { throw new BadMethodCallException( - sprintf( + \sprintf( 'Cannot register service for security token on "%s" purpose.' . ' A service with id "%s" is already registered.', $purpose, - $id - ) + $id, + ), ); } @@ -46,7 +46,7 @@ public static function create( $usages, $keep, $unique, - ] + ], ); $definition->addTag('yokai_security_token.configuration'); diff --git a/src/DependencyInjection/YokaiSecurityTokenExtension.php b/src/DependencyInjection/YokaiSecurityTokenExtension.php index 3b3f864..e6de3d4 100644 --- a/src/DependencyInjection/YokaiSecurityTokenExtension.php +++ b/src/DependencyInjection/YokaiSecurityTokenExtension.php @@ -19,7 +19,7 @@ /** * @author Yann Eugoné */ -class YokaiSecurityTokenExtension extends Extension +final class YokaiSecurityTokenExtension extends Extension { public function load(array $configs, ContainerBuilder $container): void { @@ -43,7 +43,7 @@ private function registerTokens(array $config, ContainerBuilder $container): voi $token['usages'], $token['keep'], $token['unique'], - $container + $container, ); } } @@ -53,7 +53,7 @@ private function registerAliases(array $config, ContainerBuilder $container): vo $isTest = $container->getParameter('kernel.environment') === 'test'; foreach ($config['services'] as $name => $service) { - $alias = $container->setAlias(sprintf('yokai_security_token.%s', $name), $service); + $alias = $container->setAlias(\sprintf('yokai_security_token.%s', $name), $service); $alias->setPublic(true); } } @@ -70,7 +70,7 @@ private function registerAutoconfigureAliases(ContainerBuilder $container): void ]; foreach ($interfaceMap as $service => $interface) { - $container->setAlias($interface, sprintf('yokai_security_token.%s', $service)); + $container->setAlias($interface, \sprintf('yokai_security_token.%s', $service)); } } } diff --git a/src/Entity/Token.php b/src/Entity/Token.php index 772317a..7dac656 100644 --- a/src/Entity/Token.php +++ b/src/Entity/Token.php @@ -88,7 +88,7 @@ public function __construct( string $keepDuration, int $allowedUsages = 1, array $payload = [], - array $information = [] + array $information = [], ) { $this->userClass = $userClass; $this->userId = $userId; @@ -103,7 +103,7 @@ public function __construct( $this->usages = new ArrayCollection(); } - public function getId(): ?int + public function getId(): int|null { return $this->id; } @@ -181,7 +181,7 @@ public function getAllowedUsages(): int public function getCountUsages(): int { - return count($this->usages); + return \count($this->usages); } /** @@ -204,7 +204,7 @@ public function consume(array $information, DateTime|null $date = null): void { if ($this->isConsumed()) { throw new LogicException( - sprintf('Token "%d" is already consumed.', $this->id) + \sprintf('Token "%d" is already consumed.', $this->id), ); } diff --git a/src/Entity/TokenUsage.php b/src/Entity/TokenUsage.php index 288ba12..28822c9 100644 --- a/src/Entity/TokenUsage.php +++ b/src/Entity/TokenUsage.php @@ -38,7 +38,7 @@ public function __construct(Token $token, array $information, DateTime|null $cre $this->createdAt = $createdAt ?: new DateTime(); } - public function getId(): ?int + public function getId(): int|null { return $this->id; } diff --git a/src/Event/ConsumeTokenEvent.php b/src/Event/ConsumeTokenEvent.php index 33bd8ed..433fb3a 100644 --- a/src/Event/ConsumeTokenEvent.php +++ b/src/Event/ConsumeTokenEvent.php @@ -13,7 +13,7 @@ * * @author Yann Eugoné */ -class ConsumeTokenEvent extends Event +final class ConsumeTokenEvent extends Event { /** * @var Token @@ -35,7 +35,7 @@ class ConsumeTokenEvent extends Event * @param DateTime|null $at Date/time at which the token has been consumed * @param array $information Some context information */ - public function __construct(Token $token, ?DateTime $at, array $information) + public function __construct(Token $token, DateTime|null $at, array $information) { $this->token = $token; $this->at = $at; @@ -53,7 +53,7 @@ public function getToken(): Token /** * Date/time at which the token has been consumed */ - public function getAt(): ?DateTime + public function getAt(): DateTime|null { return $this->at; } diff --git a/src/Event/CreateTokenEvent.php b/src/Event/CreateTokenEvent.php index acb1b20..95137f9 100644 --- a/src/Event/CreateTokenEvent.php +++ b/src/Event/CreateTokenEvent.php @@ -11,7 +11,7 @@ * * @author Yann Eugoné */ -class CreateTokenEvent extends Event +final class CreateTokenEvent extends Event { /** * @var string @@ -85,6 +85,6 @@ public function setPayload(array $payload): void */ public function addPayload(array $payload): void { - $this->payload = array_merge($this->payload, $payload); + $this->payload = \array_merge($this->payload, $payload); } } diff --git a/src/Event/TokenAlreadyConsumedEvent.php b/src/Event/TokenAlreadyConsumedEvent.php index fbb9785..b9fc6f4 100644 --- a/src/Event/TokenAlreadyConsumedEvent.php +++ b/src/Event/TokenAlreadyConsumedEvent.php @@ -11,7 +11,7 @@ * * @author Yann Eugoné */ -class TokenAlreadyConsumedEvent extends Event +final class TokenAlreadyConsumedEvent extends Event { /** * @var string diff --git a/src/Event/TokenConsumedEvent.php b/src/Event/TokenConsumedEvent.php index 90855ad..b8b3193 100644 --- a/src/Event/TokenConsumedEvent.php +++ b/src/Event/TokenConsumedEvent.php @@ -12,7 +12,7 @@ * * @author Yann Eugoné */ -class TokenConsumedEvent extends Event +final class TokenConsumedEvent extends Event { /** * @var Token diff --git a/src/Event/TokenCreatedEvent.php b/src/Event/TokenCreatedEvent.php index 04f47d1..cbb52ba 100644 --- a/src/Event/TokenCreatedEvent.php +++ b/src/Event/TokenCreatedEvent.php @@ -12,7 +12,7 @@ * * @author Yann Eugoné */ -class TokenCreatedEvent extends Event +final class TokenCreatedEvent extends Event { /** * @var Token diff --git a/src/Event/TokenExpiredEvent.php b/src/Event/TokenExpiredEvent.php index 1e71451..85f92cc 100644 --- a/src/Event/TokenExpiredEvent.php +++ b/src/Event/TokenExpiredEvent.php @@ -11,7 +11,7 @@ * * @author Yann Eugoné */ -class TokenExpiredEvent extends Event +final class TokenExpiredEvent extends Event { /** * @var string diff --git a/src/Event/TokenNotFoundEvent.php b/src/Event/TokenNotFoundEvent.php index e4b4656..eb95f16 100644 --- a/src/Event/TokenNotFoundEvent.php +++ b/src/Event/TokenNotFoundEvent.php @@ -11,7 +11,7 @@ * * @author Yann Eugoné */ -class TokenNotFoundEvent extends Event +final class TokenNotFoundEvent extends Event { /** * @var string diff --git a/src/Event/TokenRetrievedEvent.php b/src/Event/TokenRetrievedEvent.php index c5c4584..fcca274 100644 --- a/src/Event/TokenRetrievedEvent.php +++ b/src/Event/TokenRetrievedEvent.php @@ -12,7 +12,7 @@ * * @author Yann Eugoné */ -class TokenRetrievedEvent extends Event +final class TokenRetrievedEvent extends Event { /** * @var Token diff --git a/src/Event/TokenTotallyConsumedEvent.php b/src/Event/TokenTotallyConsumedEvent.php index f90bc8d..209a858 100644 --- a/src/Event/TokenTotallyConsumedEvent.php +++ b/src/Event/TokenTotallyConsumedEvent.php @@ -12,7 +12,7 @@ * * @author Yann Eugoné */ -class TokenTotallyConsumedEvent extends Event +final class TokenTotallyConsumedEvent extends Event { /** * @var Token diff --git a/src/EventDispatcher.php b/src/EventDispatcher.php index 91e7f84..1d42d28 100644 --- a/src/EventDispatcher.php +++ b/src/EventDispatcher.php @@ -20,7 +20,7 @@ /** * @author Yann Eugoné */ -class EventDispatcher +final class EventDispatcher { /** * @var EventDispatcherInterface @@ -38,7 +38,7 @@ public function __construct(EventDispatcherInterface $eventDispatcher) public function createToken(string $purpose, $user, array $payload): CreateTokenEvent { $this->eventDispatcher->dispatch( - $event = new CreateTokenEvent($purpose, $user, $payload) + $event = new CreateTokenEvent($purpose, $user, $payload), ); return $event; @@ -47,7 +47,7 @@ public function createToken(string $purpose, $user, array $payload): CreateToken public function tokenCreated(Token $token): TokenCreatedEvent { $this->eventDispatcher->dispatch( - $event = new TokenCreatedEvent($token) + $event = new TokenCreatedEvent($token), ); return $event; @@ -56,7 +56,7 @@ public function tokenCreated(Token $token): TokenCreatedEvent public function consumeToken(Token $token, DateTime|null $at = null, array $information = []): ConsumeTokenEvent { $this->eventDispatcher->dispatch( - $event = new ConsumeTokenEvent($token, $at, $information) + $event = new ConsumeTokenEvent($token, $at, $information), ); return $event; @@ -65,7 +65,7 @@ public function consumeToken(Token $token, DateTime|null $at = null, array $info public function tokenConsumed(Token $token): TokenConsumedEvent { $this->eventDispatcher->dispatch( - $event = new TokenConsumedEvent($token) + $event = new TokenConsumedEvent($token), ); return $event; @@ -74,7 +74,7 @@ public function tokenConsumed(Token $token): TokenConsumedEvent public function tokenTotallyConsumed(Token $token): TokenTotallyConsumedEvent { $this->eventDispatcher->dispatch( - $event = new TokenTotallyConsumedEvent($token) + $event = new TokenTotallyConsumedEvent($token), ); return $event; @@ -83,7 +83,7 @@ public function tokenTotallyConsumed(Token $token): TokenTotallyConsumedEvent public function tokenNotFound(string $purpose, string $value): TokenNotFoundEvent { $this->eventDispatcher->dispatch( - $event = new TokenNotFoundEvent($purpose, $value) + $event = new TokenNotFoundEvent($purpose, $value), ); return $event; @@ -92,7 +92,7 @@ public function tokenNotFound(string $purpose, string $value): TokenNotFoundEven public function tokenExpired(string $purpose, string $value): TokenExpiredEvent { $this->eventDispatcher->dispatch( - $event = new TokenExpiredEvent($purpose, $value) + $event = new TokenExpiredEvent($purpose, $value), ); return $event; @@ -101,7 +101,7 @@ public function tokenExpired(string $purpose, string $value): TokenExpiredEvent public function tokenAlreadyConsumed(string $purpose, string $value): TokenAlreadyConsumedEvent { $this->eventDispatcher->dispatch( - $event = new TokenAlreadyConsumedEvent($purpose, $value) + $event = new TokenAlreadyConsumedEvent($purpose, $value), ); return $event; @@ -110,7 +110,7 @@ public function tokenAlreadyConsumed(string $purpose, string $value): TokenAlrea public function tokenRetrieved(Token $token): TokenRetrievedEvent { $this->eventDispatcher->dispatch( - $event = new TokenRetrievedEvent($token) + $event = new TokenRetrievedEvent($token), ); return $event; diff --git a/src/Exception/InvalidTokenException.php b/src/Exception/InvalidTokenException.php index 73c7d7b..5d26b88 100644 --- a/src/Exception/InvalidTokenException.php +++ b/src/Exception/InvalidTokenException.php @@ -11,6 +11,6 @@ * * @author Yann Eugoné */ -class InvalidTokenException extends RuntimeException +abstract class InvalidTokenException extends RuntimeException { } diff --git a/src/Exception/TokenConsumedException.php b/src/Exception/TokenConsumedException.php index b1ae61b..83825e9 100644 --- a/src/Exception/TokenConsumedException.php +++ b/src/Exception/TokenConsumedException.php @@ -9,7 +9,7 @@ * * @author Yann Eugoné */ -class TokenConsumedException extends InvalidTokenException +final class TokenConsumedException extends InvalidTokenException { /** * Create an instance of this class. @@ -21,12 +21,12 @@ class TokenConsumedException extends InvalidTokenException public static function create(string $value, string $purpose, int $usages): self { return new self( - sprintf( + \sprintf( 'The "%s" token with value "%s" was used times "%s".', $purpose, $value, - $usages - ) + $usages, + ), ); } } diff --git a/src/Exception/TokenExpiredException.php b/src/Exception/TokenExpiredException.php index 42b7719..0cb82e0 100644 --- a/src/Exception/TokenExpiredException.php +++ b/src/Exception/TokenExpiredException.php @@ -11,7 +11,7 @@ * * @author Yann Eugoné */ -class TokenExpiredException extends InvalidTokenException +final class TokenExpiredException extends InvalidTokenException { /** * Create an instance of this class. @@ -23,12 +23,12 @@ class TokenExpiredException extends InvalidTokenException public static function create(string $value, string $purpose, DateTime $date): self { return new self( - sprintf( + \sprintf( 'The "%s" token with value "%s" is expired since "%s".', $purpose, $value, - $date->format(DateTime::ISO8601) - ) + $date->format(DateTime::ISO8601), + ), ); } } diff --git a/src/Exception/TokenNotFoundException.php b/src/Exception/TokenNotFoundException.php index ee8ef4c..9495371 100644 --- a/src/Exception/TokenNotFoundException.php +++ b/src/Exception/TokenNotFoundException.php @@ -9,7 +9,7 @@ * * @author Yann Eugoné */ -class TokenNotFoundException extends InvalidTokenException +final class TokenNotFoundException extends InvalidTokenException { /** * Create an instance of this class. @@ -20,11 +20,11 @@ class TokenNotFoundException extends InvalidTokenException public static function create(string $value, string $purpose): self { return new self( - sprintf( + \sprintf( 'The "%s" token with value "%s" was not found.', $purpose, - $value - ) + $value, + ), ); } } diff --git a/src/Factory/TokenFactory.php b/src/Factory/TokenFactory.php index eeab187..9034751 100644 --- a/src/Factory/TokenFactory.php +++ b/src/Factory/TokenFactory.php @@ -15,7 +15,7 @@ * * @author Yann Eugoné */ -class TokenFactory implements TokenFactoryInterface +final class TokenFactory implements TokenFactoryInterface { /** * @var TokenConfigurationRegistry @@ -47,7 +47,7 @@ public function __construct( TokenConfigurationRegistry $registry, InformationGuesserInterface $informationGuesser, UserManagerInterface $userManager, - TokenRepositoryInterface $repository + TokenRepositoryInterface $repository, ) { $this->registry = $registry; $this->informationGuesser = $informationGuesser; diff --git a/src/Generator/OpenSslTokenGenerator.php b/src/Generator/OpenSslTokenGenerator.php index adc3617..84f4f77 100644 --- a/src/Generator/OpenSslTokenGenerator.php +++ b/src/Generator/OpenSslTokenGenerator.php @@ -11,7 +11,7 @@ * * @author Yann Eugoné */ -class OpenSslTokenGenerator implements TokenGeneratorInterface +final class OpenSslTokenGenerator implements TokenGeneratorInterface { private const DEFAULT_LENGTH = 32; @@ -22,7 +22,7 @@ class OpenSslTokenGenerator implements TokenGeneratorInterface public function __construct(int $length = self::DEFAULT_LENGTH) { - if (!function_exists('openssl_random_pseudo_bytes')) { + if (!\function_exists('openssl_random_pseudo_bytes')) { throw new LogicException('The extension "openssl" is required to use "open ssl" token generator.'); } @@ -31,6 +31,6 @@ public function __construct(int $length = self::DEFAULT_LENGTH) public function generate(): string { - return rtrim(strtr(base64_encode((string)openssl_random_pseudo_bytes($this->length)), '+/', '-_'), '='); + return \rtrim(\strtr(\base64_encode((string)\openssl_random_pseudo_bytes($this->length)), '+/', '-_'), '='); } } diff --git a/src/InformationGuesser/InformationGuesser.php b/src/InformationGuesser/InformationGuesser.php index b87910e..648fb9d 100644 --- a/src/InformationGuesser/InformationGuesser.php +++ b/src/InformationGuesser/InformationGuesser.php @@ -11,7 +11,7 @@ * * @author Yann Eugoné */ -class InformationGuesser implements InformationGuesserInterface +final class InformationGuesser implements InformationGuesserInterface { /** * @var RequestStack @@ -35,7 +35,7 @@ public function get(): array return [ 'ip' => $request->getClientIp(), - 'host' => gethostname(), + 'host' => \gethostname(), ]; } } diff --git a/src/Manager/ChainUserManager.php b/src/Manager/ChainUserManager.php index 2b445ed..ad0221d 100644 --- a/src/Manager/ChainUserManager.php +++ b/src/Manager/ChainUserManager.php @@ -9,7 +9,7 @@ * * @author Yann Eugoné */ -class ChainUserManager implements UserManagerInterface +final class ChainUserManager implements UserManagerInterface { /** * @var iterable @@ -77,15 +77,15 @@ private function getManagerForClass(string $class): UserManagerInterface return $manager; } - $tries[] = get_class($manager); + $tries[] = \get_class($manager); } throw new \InvalidArgumentException( - sprintf( + \sprintf( 'Class "%s" is not supported by any UserManager. Tried "%s".', $class, - implode('", "', $tries) - ) + \implode('", "', $tries), + ), ); } @@ -105,29 +105,29 @@ private function getManagerForUser($user): UserManagerInterface return $manager; } - $tries[] = get_class($manager); + $tries[] = \get_class($manager); } - if (is_object($user)) { - if (!method_exists($user, '__toString')) { - $userAsString = sprintf('%s::%s', get_class($user), spl_object_hash($user)); + if (\is_object($user)) { + if (!\method_exists($user, '__toString')) { + $userAsString = \sprintf('%s::%s', \get_class($user), \spl_object_hash($user)); } else { $userAsString = (string)$user; } } else { - if (is_scalar($user)) { + if (\is_scalar($user)) { $userAsString = (string)$user; } else { - $userAsString = get_debug_type($user); + $userAsString = \get_debug_type($user); } } throw new \InvalidArgumentException( - sprintf( + \sprintf( 'User "%s" is not supported by any UserManager. Tried "%s".', $userAsString, - implode('", "', $tries) - ) + \implode('", "', $tries), + ), ); } } diff --git a/src/Manager/DoctrineUserManager.php b/src/Manager/DoctrineUserManager.php index aca3021..531009e 100644 --- a/src/Manager/DoctrineUserManager.php +++ b/src/Manager/DoctrineUserManager.php @@ -13,7 +13,7 @@ * * @author Yann Eugoné */ -class DoctrineUserManager implements UserManagerInterface +final class DoctrineUserManager implements UserManagerInterface { /** * @var ManagerRegistry @@ -42,7 +42,7 @@ public function supportsClass(string $class): bool public function supportsUser($user): bool { return $this->supportsClass( - $this->getClass($user) + $this->getClass($user), ); } @@ -65,14 +65,14 @@ public function getId($user): string $class = $this->getClass($user); $identifiers = $this->getManagerFor($class)->getClassMetadata($class)->getIdentifierValues($user); - if (count($identifiers) > 1) { + if (\count($identifiers) > 1) { throw new \InvalidArgumentException('Entities with composite ids are not supported'); } - $identifier = reset($identifiers); - if (is_scalar($identifier) + $identifier = \reset($identifiers); + if (\is_scalar($identifier) || $identifier === null - || (is_object($identifier) && method_exists($identifier, '__toString')) + || (\is_object($identifier) && \method_exists($identifier, '__toString')) ) { return (string)$identifier; } @@ -91,10 +91,10 @@ private function getManagerFor(string $class): ObjectManager if ($manager === null) { throw new \InvalidArgumentException( - sprintf( + \sprintf( 'Class "%s" seems not to be a managed Doctrine entity. Did you forget to map it?', - $class - ) + $class, + ), ); } diff --git a/src/Manager/TokenManager.php b/src/Manager/TokenManager.php index 374c2fb..2f4bec8 100644 --- a/src/Manager/TokenManager.php +++ b/src/Manager/TokenManager.php @@ -17,7 +17,7 @@ /** * @author Yann Eugoné */ -class TokenManager implements TokenManagerInterface +final class TokenManager implements TokenManagerInterface { /** * @var TokenFactoryInterface @@ -56,7 +56,7 @@ public function __construct( TokenRepositoryInterface $repository, InformationGuesserInterface $informationGuesser, UserManagerInterface $userManager, - EventDispatcher $eventDispatcher + EventDispatcher $eventDispatcher, ) { $this->factory = $factory; $this->repository = $repository; diff --git a/src/Repository/DoctrineORMTokenRepository.php b/src/Repository/DoctrineORMTokenRepository.php index 42c0120..7050317 100644 --- a/src/Repository/DoctrineORMTokenRepository.php +++ b/src/Repository/DoctrineORMTokenRepository.php @@ -16,7 +16,7 @@ * * @author Yann Eugoné */ -class DoctrineORMTokenRepository implements TokenRepositoryInterface +final class DoctrineORMTokenRepository implements TokenRepositoryInterface { /** * @var EntityManager @@ -60,7 +60,7 @@ public function get(string $value, string $purpose): Token return $token; } - public function findExisting(string $userClass, string $userId, string $purpose): ?Token + public function findExisting(string $userClass, string $userId, string $purpose): Token|null { $token = $this->repository->findOneBy( [ @@ -103,7 +103,7 @@ public function exists(string $value, string $purpose): bool /** @var string|int $result */ $result = $builder->getQuery()->getSingleScalarResult(); - return intval($result) > 0; + return \intval($result) > 0; } private function save(Token $token): void diff --git a/src/Repository/TokenRepositoryInterface.php b/src/Repository/TokenRepositoryInterface.php index 2aa3324..eb3f857 100644 --- a/src/Repository/TokenRepositoryInterface.php +++ b/src/Repository/TokenRepositoryInterface.php @@ -39,7 +39,7 @@ public function get(string $value, string $purpose): Token; * * @return Token|null The token object from storage of null if not found */ - public function findExisting(string $userClass, string $userId, string $purpose): ?Token; + public function findExisting(string $userClass, string $userId, string $purpose): Token|null; /** * Tell whether or not it exists a token for given purpose and value. diff --git a/src/YokaiSecurityTokenBundle.php b/src/YokaiSecurityTokenBundle.php index ceb08d3..a9cdd58 100644 --- a/src/YokaiSecurityTokenBundle.php +++ b/src/YokaiSecurityTokenBundle.php @@ -14,7 +14,7 @@ /** * @author Yann Eugoné */ -class YokaiSecurityTokenBundle extends Bundle +final class YokaiSecurityTokenBundle extends Bundle { public function getPath(): string { @@ -27,18 +27,18 @@ public function build(ContainerBuilder $container): void 'yokai_security_token.configuration_registry', 'yokai_security_token.configuration', null, - 0 + 0, ); $registerUserManager = new ArgumentRegisterTaggedServicesCompilerPass( 'yokai_security_token.user_manager', 'yokai_security_token.user_manager', UserManagerInterface::class, - 0 + 0, ); $registerEntityMapping = DoctrineOrmMappingsPass::createXmlMappingDriver( - [realpath(__DIR__ . '/../config/doctrine') => 'Yokai\SecurityTokenBundle\Entity'], + [\realpath(__DIR__ . '/../config/doctrine') => 'Yokai\SecurityTokenBundle\Entity'], ['doctrine.orm.entity_manager'], - false + false, ); $container diff --git a/tests/Command/ArchiveTokenCommandTest.php b/tests/Command/ArchiveTokenCommandTest.php index 17d9871..cac4188 100644 --- a/tests/Command/ArchiveTokenCommandTest.php +++ b/tests/Command/ArchiveTokenCommandTest.php @@ -16,7 +16,7 @@ * * phpcs:ignoreFile PSR1.Methods.CamelCapsMethodName.NotCamelCaps */ -class ArchiveTokenCommandTest extends KernelTestCase +final class ArchiveTokenCommandTest extends KernelTestCase { /** * @var MockObject @@ -44,7 +44,7 @@ protected function tearDown(): void unset( $this->archivist, - $this->application + $this->application, ); } @@ -65,10 +65,7 @@ protected function runCommand(Command $command, array $options = []): string return $tester->getDisplay(); } - /** - * @test - */ - public function it_archive_every_token_when_run_without_options_with_confirmation(): void + public function testIt_archive_every_token_when_run_without_options_with_confirmation(): void { $command = $this->command(); @@ -82,10 +79,7 @@ public function it_archive_every_token_when_run_without_options_with_confirmatio self::assertStringContainsString('Successfully archived 10 security token(s).', $output); } - /** - * @test - */ - public function it_archive_partial_tokens_when_run_with_options(): void + public function testIt_archive_partial_tokens_when_run_with_options(): void { $command = $this->command(); diff --git a/tests/DependencyInjection/DependencyInjectionTest.php b/tests/DependencyInjection/DependencyInjectionTest.php index 11118fe..4a3e93a 100644 --- a/tests/DependencyInjection/DependencyInjectionTest.php +++ b/tests/DependencyInjection/DependencyInjectionTest.php @@ -33,7 +33,7 @@ * * phpcs:ignoreFile PSR1.Methods.CamelCapsMethodName.NotCamelCaps */ -class DependencyInjectionTest extends TestCase +final class DependencyInjectionTest extends TestCase { /** * @var ContainerBuilder @@ -60,7 +60,7 @@ protected function setUp(): void $this->container->setDefinition('doctrine.orm.default_entity_manager', new Definition(EntityManager::class)); $this->container->setDefinition( 'doctrine.orm.default_metadata_driver', - new Definition(MappingDriverChain::class) + new Definition(MappingDriverChain::class), ); $this->container->setDefinition('doctrine.orm.default_configuration', new Definition(Configuration::class)); $this->container->setDefinition('request_stack', new Definition(RequestStack::class)); @@ -78,7 +78,7 @@ protected function setUp(): void ]; foreach ($mocks as $id => $class) { $service = $this->createMock($class); - $this->container->setDefinition($id, new Definition(get_class($service))); + $this->container->setDefinition($id, new Definition(\get_class($service))); } $this->container->registerExtension($bundle->getContainerExtension()); @@ -86,13 +86,12 @@ protected function setUp(): void } /** - * @test * @dataProvider configurationProvider */ - public function it_parse_configuration_as_expected(string $resource, array $tokens, array $aliases): void + public function testIt_parse_configuration_as_expected(string $resource, array $tokens, array $aliases): void { // for test purpose, all services are switched to public - $this->container->addCompilerPass(new class() implements CompilerPassInterface { + $this->container->addCompilerPass(new class implements CompilerPassInterface { public function process(ContainerBuilder $container) { $container->findDefinition('yokai_security_token.configuration_registry')->setPublic(true); @@ -121,7 +120,7 @@ public function process(ContainerBuilder $container) foreach ($aliases as $alias => $expectedId) { self::assertTrue( $this->container->has($alias), - "An alias named \"$alias\" exists." + "An alias named \"$alias\" exists.", ); } } @@ -131,7 +130,7 @@ protected function loadConfiguration(string $resource): void $locator = new FileLocator(__DIR__ . '/configuration/'); $path = $locator->locate($resource); - switch (pathinfo($path, PATHINFO_EXTENSION)) { + switch (\pathinfo($path, PATHINFO_EXTENSION)) { case 'yml': $loader = new Loader\YamlFileLoader($this->container, $locator); break; diff --git a/tests/Entity/TokenTest.php b/tests/Entity/TokenTest.php index 751e368..62401fd 100644 --- a/tests/Entity/TokenTest.php +++ b/tests/Entity/TokenTest.php @@ -12,12 +12,9 @@ * * phpcs:ignoreFile PSR1.Methods.CamelCapsMethodName.NotCamelCaps */ -class TokenTest extends TestCase +final class TokenTest extends TestCase { - /** - * @test - */ - public function it_allow_limited_usage_token(): void + public function testIt_allow_limited_usage_token(): void { $token = new Token('string', 'jdoe', 'unique-token', 'reset-password', '+1 day', '+1 month', 2); self::assertFalse($token->isConsumed()); @@ -32,10 +29,7 @@ public function it_allow_limited_usage_token(): void self::assertSame([2], $token->getLastUsage()->getInformation()); } - /** - * @test - */ - public function it_allow_unlimited_usage_token(): void + public function testIt_allow_unlimited_usage_token(): void { $token = new Token('string', 'jdoe', 'unique-token', 'reset-password', '+1 day', '+1 month', 0); self::assertFalse($token->isConsumed()); diff --git a/tests/Factory/TokenFactoryTest.php b/tests/Factory/TokenFactoryTest.php index 4b31da1..8da21cd 100644 --- a/tests/Factory/TokenFactoryTest.php +++ b/tests/Factory/TokenFactoryTest.php @@ -21,7 +21,7 @@ * * phpcs:ignoreFile PSR1.Methods.CamelCapsMethodName.NotCamelCaps */ -class TokenFactoryTest extends TestCase +final class TokenFactoryTest extends TestCase { /** * @var MockObject @@ -50,7 +50,7 @@ protected function tearDown(): void unset( $this->informationGuesser, $this->userManager, - $this->repository + $this->repository, ); } @@ -60,14 +60,11 @@ protected function factory(array $configuration): TokenFactory new TokenConfigurationRegistry($configuration), $this->informationGuesser, $this->userManager, - $this->repository + $this->repository, ); } - /** - * @test - */ - public function it_create_token_according_to_configuration(): void + public function testIt_create_token_according_to_configuration(): void { $generator1 = $this->createMock(TokenGeneratorInterface::class); $generator1->method('generate') @@ -92,7 +89,7 @@ public function it_create_token_according_to_configuration(): void '+1 month', 1, [], - [] + [], ); $configuration = [ diff --git a/tests/Generator/OpenSslTokenGeneratorTest.php b/tests/Generator/OpenSslTokenGeneratorTest.php index 2f1d2d8..efe1a72 100644 --- a/tests/Generator/OpenSslTokenGeneratorTest.php +++ b/tests/Generator/OpenSslTokenGeneratorTest.php @@ -12,12 +12,9 @@ * * phpcs:ignoreFile PSR1.Methods.CamelCapsMethodName.NotCamelCaps */ -class OpenSslTokenGeneratorTest extends TestCase +final class OpenSslTokenGeneratorTest extends TestCase { - /** - * @test - */ - public function it_generate_unique_token(): void + public function testIt_generate_unique_token(): void { $generator = new OpenSslTokenGenerator(); @@ -27,6 +24,6 @@ public function it_generate_unique_token(): void $tokens[] = $generator->generate(); } - self::assertSame(array_unique($tokens), $tokens); + self::assertSame(\array_unique($tokens), $tokens); } } diff --git a/tests/InformationGuesser/InformationGuesserTest.php b/tests/InformationGuesser/InformationGuesserTest.php index c74157c..4010aed 100644 --- a/tests/InformationGuesser/InformationGuesserTest.php +++ b/tests/InformationGuesser/InformationGuesserTest.php @@ -14,17 +14,14 @@ * * phpcs:ignoreFile PSR1.Methods.CamelCapsMethodName.NotCamelCaps */ -class InformationGuesserTest extends TestCase +final class InformationGuesserTest extends TestCase { protected function guesser(RequestStack $requestStack): InformationGuesser { return new InformationGuesser($requestStack); } - /** - * @test - */ - public function it_return_empty_array_if_no_master_request(): void + public function testIt_return_empty_array_if_no_master_request(): void { $requestStack = new RequestStack(); @@ -33,10 +30,7 @@ public function it_return_empty_array_if_no_master_request(): void self::assertSame([], $info); } - /** - * @test - */ - public function it_return_array_with_ip_from_master_request(): void + public function testIt_return_array_with_ip_from_master_request(): void { $requestStack = new RequestStack(); $requestStack->push(new Request([], [], [], [], [], ['REMOTE_ADDR' => '88.88.88.88'])); diff --git a/tests/Kernel.php b/tests/Kernel.php index a83fcb5..f22ade4 100644 --- a/tests/Kernel.php +++ b/tests/Kernel.php @@ -10,7 +10,7 @@ /** * @author Yann Eugoné */ -class Kernel extends BaseKernel +final class Kernel extends BaseKernel { public function registerBundles(): iterable { @@ -33,11 +33,11 @@ public function getProjectDir(): string public function getCacheDir(): string { - return sys_get_temp_dir() . '/' . BaseKernel::VERSION . '/cache/' . $this->environment; + return \sys_get_temp_dir() . '/' . BaseKernel::VERSION . '/cache/' . $this->environment; } public function getLogDir(): string { - return sys_get_temp_dir() . '/' . BaseKernel::VERSION . '/logs'; + return \sys_get_temp_dir() . '/' . BaseKernel::VERSION . '/logs'; } } diff --git a/tests/Manager/ChainUserManagerTest.php b/tests/Manager/ChainUserManagerTest.php index bd8ba2e..3fae055 100644 --- a/tests/Manager/ChainUserManagerTest.php +++ b/tests/Manager/ChainUserManagerTest.php @@ -17,7 +17,7 @@ * * phpcs:ignoreFile PSR1.Methods.CamelCapsMethodName.NotCamelCaps */ -class ChainUserManagerTest extends TestCase +final class ChainUserManagerTest extends TestCase { private function manager($managers): ChainUserManager { @@ -72,10 +72,7 @@ private function documentManager(): UserManagerInterface return $manager; } - /** - * @test - */ - public function it_supports_same_classes_as_managers(): void + public function testIt_supports_same_classes_as_managers(): void { $entityManager = $this->entityManager(); $documentManager = $this->documentManager(); @@ -100,10 +97,7 @@ public function it_supports_same_classes_as_managers(): void self::assertFalse($userEmptyManager->supportsClass($document)); } - /** - * @test - */ - public function it_supports_same_users_as_managers(): void + public function testIt_supports_same_users_as_managers(): void { $entityManager = $this->entityManager(); $documentManager = $this->documentManager(); @@ -128,10 +122,7 @@ public function it_supports_same_users_as_managers(): void self::assertFalse($userEmptyManager->supportsUser($document)); } - /** - * @test - */ - public function it_get_user_class_from_appropriate_manager(): void + public function testIt_get_user_class_from_appropriate_manager(): void { $entity = new UserEntity(); $document = new UserDocument(); @@ -141,10 +132,7 @@ public function it_get_user_class_from_appropriate_manager(): void self::assertSame(UserDocument::class, $userCompleteManager->getClass($document)); } - /** - * @test - */ - public function it_get_user_id_from_appropriate_manager() + public function testIt_get_user_id_from_appropriate_manager() { $entity = new UserEntity(); $document = new UserDocument(); @@ -154,23 +142,17 @@ public function it_get_user_id_from_appropriate_manager() self::assertSame('uuid', $userCompleteManager->getId($document)); } - /** - * @test - */ - public function it_get_user_from_appropriate_manager(): void + public function testIt_get_user_from_appropriate_manager(): void { $userCompleteManager = $this->manager([$this->entityManager(), $this->documentManager()]); self::assertInstanceOf(UserEntity::class, $userCompleteManager->get(UserEntity::class, '9999')); self::assertInstanceOf( UserDocument::class, - $userCompleteManager->get(UserDocument::class, '1111-2222-3333-4444') + $userCompleteManager->get(UserDocument::class, '1111-2222-3333-4444'), ); } - /** - * @test - */ - public function it_throw_exception_on_get_user_class_without_appropriate_manager(): void + public function testIt_throw_exception_on_get_user_class_without_appropriate_manager(): void { $this->expectException(InvalidArgumentException::class); @@ -178,10 +160,7 @@ public function it_throw_exception_on_get_user_class_without_appropriate_manager $userCompleteManager->getClass(new \stdClass()); } - /** - * @test - */ - public function it_throw_exception_on_get_user_id_without_appropriate_manager(): void + public function testIt_throw_exception_on_get_user_id_without_appropriate_manager(): void { $this->expectException(InvalidArgumentException::class); @@ -189,10 +168,7 @@ public function it_throw_exception_on_get_user_id_without_appropriate_manager(): $userCompleteManager->getId(new \stdClass()); } - /** - * @test - */ - public function it_throw_exception_on_get_user_without_appropriate_manager(): void + public function testIt_throw_exception_on_get_user_without_appropriate_manager(): void { $this->expectException(InvalidArgumentException::class); diff --git a/tests/Manager/DoctrineUserManagerTest.php b/tests/Manager/DoctrineUserManagerTest.php index 784fb00..196042f 100644 --- a/tests/Manager/DoctrineUserManagerTest.php +++ b/tests/Manager/DoctrineUserManagerTest.php @@ -17,7 +17,7 @@ * * phpcs:ignoreFile PSR1.Methods.CamelCapsMethodName.NotCamelCaps */ -class DoctrineUserManagerTest extends TestCase +final class DoctrineUserManagerTest extends TestCase { /** * @var MockObject @@ -46,7 +46,7 @@ protected function tearDown(): void unset( $this->registry, $this->objectManager, - $this->classMetadata + $this->classMetadata, ); } @@ -72,87 +72,72 @@ public function getId() }; } - /** - * @test - */ - public function it_supports_doctrine_entities(): void + public function testIt_supports_doctrine_entities(): void { $user = $this->user('jdoe'); $this->registry->method('getManagerForClass') - ->with(get_class($user)) + ->with(\get_class($user)) ->willReturn($this->objectManager); $manager = $this->manager(); - self::assertTrue($manager->supportsClass(get_class($user))); + self::assertTrue($manager->supportsClass(\get_class($user))); self::assertTrue($manager->supportsUser($user)); } - /** - * @test - */ - public function it_do_not_supports_objects_out_of_doctrine(): void + public function testIt_do_not_supports_objects_out_of_doctrine(): void { $user = $this->user('jdoe'); $this->registry->method('getManagerForClass') - ->with(get_class($user)) + ->with(\get_class($user)) ->willReturn(null); $manager = $this->manager(); - self::assertFalse($manager->supportsClass(get_class($user))); + self::assertFalse($manager->supportsClass(\get_class($user))); self::assertFalse($manager->supportsUser($user)); } - /** - * @test - */ - public function it_get_user(): void + public function testIt_get_user(): void { $expected = $this->user('jdoe'); $this->registry->expects(self::once()) ->method('getManagerForClass') - ->with(get_class($expected)) + ->with(\get_class($expected)) ->willReturn($this->objectManager); $this->objectManager->expects(self::once()) ->method('find') - ->with(get_class($expected), 'jdoe') + ->with(\get_class($expected), 'jdoe') ->willReturn($expected); - $user = $this->manager()->get(get_class($expected), 'jdoe'); + $user = $this->manager()->get(\get_class($expected), 'jdoe'); self::assertSame($expected, $user); } - /** - * @test - */ - public function it_get_user_class(): void + public function testIt_get_user_class(): void { $expected = $this->user('jdoe'); $class = $this->manager()->getClass($expected); - self::assertSame(get_class($expected), $class); + self::assertSame(\get_class($expected), $class); } - /** - * @test - */ - public function it_get_user_id(): void + public function testIt_get_user_id(): void { $expected = $this->user('jdoe'); $this->registry->expects(self::once()) ->method('getManagerForClass') - ->with(get_class($expected)) + ->with(\get_class($expected)) ->willReturn($this->objectManager); $this->objectManager->expects(self::once()) ->method('getClassMetadata') - ->with(get_class($expected)) + ->with(\get_class($expected)) ->willReturn($this->classMetadata); $this->classMetadata->expects(self::once()) diff --git a/tests/Manager/Mock/UserDocument.php b/tests/Manager/Mock/UserDocument.php index a439830..0ea5875 100644 --- a/tests/Manager/Mock/UserDocument.php +++ b/tests/Manager/Mock/UserDocument.php @@ -7,6 +7,6 @@ /** * @author Yann Eugoné */ -class UserDocument +final class UserDocument { } diff --git a/tests/Manager/Mock/UserEntity.php b/tests/Manager/Mock/UserEntity.php index afcd706..083d4e3 100644 --- a/tests/Manager/Mock/UserEntity.php +++ b/tests/Manager/Mock/UserEntity.php @@ -7,6 +7,6 @@ /** * @author Yann Eugoné */ -class UserEntity +final class UserEntity { } diff --git a/tests/Manager/TokenManagerTest.php b/tests/Manager/TokenManagerTest.php index c40702b..ee12fa5 100644 --- a/tests/Manager/TokenManagerTest.php +++ b/tests/Manager/TokenManagerTest.php @@ -32,7 +32,7 @@ * * phpcs:ignoreFile PSR1.Methods.CamelCapsMethodName.NotCamelCaps */ -class TokenManagerTest extends TestCase +final class TokenManagerTest extends TestCase { /** * @var MockObjectrepository, $this->informationGuesser, $this->userManager, - $this->eventDispatcher + $this->eventDispatcher, ); } @@ -86,14 +86,11 @@ protected function manager(): TokenManager $this->repository, $this->informationGuesser, $this->userManager, - new EventDispatcher($this->eventDispatcher) + new EventDispatcher($this->eventDispatcher), ); } - /** - * @test - */ - public function it_dispatch_not_found_exceptions_on_get_token_from_repository(): void + public function testIt_dispatch_not_found_exceptions_on_get_token_from_repository(): void { $this->expectException(TokenNotFoundException::class); @@ -114,10 +111,7 @@ public function it_dispatch_not_found_exceptions_on_get_token_from_repository(): $this->manager()->get('forgot_password', 'unique-token'); } - /** - * @test - */ - public function it_dispatch_expired_exceptions_on_get_token_from_repository(): void + public function testIt_dispatch_expired_exceptions_on_get_token_from_repository(): void { $this->expectException(TokenExpiredException::class); @@ -138,10 +132,7 @@ public function it_dispatch_expired_exceptions_on_get_token_from_repository(): v $this->manager()->get('forgot_password', 'unique-token'); } - /** - * @test - */ - public function it_dispatch_used_exceptions_on_get_token_from_repository(): void + public function testIt_dispatch_used_exceptions_on_get_token_from_repository(): void { $this->expectException(TokenConsumedException::class); @@ -162,10 +153,7 @@ public function it_dispatch_used_exceptions_on_get_token_from_repository(): void $this->manager()->get('forgot_password', 'unique-token'); } - /** - * @test - */ - public function it_get_token_from_repository(): void + public function testIt_get_token_from_repository(): void { $this->repository->expects(self::once()) ->method('get') @@ -185,10 +173,7 @@ public function it_get_token_from_repository(): void self::assertSame($expected, $token); } - /** - * @test - */ - public function it_create_unique_token(): void + public function testIt_create_unique_token(): void { $expectedToken = new Token( 'string', @@ -199,7 +184,7 @@ public function it_create_unique_token(): void '+1 month', 1, ['payload', 'information'], - ['created', 'information'] + ['created', 'information'], ); $this->factory->expects(self::once()) @@ -230,10 +215,7 @@ public function it_create_unique_token(): void self::assertSame($expectedToken, $token); } - /** - * @test - */ - public function it_consume_token(): void + public function testIt_consume_token(): void { $token = new Token('string', 'jdoe', 'unique-token', 'reset-password', '+1 day', '+1 month'); @@ -270,10 +252,7 @@ public function it_consume_token(): void self::assertInstanceOf(\DateTime::class, $usage->getCreatedAt()); } - /** - * @test - */ - public function it_extract_user_from_token(): void + public function testIt_extract_user_from_token(): void { $token = new Token('string', 'jdoe', 'unique-token', 'reset-password', '+1 day', '+1 month', 1, []); diff --git a/tests/Repository/DoctrineORMTokenRepositoryTest.php b/tests/Repository/DoctrineORMTokenRepositoryTest.php index cba4510..66cb302 100644 --- a/tests/Repository/DoctrineORMTokenRepositoryTest.php +++ b/tests/Repository/DoctrineORMTokenRepositoryTest.php @@ -19,7 +19,7 @@ * * phpcs:ignoreFile PSR1.Methods.CamelCapsMethodName.NotCamelCaps */ -class DoctrineORMTokenRepositoryTest extends TestCase +final class DoctrineORMTokenRepositoryTest extends TestCase { /** * @var MockObject @@ -41,7 +41,7 @@ protected function tearDown(): void { unset( $this->manager, - $this->repository + $this->repository, ); } @@ -50,10 +50,7 @@ protected function repository(): DoctrineORMTokenRepository return new DoctrineORMTokenRepository($this->manager, $this->repository); } - /** - * @test - */ - public function it_throw_exception_if_token_not_found(): void + public function testIt_throw_exception_if_token_not_found(): void { $this->expectException(TokenNotFoundException::class); @@ -65,10 +62,7 @@ public function it_throw_exception_if_token_not_found(): void $this->repository()->get('unique', 'init_password'); } - /** - * @test - */ - public function it_throw_exception_if_token_expired(): void + public function testIt_throw_exception_if_token_expired(): void { $this->expectException(TokenExpiredException::class); @@ -82,10 +76,7 @@ public function it_throw_exception_if_token_expired(): void $this->repository()->get('unique', 'init_password'); } - /** - * @test - */ - public function it_throw_exception_if_token_used_single_time(): void + public function testIt_throw_exception_if_token_used_single_time(): void { $this->expectException(TokenConsumedException::class); @@ -100,10 +91,7 @@ public function it_throw_exception_if_token_used_single_time(): void $this->repository()->get('unique', 'init_password'); } - /** - * @test - */ - public function it_throw_exception_if_token_used_multiple_times(): void + public function testIt_throw_exception_if_token_used_multiple_times(): void { $this->expectException(TokenConsumedException::class); @@ -119,10 +107,7 @@ public function it_throw_exception_if_token_used_multiple_times(): void $this->repository()->get('unique', 'init_password'); } - /** - * @test - */ - public function it_get_valid_token(): void + public function testIt_get_valid_token(): void { $token = new Token('string', 'jdoe', 'unique', 'init_password', '+1 day', '+1 month', 1, []); @@ -136,10 +121,7 @@ public function it_get_valid_token(): void self::assertSame($token, $got); } - /** - * @test - */ - public function it_create_token(): void + public function testIt_create_token(): void { $token = new Token('string', 'jdoe', 'unique', 'init_password', '+1 day', '+1 month', 1, []); @@ -158,10 +140,7 @@ public function it_create_token(): void $this->repository()->create($token); } - /** - * @test - */ - public function it_update_token(): void + public function testIt_update_token(): void { $token = new Token('string', 'jdoe', 'unique', 'init_password', '+1 day', '+1 month', 1, []);