Skip to content

Commit

Permalink
Add missing type docs and typehints (markitosgv#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbabker authored Jul 16, 2021
1 parent 54b8e65 commit c752135
Show file tree
Hide file tree
Showing 35 changed files with 151 additions and 263 deletions.
19 changes: 5 additions & 14 deletions Command/ClearInvalidRefreshTokensCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class ClearInvalidRefreshTokensCommand.
*/
class ClearInvalidRefreshTokensCommand extends Command
{
protected static $defaultName = 'gesdinet:jwt:clear';

private $refreshTokenManager;
private RefreshTokenManagerInterface $refreshTokenManager;

public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
{
Expand All @@ -33,20 +30,14 @@ public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
$this->refreshTokenManager = $refreshTokenManager;
}

/**
* @see Command
*/
protected function configure()
protected function configure(): void
{
$this
->setDescription('Clear invalid refresh tokens.')
->addArgument('datetime', InputArgument::OPTIONAL);
->addArgument('datetime', InputArgument::OPTIONAL, 'An optional date, all tokens before this date will be removed; the value should be able to be parsed by DateTime.');
}

/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$datetime = $input->getArgument('datetime');

Expand All @@ -59,7 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$revokedTokens = $this->refreshTokenManager->revokeAllInvalid($datetime);

foreach ($revokedTokens as $revokedToken) {
$output->writeln(sprintf('Revoke <comment>%s</comment>', $revokedToken->getRefreshToken()));
$output->writeln(sprintf('Revoked <comment>%s</comment>', $revokedToken->getRefreshToken()));
}

return 0;
Expand Down
21 changes: 6 additions & 15 deletions Command/RevokeRefreshTokenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class ClearInvalidRefreshTokensCommand.
*/
class RevokeRefreshTokenCommand extends Command
{
protected static $defaultName = 'gesdinet:jwt:revoke';

private $refreshTokenManager;
private RefreshTokenManagerInterface $refreshTokenManager;

public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
{
Expand All @@ -33,34 +30,28 @@ public function __construct(RefreshTokenManagerInterface $refreshTokenManager)
$this->refreshTokenManager = $refreshTokenManager;
}

/**
* @see Command
*/
protected function configure()
protected function configure(): void
{
$this
->setDescription('Revoke a refresh token')
->addArgument('refresh_token', InputArgument::REQUIRED, 'The refresh token to revoke');
}

/**
* @see Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function execute(InputInterface $input, OutputInterface $output): int
{
$refreshTokenParam = $input->getArgument('refresh_token');

$refreshToken = $this->refreshTokenManager->get($refreshTokenParam);

if (null === $refreshToken) {
$output->writeln(sprintf('<error>Not Found:</error> Refresh Token <comment>%s</comment> doesn\'t exists', $refreshTokenParam));
$output->writeln(sprintf('<error>Not Found:</error> Refresh Token <comment>%s</comment> doesn\'t exist', $refreshTokenParam));

return -1;
return 1;
}

$this->refreshTokenManager->delete($refreshToken);

$output->writeln(sprintf('Revoke <comment>%s</comment>', $refreshToken->getRefreshToken()));
$output->writeln(sprintf('Revoked <comment>%s</comment>', $refreshToken->getRefreshToken()));

return 0;
}
Expand Down
10 changes: 1 addition & 9 deletions DependencyInjection/Compiler/CustomUserProviderCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,11 @@
use Symfony\Component\DependencyInjection\Reference;

/**
* CustomUserProviderCompilerPass.
*
* @deprecated no replacement
*/
final class CustomUserProviderCompilerPass implements CompilerPassInterface
{
/**
* @var bool
*/
private $internalUse;
private bool $internalUse;

/**
* @param bool $internalUse Flag indicating the pass was created by an internal bundle call (used to suppress runtime deprecations)
Expand All @@ -27,9 +22,6 @@ public function __construct(bool $internalUse = false)
$this->internalUse = $internalUse;
}

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (false === $this->internalUse) {
Expand Down
6 changes: 0 additions & 6 deletions DependencyInjection/Compiler/ObjectManagerCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* ObjectManagerCompilerPass.
*/
final class ObjectManagerCompilerPass implements CompilerPassInterface
{
/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$objectManagerId = $container->getParameter('gesdinet.jwtrefreshtoken.object_manager.id');
Expand Down
10 changes: 1 addition & 9 deletions DependencyInjection/Compiler/UserCheckerCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* UserCheckerCompilerPass.
*
* @deprecated no replacement
*/
final class UserCheckerCompilerPass implements CompilerPassInterface
{
/**
* @var bool
*/
private $internalUse;
private bool $internalUse;

/**
* @param bool $internalUse Flag indicating the pass was created by an internal bundle call (used to suppress runtime deprecations)
Expand All @@ -25,9 +20,6 @@ public function __construct(bool $internalUse = false)
$this->internalUse = $internalUse;
}

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
if (false === $this->internalUse) {
Expand Down
10 changes: 1 addition & 9 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,9 @@
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
public function getConfigTreeBuilder(): TreeBuilder
{
$treeBuilder = new TreeBuilder('gesdinet_jwt_refresh_token');
$rootNode = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('gesdinet_jwt_refresh_token');
Expand Down
35 changes: 12 additions & 23 deletions DependencyInjection/GesdinetJWTRefreshTokenExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,16 @@

namespace Gesdinet\JWTRefreshTokenBundle\DependencyInjection;

use Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass;
use Gesdinet\JWTRefreshTokenBundle\Document\RefreshToken as RefreshTokenDocument;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken as RefreshTokenEntity;
use Gesdinet\JWTRefreshTokenBundle\Request\Extractor\ExtractorInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

/**
* This is the class that loads and manages your bundle configuration.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class GesdinetJWTRefreshTokenExtension extends Extension
{
private const DEPRECATED_SERVICES = [
Expand All @@ -31,10 +29,7 @@ class GesdinetJWTRefreshTokenExtension extends Extension
'gesdinet.jwtrefreshtoken.user_provider' => '1.0',
];

/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);

Expand All @@ -52,13 +47,11 @@ public function load(array $configs, ContainerBuilder $container)
$container->setParameter('gesdinet_jwt_refresh_token.token_parameter_name', $config['token_parameter_name']);
$container->setParameter('gesdinet_jwt_refresh_token.doctrine_mappings', $config['doctrine_mappings']);

$refreshTokenClass = 'Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken';
$refreshTokenClass = RefreshTokenEntity::class;
$objectManager = 'doctrine.orm.entity_manager';

if (!class_exists('Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass')
|| 'mongodb' === strtolower($config['manager_type'])
) {
$refreshTokenClass = 'Gesdinet\JWTRefreshTokenBundle\Document\RefreshToken';
if (!class_exists(DoctrineOrmMappingsPass::class) || 'mongodb' === strtolower($config['manager_type'])) {
$refreshTokenClass = RefreshTokenDocument::class;
$objectManager = 'doctrine_mongodb.odm.document_manager';
}

Expand Down Expand Up @@ -104,13 +97,11 @@ private function deprecateServices(ContainerBuilder $container): void
}

/**
* Get refresh token class from configuration.
*
* Supports deprecated configuration
* Get the refresh token class from configuration.
*
* @return string|null
* Falls back to deprecated configuration nodes if necessary.
*/
protected function getRefreshTokenClass(array $config)
protected function getRefreshTokenClass(array $config): ?string
{
if (isset($config['refresh_token_class'])) {
return $config['refresh_token_class'];
Expand All @@ -122,11 +113,9 @@ protected function getRefreshTokenClass(array $config)
/**
* Get object manager from configuration.
*
* Supports deprecated configuration
*
* @return string|null
* Falls back to deprecated configuration nodes if necessary.
*/
protected function getObjectManager(array $config)
protected function getObjectManager(array $config): ?string
{
if (isset($config['object_manager'])) {
return $config['object_manager'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ public function addConfiguration(NodeDefinition $node): void
;
}

/**
* @return string
*/
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId)
{
$authenticatorId = 'security.authenticator.refresh_jwt.'.$firewallName;
Expand All @@ -83,7 +86,7 @@ public function createAuthenticator(ContainerBuilder $container, string $firewal
return $authenticatorId;
}

private function createAuthenticationSuccessHandler(ContainerBuilder $container, string $id, array $config)
private function createAuthenticationSuccessHandler(ContainerBuilder $container, string $id, array $config): string
{
$successHandlerId = $this->getSuccessHandlerId($id);

Expand All @@ -100,27 +103,27 @@ private function createAuthenticationSuccessHandler(ContainerBuilder $container,
return $successHandlerId;
}

private function createAuthenticationFailureHandler(ContainerBuilder $container, string $id, array $config)
private function createAuthenticationFailureHandler(ContainerBuilder $container, string $id, array $config): string
{
$id = $this->getFailureHandlerId($id);
$failureHandlerId = $this->getFailureHandlerId($id);

if (isset($config['failure_handler'])) {
$container->setDefinition($id, new ChildDefinition('security.authentication.custom_failure_handler'))
$container->setDefinition($failureHandlerId, new ChildDefinition('security.authentication.custom_failure_handler'))
->replaceArgument(0, new Reference($config['failure_handler']))
->replaceArgument(1, []);
} else {
$container->setDefinition($id, new ChildDefinition('gesdinet.jwtrefreshtoken.security.authentication.failure_handler'));
$container->setDefinition($failureHandlerId, new ChildDefinition('gesdinet.jwtrefreshtoken.security.authentication.failure_handler'));
}

return $id;
return $failureHandlerId;
}

private function getSuccessHandlerId(string $id)
private function getSuccessHandlerId(string $id): string
{
return 'security.authentication.success_handler.'.$id.'.'.str_replace('-', '_', $this->getKey());
}

private function getFailureHandlerId(string $id)
private function getFailureHandlerId(string $id): string
{
return 'security.authentication.failure_handler.'.$id.'.'.str_replace('-', '_', $this->getKey());
}
Expand Down
9 changes: 3 additions & 6 deletions Doctrine/RefreshTokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Gesdinet\JWTRefreshTokenBundle\Doctrine;

use DateTime;
use Doctrine\Persistence\ObjectManager;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshTokenRepository;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
Expand All @@ -35,9 +34,7 @@ class RefreshTokenManager extends BaseRefreshTokenManager
protected $repository;

/**
* Constructor.
*
* @param string $class
* @param class-string<RefreshTokenInterface> $class
*/
public function __construct(ObjectManager $om, $class)
{
Expand Down Expand Up @@ -92,8 +89,8 @@ public function delete(RefreshTokenInterface $refreshToken, $andFlush = true)
}

/**
* @param DateTime $datetime
* @param bool $andFlush
* @param \DateTimeInterface|null $datetime
* @param bool $andFlush
*
* @return RefreshTokenInterface[]
*/
Expand Down
4 changes: 2 additions & 2 deletions Document/AbstractRefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

use Gesdinet\JWTRefreshTokenBundle\Model\AbstractRefreshToken as BaseAbstractRefreshToken;

trigger_deprecation('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%s" class is deprecated, use "%s" instead.', AbstractRefreshToken::class, BaseAbstractRefreshToken::class);

/**
* Abstract Refresh Token.
*
* @deprecated Extend from `Gesdinet\JWTRefreshTokenBundle\Model\AbstractRefreshToken` instead
*/
abstract class AbstractRefreshToken extends BaseAbstractRefreshToken
Expand Down
3 changes: 0 additions & 3 deletions Document/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

use Gesdinet\JWTRefreshTokenBundle\Model\AbstractRefreshToken;

/**
* Refresh Token.
*/
class RefreshToken extends AbstractRefreshToken
{
}
4 changes: 2 additions & 2 deletions Entity/AbstractRefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@

use Gesdinet\JWTRefreshTokenBundle\Model\AbstractRefreshToken as BaseAbstractRefreshToken;

trigger_deprecation('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%s" class is deprecated, use "%s" instead.', AbstractRefreshToken::class, BaseAbstractRefreshToken::class);

/**
* Abstract Refresh Token.
*
* @deprecated Extend from `Gesdinet\JWTRefreshTokenBundle\Model\AbstractRefreshToken` instead
*/
abstract class AbstractRefreshToken extends BaseAbstractRefreshToken
Expand Down
Loading

0 comments on commit c752135

Please sign in to comment.