Skip to content
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

feat: import namespaces classes via rector #380

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions Command/ClearInvalidRefreshTokensCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Gesdinet\JWTRefreshTokenBundle\Command;

use DateTime;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManagerInterface;
use Symfony\Component\Console\Attribute\AsCommand;
Expand Down Expand Up @@ -52,9 +53,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$datetime = $input->getArgument('datetime');

if (null === $datetime) {
$datetime = new \DateTime();
$datetime = new DateTime();
} else {
$datetime = new \DateTime($datetime);
$datetime = new DateTime($datetime);
}

$revokedTokens = $this->refreshTokenManager->revokeAllInvalid($datetime);
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/GesdinetJWTRefreshTokenExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Gesdinet\JWTRefreshTokenBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ORM\EntityManager;
use Gesdinet\JWTRefreshTokenBundle\Document\RefreshToken as RefreshTokenDocument;
Expand All @@ -19,15 +20,14 @@
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader;

class GesdinetJWTRefreshTokenExtension extends Extension
{
public function load(array $configs, ContainerBuilder $container): void
{
$config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs);

$loader = new Loader\PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.php');

$container->registerForAutoconfiguration(ExtractorInterface::class)->addTag('gesdinet_jwt_refresh_token.request_extractor');
Expand Down
10 changes: 6 additions & 4 deletions Doctrine/RefreshTokenManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Gesdinet\JWTRefreshTokenBundle\Doctrine;

use LogicException;
use DateTimeInterface;
use Doctrine\Persistence\ObjectManager;
use Gesdinet\JWTRefreshTokenBundle\Generator\RefreshTokenGeneratorInterface;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
Expand All @@ -36,7 +38,7 @@ class RefreshTokenManager implements RefreshTokenManagerInterface
/**
* @param class-string<RefreshTokenInterface> $class
*
* @throws \LogicException if the object repository does not implement `Gesdinet\JWTRefreshTokenBundle\Doctrine\RefreshTokenRepositoryInterface`
* @throws LogicException if the object repository does not implement `Gesdinet\JWTRefreshTokenBundle\Doctrine\RefreshTokenRepositoryInterface`
*/
public function __construct(ObjectManager $om, $class)
{
Expand All @@ -45,7 +47,7 @@ public function __construct(ObjectManager $om, $class)
$repository = $om->getRepository($class);

if (!$repository instanceof RefreshTokenRepositoryInterface) {
throw new \LogicException(sprintf('Repository mapped for "%s" should implement %s.', $class, RefreshTokenRepositoryInterface::class));
throw new LogicException(sprintf('Repository mapped for "%s" should implement %s.', $class, RefreshTokenRepositoryInterface::class));
}

$this->repository = $repository;
Expand Down Expand Up @@ -119,8 +121,8 @@ public function delete(RefreshTokenInterface $refreshToken, $andFlush = true)
}

/**
* @param \DateTimeInterface|null $datetime
* @param bool $andFlush
* @param DateTimeInterface|null $datetime
* @param bool $andFlush
*
* @return RefreshTokenInterface[]
*/
Expand Down
3 changes: 2 additions & 1 deletion Doctrine/RefreshTokenRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Gesdinet\JWTRefreshTokenBundle\Doctrine;

use DateTimeInterface;
use Doctrine\Persistence\ObjectRepository;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;

Expand All @@ -13,7 +14,7 @@
interface RefreshTokenRepositoryInterface extends ObjectRepository
{
/**
* @param \DateTimeInterface|null $datetime
* @param DateTimeInterface|null $datetime
*
* @return T[]
*/
Expand Down
6 changes: 4 additions & 2 deletions Document/RefreshTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Gesdinet\JWTRefreshTokenBundle\Document;

use DateTimeInterface;
use DateTime;
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
use Gesdinet\JWTRefreshTokenBundle\Doctrine\RefreshTokenRepositoryInterface;

Expand All @@ -13,13 +15,13 @@
class RefreshTokenRepository extends DocumentRepository implements RefreshTokenRepositoryInterface
{
/**
* @param \DateTimeInterface|null $datetime
* @param DateTimeInterface|null $datetime
*
* @return RefreshToken[]
*/
public function findInvalid($datetime = null)
{
$datetime = (null === $datetime) ? new \DateTime() : $datetime;
$datetime = (null === $datetime) ? new DateTime() : $datetime;

$queryBuilder = $this->createQueryBuilder()
->field('valid')->lt($datetime);
Expand Down
6 changes: 4 additions & 2 deletions Entity/RefreshTokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Gesdinet\JWTRefreshTokenBundle\Entity;

use DateTimeInterface;
use DateTime;
use Doctrine\ORM\EntityRepository;
use Gesdinet\JWTRefreshTokenBundle\Doctrine\RefreshTokenRepositoryInterface;

Expand All @@ -13,13 +15,13 @@
class RefreshTokenRepository extends EntityRepository implements RefreshTokenRepositoryInterface
{
/**
* @param \DateTimeInterface|null $datetime
* @param DateTimeInterface|null $datetime
*
* @return RefreshToken[]
*/
public function findInvalid($datetime = null)
{
$datetime = (null === $datetime) ? new \DateTime() : $datetime;
$datetime = (null === $datetime) ? new DateTime() : $datetime;

return $this->createQueryBuilder('u')
->where('u.valid < :datetime')
Expand Down
3 changes: 2 additions & 1 deletion EventListener/AttachRefreshTokenOnSuccessListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Gesdinet\JWTRefreshTokenBundle\EventListener;

use LogicException;
use Gesdinet\JWTRefreshTokenBundle\Generator\RefreshTokenGeneratorInterface;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManagerInterface;
Expand Down Expand Up @@ -102,7 +103,7 @@ public function __construct(
$this->returnExpirationParameterName = $returnExpirationParameterName;

if ($this->cookieSettings['partitioned'] && Kernel::VERSION < '6.4') {
throw new \LogicException(sprintf('The `partitioned` option for cookies is only available for Symfony 6.4 and above. You are currently on version %s', Kernel::VERSION));
throw new LogicException(sprintf('The `partitioned` option for cookies is only available for Symfony 6.4 and above. You are currently on version %s', Kernel::VERSION));
}
}

Expand Down
3 changes: 2 additions & 1 deletion Http/RefreshAuthenticationFailureResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@

namespace Gesdinet\JWTRefreshTokenBundle\Http;

use ReflectionMethod;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

if (80000 <= \PHP_VERSION_ID && (new \ReflectionMethod(JsonResponse::class, 'setData'))->hasReturnType()) {
if (80000 <= \PHP_VERSION_ID && (new ReflectionMethod(JsonResponse::class, 'setData'))->hasReturnType()) {
eval('
namespace Gesdinet\JWTRefreshTokenBundle\Http;

Expand Down
8 changes: 5 additions & 3 deletions Model/AbstractRefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Gesdinet\JWTRefreshTokenBundle\Model;

use DateTimeInterface;
use DateTime;
use Symfony\Component\Security\Core\User\UserInterface;

abstract class AbstractRefreshToken implements RefreshTokenInterface
Expand All @@ -31,7 +33,7 @@ abstract class AbstractRefreshToken implements RefreshTokenInterface
protected $username;

/**
* @var \DateTimeInterface|null
* @var DateTimeInterface|null
*/
protected $valid;

Expand All @@ -40,7 +42,7 @@ abstract class AbstractRefreshToken implements RefreshTokenInterface
*/
public static function createForUserWithTtl(string $refreshToken, UserInterface $user, int $ttl): RefreshTokenInterface
{
$valid = new \DateTime();
$valid = new DateTime();

// Explicitly check for a negative number based on a behavior change in PHP 8.2, see https://github.com/php/php-src/issues/9950
if ($ttl > 0) {
Expand Down Expand Up @@ -138,6 +140,6 @@ public function getUsername()
*/
public function isValid()
{
return null !== $this->valid && $this->valid >= new \DateTime();
return null !== $this->valid && $this->valid >= new DateTime();
}
}
8 changes: 5 additions & 3 deletions Model/RefreshTokenInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

namespace Gesdinet\JWTRefreshTokenBundle\Model;

use Stringable;
use DateTimeInterface;
use Symfony\Component\Security\Core\User\UserInterface;

interface RefreshTokenInterface extends \Stringable
interface RefreshTokenInterface extends Stringable
{
/**
* Creates a new model instance based on the provided details.
Expand All @@ -38,14 +40,14 @@ public function setRefreshToken($refreshToken = null);
public function getRefreshToken();

/**
* @param \DateTimeInterface|null $valid
* @param DateTimeInterface|null $valid
*
* @return $this
*/
public function setValid($valid);

/**
* @return \DateTimeInterface|null
* @return DateTimeInterface|null
*/
public function getValid();

Expand Down
4 changes: 3 additions & 1 deletion Model/RefreshTokenManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Gesdinet\JWTRefreshTokenBundle\Model;

use DateTimeInterface;

/**
* Interface to be implemented by user managers. This adds an additional level
* of abstraction between your application, and the actual repository.
Expand Down Expand Up @@ -53,7 +55,7 @@ public function save(RefreshTokenInterface $refreshToken);
public function delete(RefreshTokenInterface $refreshToken);

/**
* @param \DateTimeInterface|null $datetime
* @param DateTimeInterface|null $datetime
*
* @return RefreshTokenInterface[]
*/
Expand Down
3 changes: 2 additions & 1 deletion Security/Authenticator/RefreshTokenAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Gesdinet\JWTRefreshTokenBundle\Security\Authenticator;

use InvalidArgumentException;
use Gesdinet\JWTRefreshTokenBundle\Request\Extractor\ExtractorInterface;
use Gesdinet\JWTRefreshTokenBundle\Exception\UnknownRefreshTokenException;
use Gesdinet\JWTRefreshTokenBundle\Exception\UnknownUserFromRefreshTokenException;
Expand Down Expand Up @@ -83,7 +84,7 @@ public function getCredentials(Request $request)
public function getUser($credentials, UserProviderInterface $userProvider)
{
if (!$userProvider instanceof RefreshTokenProvider) {
throw new \InvalidArgumentException(sprintf('The user provider must be an instance of RefreshTokenProvider (%s was given).', get_class($userProvider)));
throw new InvalidArgumentException(sprintf('The user provider must be an instance of RefreshTokenProvider (%s was given).', get_class($userProvider)));
}

$refreshToken = $credentials['token'] ?? null;
Expand Down
3 changes: 2 additions & 1 deletion Security/Http/Authenticator/RefreshTokenAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Gesdinet\JWTRefreshTokenBundle\Security\Http\Authenticator;

use DateTime;
use Gesdinet\JWTRefreshTokenBundle\Event\RefreshTokenNotFoundEvent;
use Gesdinet\JWTRefreshTokenBundle\Http\RefreshAuthenticationFailureResponse;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
Expand Down Expand Up @@ -115,7 +116,7 @@ public function authenticate(Request $request): Passport
}

if ($this->options['ttl_update']) {
$expirationDate = new \DateTime();
$expirationDate = new DateTime();

// Explicitly check for a negative number based on a behavior change in PHP 8.2, see https://github.com/php/php-src/issues/9950
if ($this->options['ttl'] > 0) {
Expand Down
3 changes: 2 additions & 1 deletion Security/Provider/RefreshTokenProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Gesdinet\JWTRefreshTokenBundle\Security\Provider;

use ReflectionClass;
use Symfony\Component\Security\Core\User\InMemoryUser;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Core\User\User;
Expand All @@ -21,7 +22,7 @@

trigger_deprecation('gesdinet/jwt-refresh-token-bundle', '1.0', 'The "%s" class is deprecated, configure the user provider for the `refresh_jwt` authenticator instead.', RefreshTokenProvider::class);

if ((new \ReflectionClass(UserProviderInterface::class))->getMethod('supportsClass')->hasReturnType()) {
if ((new ReflectionClass(UserProviderInterface::class))->getMethod('supportsClass')->hasReturnType()) {
/**
* Compatibility layer for Symfony 7.0 and later, where {@see UserProviderInterface::supportsClass()} has a return type.
*
Expand Down
3 changes: 2 additions & 1 deletion Service/RefreshToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Gesdinet\JWTRefreshTokenBundle\Service;

use DateTime;
use Gesdinet\JWTRefreshTokenBundle\Event\RefreshEvent;
use Gesdinet\JWTRefreshTokenBundle\Security\Authenticator\RefreshTokenAuthenticator;
use Gesdinet\JWTRefreshTokenBundle\Exception\InvalidRefreshTokenException;
Expand Down Expand Up @@ -106,7 +107,7 @@ public function refresh(Request $request)
}

if ($this->ttlUpdate) {
$expirationDate = new \DateTime();
$expirationDate = new DateTime();
$expirationDate->modify(sprintf('+%d seconds', $this->ttl));
$refreshToken->setValid($expirationDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Gesdinet\JWTRefreshTokenBundle\Tests\Functional\Command;

use DateTimeInterface;
use Gesdinet\JWTRefreshTokenBundle\Command\ClearInvalidRefreshTokensCommand;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenInterface;
use Gesdinet\JWTRefreshTokenBundle\Model\RefreshTokenManagerInterface;
Expand All @@ -23,7 +24,7 @@ public function test_clears_tokens_without_timestamp(): void
$refreshTokenManager = $this->createMock(RefreshTokenManagerInterface::class);
$refreshTokenManager->expects($this->once())
->method('revokeAllInvalid')
->with($this->isInstanceOf(\DateTimeInterface::class))
->with($this->isInstanceOf(DateTimeInterface::class))
->willReturn([$refreshToken]);

$command = new ClearInvalidRefreshTokensCommand($refreshTokenManager);
Expand Down Expand Up @@ -51,7 +52,7 @@ public function test_clears_tokens_with_timestamp(): void
$refreshTokenManager = $this->createMock(RefreshTokenManagerInterface::class);
$refreshTokenManager->expects($this->once())
->method('revokeAllInvalid')
->with($this->isInstanceOf(\DateTimeInterface::class))
->with($this->isInstanceOf(DateTimeInterface::class))
->willReturn([$refreshToken]);

$command = new ClearInvalidRefreshTokensCommand($refreshTokenManager);
Expand Down
3 changes: 2 additions & 1 deletion Tests/Functional/Document/RefreshTokenRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Gesdinet\JWTRefreshTokenBundle\Tests\Functional\Document;

use DateTime;
use Gesdinet\JWTRefreshTokenBundle\Doctrine\RefreshTokenManager;
use Gesdinet\JWTRefreshTokenBundle\Document\RefreshTokenRepository;
use Gesdinet\JWTRefreshTokenBundle\Generator\RefreshTokenGenerator;
Expand Down Expand Up @@ -93,7 +94,7 @@ public function test_retrieves_all_tokens_older_than_the_specified_time(): void
/** @var RefreshTokenRepository $repo */
$repo = $this->documentManager->getRepository(RefreshToken::class);

$time = new \DateTime();
$time = new DateTime();
$time->modify('+1200 seconds');

$this->assertCount(5, $repo->findInvalid($time));
Expand Down
3 changes: 2 additions & 1 deletion Tests/Functional/Entity/RefreshTokenRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Gesdinet\JWTRefreshTokenBundle\Tests\Functional\Entity;

use DateTime;
use Doctrine\ORM\Tools\SchemaTool;
use Gesdinet\JWTRefreshTokenBundle\Doctrine\RefreshTokenManager;
use Gesdinet\JWTRefreshTokenBundle\Entity\RefreshTokenRepository;
Expand Down Expand Up @@ -89,7 +90,7 @@ public function test_retrieves_all_tokens_older_than_the_specified_time(): void
/** @var RefreshTokenRepository $repo */
$repo = $this->entityManager->getRepository(RefreshToken::class);

$time = new \DateTime();
$time = new DateTime();
$time->modify('+1200 seconds');

$this->assertCount(5, $repo->findInvalid($time));
Expand Down
Loading