diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml
new file mode 100644
index 00000000..ebdde0f7
--- /dev/null
+++ b/.github/workflows/coding-standards.yml
@@ -0,0 +1,39 @@
+name: Coding Standards
+
+on: [push]
+
+jobs:
+ tests:
+ runs-on: ${{ matrix.operating-system }}
+ strategy:
+ matrix:
+ operating-system: [ubuntu-latest]
+ php-versions: ['8.1']
+ name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
+
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v2
+ with:
+ ref: ${{ github.head_ref }}
+
+ - name: Setup PHP, with composer and extensions
+ uses: shivammathur/setup-php@v2
+ with:
+ php-version: ${{ matrix.php-versions }}
+ extensions: json, mbstring, openssl, sqlite3
+ coverage: xdebug
+
+ - name: Install Composer dependencies
+ run: |
+ composer install
+ composer require rector/rector symplify/easy-coding-standard --dev
+
+ - name: CONDING STANDARDS (ECS)
+ run: |
+ vendor/bin/ecs check
+
+ - name: CONDING STANDARDS (RECTOR)
+ run: |
+ vendor/bin/rector process --ansi --dry-run --xdebug
+
diff --git a/.php_cs b/.php_cs
deleted file mode 100755
index e697c1e2..00000000
--- a/.php_cs
+++ /dev/null
@@ -1,14 +0,0 @@
-in([__DIR__]);
-
-return PhpCsFixer\Config::create()
- ->setRules([
- '@Symfony' => true,
- 'ordered_imports' => true,
- 'array_syntax' => ['syntax' => 'short'],
- 'phpdoc_scalar' => false,
- ])
- ->setUsingCache(false)
- ->setFinder($finder);
-;
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 35583eea..a6a5bbaf 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -9,13 +9,19 @@ maintainers accept and merge your work.
Coding standards
----------------
-You MUST follow the [PSR-1](http://www.php-fig.org/psr/1/) and
-[PSR-2](http://www.php-fig.org/psr/2/). If you don't know about any of them, you
-should really read the recommendations. Can't wait? Use the [PHP-CS-Fixer
-tool](http://cs.sensiolabs.org/):
+You MUST follow the [PSR-12](http://www.php-fig.org/psr/12/).
+If you don't know about any of them, you should really read the recommendations.
+Can't wait? Use the [symplify/easy-coding-standard](https://github.com/symplify/easy-coding-standard):
```
-$ vendor/bin/php-cs-fixer fix --config-file=.php_cs
+$ vendor/bin/ecs --fix
+```
+
+In addition, we try to use the baseline code as close as the current PHP version features.
+For that, we use [Rector](https://github.com/rectorphp/rector-src).
+
+```
+$ vendor/bin/rector process
```
__Note:__ Never fix coding standards in some existing code as it makes code review more difficult.
diff --git a/Command/CheckConfigCommand.php b/Command/CheckConfigCommand.php
index ce694680..79c9e13a 100644
--- a/Command/CheckConfigCommand.php
+++ b/Command/CheckConfigCommand.php
@@ -57,7 +57,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->keyLoader->loadKey(KeyLoaderInterface::TYPE_PUBLIC);
}
} catch (\RuntimeException $e) {
- $output->writeln(''.$e->getMessage().'');
+ $output->writeln('' . $e->getMessage() . '');
return 1;
}
diff --git a/Command/GenerateTokenCommand.php b/Command/GenerateTokenCommand.php
index 4c3ab726..af8ac7d3 100644
--- a/Command/GenerateTokenCommand.php
+++ b/Command/GenerateTokenCommand.php
@@ -92,10 +92,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$payload = [];
- if(null !== $input->getOption('ttl') && ((int) $input->getOption('ttl')) == 0) {
+ if (null !== $input->getOption('ttl') && ((int) $input->getOption('ttl')) == 0) {
$payload['exp'] = 0;
- }
- elseif(null !== $input->getOption('ttl') && ((int) $input->getOption('ttl')) > 0) {
+ } elseif (null !== $input->getOption('ttl') && ((int) $input->getOption('ttl')) > 0) {
$payload['exp'] = time() + $input->getOption('ttl');
}
@@ -103,7 +102,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln([
'',
- ''.$token.'',
+ '' . $token . '',
'',
]);
diff --git a/DependencyInjection/Compiler/DeprecateLegacyGuardAuthenticatorPass.php b/DependencyInjection/Compiler/DeprecateLegacyGuardAuthenticatorPass.php
index 6c88c302..f5a3ca59 100644
--- a/DependencyInjection/Compiler/DeprecateLegacyGuardAuthenticatorPass.php
+++ b/DependencyInjection/Compiler/DeprecateLegacyGuardAuthenticatorPass.php
@@ -30,4 +30,3 @@ public function process(ContainerBuilder $container)
->setDeprecated(...$deprecationArgs);
}
}
-
diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php
index 1a3df10d..192712b6 100644
--- a/DependencyInjection/Configuration.php
+++ b/DependencyInjection/Configuration.php
@@ -79,7 +79,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->end()
->scalarNode('user_identity_field')
- ->setDeprecated(...$this->getDeprecationParameters('The "%path%.%node%" configuration key is deprecated since version 2.15, implement "'.UserInterface::class.'::getUserIdentifier()" instead.', '2.5'))
+ ->setDeprecated(...$this->getDeprecationParameters('The "%path%.%node%" configuration key is deprecated since version 2.15, implement "' . UserInterface::class . '::getUserIdentifier()" instead.', '2.5'))
->defaultValue('username')
->cannotBeEmpty()
->end()
diff --git a/DependencyInjection/LexikJWTAuthenticationExtension.php b/DependencyInjection/LexikJWTAuthenticationExtension.php
index 746698e4..43d414e0 100644
--- a/DependencyInjection/LexikJWTAuthenticationExtension.php
+++ b/DependencyInjection/LexikJWTAuthenticationExtension.php
@@ -29,7 +29,7 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
- $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
+ $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
if (method_exists(Alias::class, 'getDeprecation')) {
$loader->load('deprecated_51.xml');
@@ -80,7 +80,7 @@ public function load(array $configs, ContainerBuilder $container)
$container->setAlias(JWTEncoderInterface::class, 'lexik_jwt_authentication.encoder');
$container->setAlias(
'lexik_jwt_authentication.key_loader',
- new Alias('lexik_jwt_authentication.key_loader.'.('openssl' === $encoderConfig['crypto_engine'] && 'lexik_jwt_authentication.encoder.default' === $encoderConfig['service'] ? $encoderConfig['crypto_engine'] : 'raw'), true)
+ new Alias('lexik_jwt_authentication.key_loader.' . ('openssl' === $encoderConfig['crypto_engine'] && 'lexik_jwt_authentication.encoder.default' === $encoderConfig['service'] ? $encoderConfig['crypto_engine'] : 'raw'), true)
);
$container
@@ -141,7 +141,6 @@ public function load(array $configs, ContainerBuilder $container)
->replaceArgument(3, $config['pass_phrase'])
->replaceArgument(4, $encoderConfig['signature_algorithm']);
}
-
}
private static function createTokenExtractors(ContainerBuilder $container, array $tokenExtractorsConfig)
diff --git a/DependencyInjection/Security/Factory/JWTAuthenticatorFactoryTrait.php b/DependencyInjection/Security/Factory/JWTAuthenticatorFactoryTrait.php
index e7503862..994b51ae 100644
--- a/DependencyInjection/Security/Factory/JWTAuthenticatorFactoryTrait.php
+++ b/DependencyInjection/Security/Factory/JWTAuthenticatorFactoryTrait.php
@@ -64,7 +64,7 @@ public function addConfiguration(NodeDefinition $node)
public function createAuthenticator(ContainerBuilder $container, string $firewallName, array $config, string $userProviderId): string
{
- $authenticatorId = 'security.authenticator.jwt.'.$firewallName;
+ $authenticatorId = 'security.authenticator.jwt.' . $firewallName;
$userProviderId = empty($config['provider']) ? $userProviderId : 'security.user.provider.concrete.' . $config['provider'];
diff --git a/DependencyInjection/Security/Factory/JWTFactory.php b/DependencyInjection/Security/Factory/JWTFactory.php
index 7e30705c..6a4155d7 100644
--- a/DependencyInjection/Security/Factory/JWTFactory.php
+++ b/DependencyInjection/Security/Factory/JWTFactory.php
@@ -33,12 +33,12 @@ public function __construct($triggerDeprecation = true)
*/
public function create(ContainerBuilder $container, $id, $config, $userProvider, $defaultEntryPoint)
{
- $providerId = 'security.authentication.provider.jwt.'.$id;
+ $providerId = 'security.authentication.provider.jwt.' . $id;
$container
->setDefinition($providerId, new ChildDefinition($config['authentication_provider']))
->replaceArgument(0, new Reference($userProvider));
- $listenerId = 'security.authentication.listener.jwt.'.$id;
+ $listenerId = 'security.authentication.listener.jwt.' . $id;
$container
->setDefinition($listenerId, new ChildDefinition($config['authentication_listener']))
->replaceArgument(2, $config);
@@ -50,7 +50,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
}
if ($config['authorization_header']['enabled']) {
- $authorizationHeaderExtractorId = 'lexik_jwt_authentication.extractor.authorization_header_extractor.'.$id;
+ $authorizationHeaderExtractorId = 'lexik_jwt_authentication.extractor.authorization_header_extractor.' . $id;
$container
->setDefinition($authorizationHeaderExtractorId, new ChildDefinition('lexik_jwt_authentication.extractor.authorization_header_extractor'))
->replaceArgument(0, $config['authorization_header']['prefix'])
@@ -62,7 +62,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
}
if ($config['query_parameter']['enabled']) {
- $queryParameterExtractorId = 'lexik_jwt_authentication.extractor.query_parameter_extractor.'.$id;
+ $queryParameterExtractorId = 'lexik_jwt_authentication.extractor.query_parameter_extractor.' . $id;
$container
->setDefinition($queryParameterExtractorId, new ChildDefinition('lexik_jwt_authentication.extractor.query_parameter_extractor'))
->replaceArgument(0, $config['query_parameter']['name']);
@@ -73,7 +73,7 @@ public function create(ContainerBuilder $container, $id, $config, $userProvider,
}
if ($config['cookie']['enabled']) {
- $cookieExtractorId = 'lexik_jwt_authentication.extractor.cookie_extractor.'.$id;
+ $cookieExtractorId = 'lexik_jwt_authentication.extractor.cookie_extractor.' . $id;
$container
->setDefinition($cookieExtractorId, new ChildDefinition('lexik_jwt_authentication.extractor.cookie_extractor'))
->replaceArgument(0, $config['cookie']['name']);
@@ -174,7 +174,7 @@ public function addConfiguration(NodeDefinition $node)
*/
protected function createEntryPoint(ContainerBuilder $container, $id, $defaultEntryPoint)
{
- $entryPointId = 'lexik_jwt_authentication.security.authentication.entry_point.'.$id;
+ $entryPointId = 'lexik_jwt_authentication.security.authentication.entry_point.' . $id;
$container->setDefinition($entryPointId, new ChildDefinition('lexik_jwt_authentication.security.authentication.entry_point'));
return $entryPointId;
diff --git a/DependencyInjection/Security/Factory/JWTUserFactory.php b/DependencyInjection/Security/Factory/JWTUserFactory.php
index ef70cf8a..f013f032 100644
--- a/DependencyInjection/Security/Factory/JWTUserFactory.php
+++ b/DependencyInjection/Security/Factory/JWTUserFactory.php
@@ -40,7 +40,7 @@ public function addConfiguration(NodeDefinition $node)
->ifTrue(function ($class) {
return !(new \ReflectionClass($class))->implementsInterface(JWTUserInterface::class);
})
- ->thenInvalid('The %s class must implement '.JWTUserInterface::class.' for using the "lexik_jwt" user provider.')
+ ->thenInvalid('The %s class must implement ' . JWTUserInterface::class . ' for using the "lexik_jwt" user provider.')
->end()
->end()
->end()
diff --git a/Event/AuthenticationFailureEvent.php b/Event/AuthenticationFailureEvent.php
index d57cf6a3..394d2b30 100644
--- a/Event/AuthenticationFailureEvent.php
+++ b/Event/AuthenticationFailureEvent.php
@@ -58,11 +58,13 @@ public function setResponse(Response $response): void
$this->response = $response;
}
- public function getRequest(): ?Request {
+ public function getRequest(): ?Request
+ {
return $this->request;
}
- public function setRequest(Request $request) {
+ public function setRequest(Request $request)
+ {
$this->request = $request;
}
}
diff --git a/Event/JWTNotFoundEvent.php b/Event/JWTNotFoundEvent.php
index ca540369..3a29987d 100644
--- a/Event/JWTNotFoundEvent.php
+++ b/Event/JWTNotFoundEvent.php
@@ -2,7 +2,8 @@
namespace Lexik\Bundle\JWTAuthenticationBundle\Event;
-use Symfony\Component\HttpFoundation\{Response, Request};
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
/**
diff --git a/Response/JWTCompatAuthenticationFailureResponse.php b/Response/JWTCompatAuthenticationFailureResponse.php
index d57fa5ae..c1f37d08 100644
--- a/Response/JWTCompatAuthenticationFailureResponse.php
+++ b/Response/JWTCompatAuthenticationFailureResponse.php
@@ -9,7 +9,7 @@
* https://github.com/lexik/LexikJWTAuthenticationBundle/issues/944
* https://github.com/vimeo/psalm/issues/7923
*/
-if (80000 <= \PHP_VERSION_ID AND (new \ReflectionMethod(JsonResponse::class, 'setData'))->hasReturnType()) {
+if (80000 <= \PHP_VERSION_ID and (new \ReflectionMethod(JsonResponse::class, 'setData'))->hasReturnType()) {
eval('
namespace Lexik\Bundle\JWTAuthenticationBundle\Response;
diff --git a/Security/Authentication/Provider/JWTProvider.php b/Security/Authentication/Provider/JWTProvider.php
index c3bcadca..abfab67d 100644
--- a/Security/Authentication/Provider/JWTProvider.php
+++ b/Security/Authentication/Provider/JWTProvider.php
@@ -2,7 +2,6 @@
namespace Lexik\Bundle\JWTAuthenticationBundle\Security\Authentication\Provider;
-use Symfony\Component\Security\Core\User\UserInterface;
use Lexik\Bundle\JWTAuthenticationBundle\Event\JWTAuthenticatedEvent;
use Lexik\Bundle\JWTAuthenticationBundle\Events;
use Lexik\Bundle\JWTAuthenticationBundle\Exception\JWTDecodeFailureException;
@@ -12,6 +11,7 @@
use Symfony\Component\Security\Core\Authentication\Provider\AuthenticationProviderInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
+use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
diff --git a/Security/Authentication/Token/JWTUserToken.php b/Security/Authentication/Token/JWTUserToken.php
index 8331ce71..5961c9a1 100644
--- a/Security/Authentication/Token/JWTUserToken.php
+++ b/Security/Authentication/Token/JWTUserToken.php
@@ -12,12 +12,16 @@
*
* @internal
*/
- abstract class JWTCompatUserToken extends AbstractToken implements GuardTokenInterface {}
+ abstract class JWTCompatUserToken extends AbstractToken implements GuardTokenInterface
+ {
+ }
} else {
/**
* @internal
*/
- abstract class JWTCompatUserToken extends AbstractToken {}
+ abstract class JWTCompatUserToken extends AbstractToken
+ {
+ }
}
/**
diff --git a/Security/Authenticator/JWTAuthenticator.php b/Security/Authenticator/JWTAuthenticator.php
index 055b34c1..c5bd1aef 100644
--- a/Security/Authenticator/JWTAuthenticator.php
+++ b/Security/Authenticator/JWTAuthenticator.php
@@ -44,7 +44,7 @@ class JWTAuthenticator extends AbstractAuthenticator implements AuthenticationEn
/**
* @var TokenExtractorInterface
*/
- private $tokenExtractor;
+ private $tokenExtractor;
/**
* @var JWTTokenManagerInterface
@@ -123,10 +123,12 @@ public function doAuthenticate(Request $request) /*: Passport */
}
$passport = new SelfValidatingPassport(
- new UserBadge((string)$payload[$idClaim],
- function ($userIdentifier) use($payload) {
- return $this->loadUser($payload, $userIdentifier);
- })
+ new UserBadge(
+ (string)$payload[$idClaim],
+ function ($userIdentifier) use ($payload) {
+ return $this->loadUser($payload, $userIdentifier);
+ }
+ )
);
$passport->setAttribute('payload', $payload);
@@ -225,13 +227,13 @@ protected function loadUser(array $payload, string $identity): UserInterface
}
return $provider->loadUserByIdentifier($identity);
- // More generic call to catch both UsernameNotFoundException for SF<5.3 and new UserNotFoundException
+ // More generic call to catch both UsernameNotFoundException for SF<5.3 and new UserNotFoundException
} catch (AuthenticationException $e) {
// try next one
}
}
- if(!class_exists(UserNotFoundException::class)) {
+ if (!class_exists(UserNotFoundException::class)) {
$ex = new UsernameNotFoundException(sprintf('There is no user with username "%s".', $identity));
$ex->setUsername($identity);
} else {
diff --git a/Security/Guard/JWTTokenAuthenticator.php b/Security/Guard/JWTTokenAuthenticator.php
index 711d5eb9..b024b245 100644
--- a/Security/Guard/JWTTokenAuthenticator.php
+++ b/Security/Guard/JWTTokenAuthenticator.php
@@ -24,8 +24,8 @@
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
-use Symfony\Component\Security\Core\Exception\UserNotFoundException as SecurityUserNotFoundException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
+use Symfony\Component\Security\Core\Exception\UserNotFoundException as SecurityUserNotFoundException;
use Symfony\Component\Security\Core\User\ChainUserProvider;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
diff --git a/Services/JWSProvider/JWSProviderInterface.php b/Services/JWSProvider/JWSProviderInterface.php
index e4166bfe..ee9a9a8a 100644
--- a/Services/JWSProvider/JWSProviderInterface.php
+++ b/Services/JWSProvider/JWSProviderInterface.php
@@ -4,6 +4,7 @@
use Lexik\Bundle\JWTAuthenticationBundle\Signature\CreatedJWS;
use Lexik\Bundle\JWTAuthenticationBundle\Signature\LoadedJWS;
+
/**
* Interface for classes that are able to create and load JSON web signatures (JWS).
*
diff --git a/Services/JWSProvider/LcobucciJWSProvider.php b/Services/JWSProvider/LcobucciJWSProvider.php
index c5838c1a..b3f017e0 100644
--- a/Services/JWSProvider/LcobucciJWSProvider.php
+++ b/Services/JWSProvider/LcobucciJWSProvider.php
@@ -2,17 +2,17 @@
namespace Lexik\Bundle\JWTAuthenticationBundle\Services\JWSProvider;
-use Lcobucci\JWT\Signer\Hmac\Sha256;
-use Lcobucci\JWT\Signer\Hmac\Sha384;
-use Lcobucci\JWT\Signer\Hmac\Sha512;
-use Lcobucci\JWT\Signer\Ecdsa;
use Lcobucci\Clock\SystemClock;
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Encoding\ChainedFormatter;
use Lcobucci\JWT\Encoding\JoseEncoder;
use Lcobucci\JWT\Parser;
use Lcobucci\JWT\Signer;
+use Lcobucci\JWT\Signer\Ecdsa;
use Lcobucci\JWT\Signer\Hmac;
+use Lcobucci\JWT\Signer\Hmac\Sha256;
+use Lcobucci\JWT\Signer\Hmac\Sha384;
+use Lcobucci\JWT\Signer\Hmac\Sha512;
use Lcobucci\JWT\Signer\Key;
use Lcobucci\JWT\Signer\Key\InMemory;
use Lcobucci\JWT\Token;
@@ -109,7 +109,7 @@ public function create(array $payload, array $header = [])
$exp = $payload['exp'] ?? $now + $this->ttl;
unset($payload['exp']);
- if($exp) {
+ if ($exp) {
$jws->expiresAt($exp instanceof \DateTimeImmutable ? $exp : ($this->useDateObjects ? new \DateTimeImmutable("@$exp") : $exp));
}
}
diff --git a/Tests/Functional/Command/GenerateKeyPairCommandTest.php b/Tests/Functional/Command/GenerateKeyPairCommandTest.php
index 940f96d2..f7f985e4 100644
--- a/Tests/Functional/Command/GenerateKeyPairCommandTest.php
+++ b/Tests/Functional/Command/GenerateKeyPairCommandTest.php
@@ -57,7 +57,6 @@ public function testItGeneratesKeyPair($algorithm, $passphrase)
\openssl_public_encrypt($payload, $encryptedData, \openssl_pkey_get_public($publicKey));
\openssl_private_decrypt($encryptedData, $decryptedData, \openssl_pkey_get_private($privateKey, $passphrase));
$this->assertSame($payload, $decryptedData);*/
-
}
public function providePassphrase()
@@ -190,7 +189,7 @@ public function testSkipIfExistsWritesIfNotExists()
)
);
- $this->assertSame(0, $tester->execute(['--skip-if-exists' => true], ['interactive' => false]));
+ $this->assertSame(0, $tester->execute(['--skip-if-exists' => true], ['interactive' => false]));
$this->assertStringContainsString('Done!', $tester->getDisplay(true));
$privateKey = \file_get_contents($privateKeyFile);
$publicKey = \file_get_contents($publicKeyFile);
@@ -216,7 +215,7 @@ public function testSkipIfExistsDoesNothingIfExists()
)
);
- $this->assertSame(0, $tester->execute(['--skip-if-exists' => true], ['interactive' => false]));
+ $this->assertSame(0, $tester->execute(['--skip-if-exists' => true], ['interactive' => false]));
$this->assertStringContainsString(
'Your key files already exist, they won\'t be overriden.',
$tester->getDisplay(true)
@@ -227,5 +226,4 @@ public function testSkipIfExistsDoesNothingIfExists()
$this->assertStringContainsString('foobar', $privateKey);
$this->assertStringContainsString('foobar', $publicKey);
}
-
}
diff --git a/Tests/Functional/GetTokenTest.php b/Tests/Functional/GetTokenTest.php
index 7f7ee031..cb452abe 100644
--- a/Tests/Functional/GetTokenTest.php
+++ b/Tests/Functional/GetTokenTest.php
@@ -46,7 +46,7 @@ public function testGetTokenWithListener()
});
static::$client->request('POST', '/login_check', ['_username' => 'lexik', '_password' => 'dummy']);
- static::$client->request('GET', '/api/secured', [], [], ['HTTP_AUTHORIZATION' => 'Bearer '.$this->getToken(static::$client->getResponse())]);
+ static::$client->request('GET', '/api/secured', [], [], ['HTTP_AUTHORIZATION' => 'Bearer ' . $this->getToken(static::$client->getResponse())]);
$this->assertArrayHasKey('added_data', $payloadTested->payload, 'The payload should contains a "added_data" claim.');
$this->assertSame('still visible after the event', $payloadTested->payload['added_data'], 'The "added_data" claim should be equal to "still visible after the event".');
diff --git a/Tests/Functional/TestCase.php b/Tests/Functional/TestCase.php
index a4cad0ce..4dc50bc1 100644
--- a/Tests/Functional/TestCase.php
+++ b/Tests/Functional/TestCase.php
@@ -20,7 +20,7 @@ abstract class TestCase extends WebTestCase
*/
protected static function createKernel(array $options = []): KernelInterface
{
- require_once __DIR__.'/app/AppKernel.php';
+ require_once __DIR__ . '/app/AppKernel.php';
return new AppKernel('test', true, $options['test_case'] ?? null);
}
@@ -65,6 +65,6 @@ protected static function getAuthenticatedToken()
protected function doSetUp()
{
$fs = new Filesystem();
- $fs->remove(sys_get_temp_dir().'/LexikJWTAuthenticationBundle/');
+ $fs->remove(sys_get_temp_dir() . '/LexikJWTAuthenticationBundle/');
}
}
diff --git a/Tests/Functional/app/AppKernel.php b/Tests/Functional/app/AppKernel.php
index 4216b7a9..dcd9307d 100644
--- a/Tests/Functional/app/AppKernel.php
+++ b/Tests/Functional/app/AppKernel.php
@@ -59,7 +59,7 @@ public function getRootDir()
*/
public function getCacheDir(): string
{
- return sys_get_temp_dir().'/LexikJWTAuthenticationBundle/cache';
+ return sys_get_temp_dir() . '/LexikJWTAuthenticationBundle/cache';
}
/**
@@ -67,7 +67,7 @@ public function getCacheDir(): string
*/
public function getLogDir(): string
{
- return sys_get_temp_dir().'/LexikJWTAuthenticationBundle/logs';
+ return sys_get_temp_dir() . '/LexikJWTAuthenticationBundle/logs';
}
/**
@@ -75,7 +75,7 @@ public function getLogDir(): string
*/
public function registerContainerConfiguration(LoaderInterface $loader)
{
- $loader->load(__DIR__.'/config/config_router_utf8.yml');
+ $loader->load(__DIR__ . '/config/config_router_utf8.yml');
// 5.3+ session config
if (class_exists(UserNotFoundException::class)) {
@@ -101,19 +101,19 @@ public function registerContainerConfiguration(LoaderInterface $loader)
]);
});
- if ($this->testCase && file_exists(__DIR__.'/config/'.$this->testCase.'/config.yml')) {
- $loader->load(__DIR__.'/config/'.$this->testCase.'/config.yml');
+ if ($this->testCase && file_exists(__DIR__ . '/config/' . $this->testCase . '/config.yml')) {
+ $loader->load(__DIR__ . '/config/' . $this->testCase . '/config.yml');
}
- $loader->load(__DIR__.sprintf('/config/security_%s.yml', $this->userProvider . (class_exists(UserNotFoundException::class) ? '' : '_legacy')));
+ $loader->load(__DIR__ . sprintf('/config/security_%s.yml', $this->userProvider . (class_exists(UserNotFoundException::class) ? '' : '_legacy')));
- if ($this->signatureAlgorithm && file_exists($file = __DIR__.sprintf('/config/config_%s_%s.yml', $this->encoder, strtolower($this->signatureAlgorithm)))) {
+ if ($this->signatureAlgorithm && file_exists($file = __DIR__ . sprintf('/config/config_%s_%s.yml', $this->encoder, strtolower($this->signatureAlgorithm)))) {
$loader->load($file);
return;
}
- $loader->load(__DIR__.sprintf('/config/config_%s.yml', $this->encoder));
+ $loader->load(__DIR__ . sprintf('/config/config_%s.yml', $this->encoder));
}
public function getUserProvider()
diff --git a/Tests/Security/Authenticator/JWTAuthenticatorTest.php b/Tests/Security/Authenticator/JWTAuthenticatorTest.php
index 284b80bf..20e47790 100644
--- a/Tests/Security/Authenticator/JWTAuthenticatorTest.php
+++ b/Tests/Security/Authenticator/JWTAuthenticatorTest.php
@@ -1,4 +1,5 @@
'lexik'];
$rawToken = 'token';
@@ -70,7 +72,8 @@ public function testAuthenticate() {
$this->assertSame($userStub, ($authenticator->authenticate($this->getRequestMock()))->getUser());
}
- public function testAuthenticateWithIntegerIdentifier() {
+ public function testAuthenticateWithIntegerIdentifier()
+ {
$userIdClaim = 'sub';
$payload = [$userIdClaim => 1];
$rawToken = 'token';
@@ -99,7 +102,8 @@ public function testAuthenticateWithIntegerIdentifier() {
$this->assertSame($userStub, ($authenticator->authenticate($this->getRequestMock()))->getUser());
}
- public function testAuthenticateWithExpiredTokenThrowsException() {
+ public function testAuthenticateWithExpiredTokenThrowsException()
+ {
$jwtManager = $this->getJWTManagerMock();
$jwtManager->method('parse')
->will($this->throwException(new JWTDecodeFailureException(JWTDecodeFailureException::EXPIRED_TOKEN, 'Expired JWT Token')));
@@ -116,12 +120,15 @@ public function testAuthenticateWithExpiredTokenThrowsException() {
$authenticator->authenticate($this->getRequestMock());
}
- public function testAuthenticateWithInvalidTokenThrowsException() {
+ public function testAuthenticateWithInvalidTokenThrowsException()
+ {
$jwtManager = $this->getJWTManagerMock();
$jwtManager->method('parse')
- ->willThrowException(new JWTDecodeFailureException(
- JWTDecodeFailureException::INVALID_TOKEN,
- 'Invalid JWT Token')
+ ->willThrowException(
+ new JWTDecodeFailureException(
+ JWTDecodeFailureException::INVALID_TOKEN,
+ 'Invalid JWT Token'
+ )
);
$authenticator = new JWTAuthenticator(
$jwtManager,
@@ -135,7 +142,8 @@ public function testAuthenticateWithInvalidTokenThrowsException() {
$authenticator->authenticate($this->getRequestMock());
}
- public function testAuthenticateWithUndecodableTokenThrowsException() {
+ public function testAuthenticateWithUndecodableTokenThrowsException()
+ {
$jwtManager = $this->getJWTManagerMock();
$jwtManager->method('parse')
->willThrowException(new JWTDecodeFailureException(
@@ -155,7 +163,8 @@ public function testAuthenticateWithUndecodableTokenThrowsException() {
$authenticator->authenticate($this->getRequestMock());
}
- public function testAuthenticationWithInvalidPayloadThrowsException() {
+ public function testAuthenticationWithInvalidPayloadThrowsException()
+ {
$jwtManager = $this->getJWTManagerMock();
$jwtManager->method('parse')
->willReturn(['foo' => 'bar']);
@@ -173,7 +182,8 @@ public function testAuthenticationWithInvalidPayloadThrowsException() {
$authenticator->authenticate($this->getRequestMock());
}
- public function testAuthenticateWithInvalidUserThrowsException() {
+ public function testAuthenticateWithInvalidUserThrowsException()
+ {
$jwtManager = $this->getJWTManagerMock();
$jwtManager->method('parse')
->willReturn(['identifier' => 'bar']);
@@ -196,7 +206,8 @@ public function testAuthenticateWithInvalidUserThrowsException() {
$authenticator->authenticate($this->getRequestMock())->getUser();
}
- public function testOnAuthenticationFailureWithInvalidToken() {
+ public function testOnAuthenticationFailureWithInvalidToken()
+ {
$authException = new InvalidTokenException();
$expectedResponse = new JWTAuthenticationFailureResponse('Invalid JWT Token');
$request = $this->getRequestMock();
@@ -216,7 +227,8 @@ public function testOnAuthenticationFailureWithInvalidToken() {
$this->assertSame($expectedResponse->getMessage(), $response->getMessage());
}
- public function testOnAuthenticationFailureWithInvalidTokenTranslatedMessage() {
+ public function testOnAuthenticationFailureWithInvalidTokenTranslatedMessage()
+ {
$authException = new InvalidTokenException();
$expectedResponse = new JWTAuthenticationFailureResponse('translated message');
$request = $this->getRequestMock();
diff --git a/Tests/Security/Guard/JWTTokenAuthenticatorTest.php b/Tests/Security/Guard/JWTTokenAuthenticatorTest.php
index e7df816c..dfb3a69c 100644
--- a/Tests/Security/Guard/JWTTokenAuthenticatorTest.php
+++ b/Tests/Security/Guard/JWTTokenAuthenticatorTest.php
@@ -21,8 +21,8 @@
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
-use Symfony\Component\Security\Core\Exception\UserNotFoundException as SecurityUserNotFoundException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
+use Symfony\Component\Security\Core\Exception\UserNotFoundException as SecurityUserNotFoundException;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
use Symfony\Component\Security\Guard\AuthenticatorInterface;
@@ -266,11 +266,11 @@ public function testCreateAuthenticatedTokenThrowsExceptionIfNotPreAuthenticated
$tokenStorage->expects(self::once())->method('getToken')->willReturn(null);
(new JWTTokenAuthenticator(
- $this->getJWTManagerMock(),
- $this->getEventDispatcherMock(),
- $this->getTokenExtractorMock(),
- $tokenStorage
- ))->createAuthenticatedToken($userStub, 'lexik');
+ $this->getJWTManagerMock(),
+ $this->getEventDispatcherMock(),
+ $this->getTokenExtractorMock(),
+ $tokenStorage
+ ))->createAuthenticatedToken($userStub, 'lexik');
}
public function testOnAuthenticationFailureWithInvalidToken()
diff --git a/Tests/Services/JWSProvider/AbstractJWSProviderTest.php b/Tests/Services/JWSProvider/AbstractJWSProviderTest.php
index 39d6e093..f7c01d78 100644
--- a/Tests/Services/JWSProvider/AbstractJWSProviderTest.php
+++ b/Tests/Services/JWSProvider/AbstractJWSProviderTest.php
@@ -79,7 +79,7 @@ public function testCreate()
->method('getPassphrase')
->willReturn('foobar');
- $payload = ['username' => 'chalasr', 'iat' => time()];
+ $payload = ['username' => 'chalasr', 'iat' => time()];
$jwsProvider = new static::$providerClass($keyLoaderMock, 'openssl', 'RS384', 3600, 0);
$this->assertInstanceOf(CreatedJWS::class, $created = $jwsProvider->create($payload));
diff --git a/Tests/Services/JWSProvider/LcobucciJWSProviderTest.php b/Tests/Services/JWSProvider/LcobucciJWSProviderTest.php
index 36440c07..9e8c37bc 100644
--- a/Tests/Services/JWSProvider/LcobucciJWSProviderTest.php
+++ b/Tests/Services/JWSProvider/LcobucciJWSProviderTest.php
@@ -84,7 +84,7 @@ public function testCreateWithEcdsa()
->method('getPassphrase')
->willReturn('foobar');
- $payload = ['username' => 'chalasr'];
+ $payload = ['username' => 'chalasr'];
$jwsProvider = new LcobucciJWSProvider($keyLoaderMock, 'openssl', 'ES512', 3600, 0);
$this->assertInstanceOf(CreatedJWS::class, $created = $jwsProvider->create($payload));
@@ -139,7 +139,7 @@ protected function createMultiplePublicKeysTestToken()
->with('private')
->willReturn(self::$multiplePublicKeysTestTokenPrivateKey);
- $payload = ['username' => 'chalasr', 'iat' => time()];
+ $payload = ['username' => 'chalasr', 'iat' => time()];
$jwsProvider = new self::$providerClass($keyLoaderMock, 'openssl', 'RS256', 3600, 0);
return $jwsProvider->create($payload)->getToken();
diff --git a/ecs.php b/ecs.php
new file mode 100644
index 00000000..5d5b330e
--- /dev/null
+++ b/ecs.php
@@ -0,0 +1,25 @@
+sets([SetList::PSR_12, ]);
+ $config->rule(OrderedImportsFixer::class);
+ $config->ruleWithConfiguration(ArraySyntaxFixer::class, [
+ 'syntax' => 'short',
+ ]);
+ $config->services()->remove(PhpdocScalarFixer::class);
+
+ $config->parallel();
+ $config->paths([__DIR__]);
+ $config->skip([
+ __DIR__ . '/.github',
+ __DIR__ . '/vendor',
+ ]);
+};