From 9aeff899ffd6b6701a5e867013397867834116f8 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Thu, 30 Nov 2023 16:45:26 +0100 Subject: [PATCH 1/5] Drop not supported PHP 7.4 & 8.0 --- .github/workflows/ci.yaml | 12 +++++------- CHANGELOG.md | 3 +++ composer.json | 4 ++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1d2d723a4..b5edfc106 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -26,10 +26,10 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: '8.1' extensions: curl, openssl, mbstring ini-values: memory_limit=-1 - tools: pecl, composer, php-cs-fixer + tools: php-cs-fixer - name: Run PHP-CS-Fixer fix run: php-cs-fixer fix --dry-run --diff --ansi @@ -46,7 +46,7 @@ jobs: - name: Setup PHP uses: shivammathur/setup-php@v2 with: - php-version: '7.4' + php-version: '8.1' extensions: curl, openssl, mbstring ini-values: memory_limit=-1 tools: composer @@ -64,12 +64,10 @@ jobs: strategy: matrix: include: - - php: '7.4' - symfony-version: '^5.4' - - php: '7.4' + - php: '8.1' symfony-version: '^5.4' bc: true - - php: '8.0' + - php: '8.1' symfony-version: '^5.4' - php: '8.1' symfony-version: '^6.3' diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c7557ae7..a819e6533 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ Changelog ========= +## 2.2.0 (202x-xx-xx) +* BC Break: Dropped support for PHP 7.4 & 8.0, + ## 2.1.0 (2023-11-30) * BC Break: Dropped support for Symfony: `>6.0, <6.3`, * Added: New Passage resource owner, diff --git a/composer.json b/composer.json index 88902edce..c7525be2f 100644 --- a/composer.json +++ b/composer.json @@ -93,8 +93,8 @@ ], "require": { - "php": "^7.4 || ^8.0", - "symfony/deprecation-contracts": "^2.5 || ^3.0", + "php": "^8.1", + "symfony/deprecation-contracts": "^3.0", "symfony/framework-bundle": "^5.4 || ^6.3 || ^7.0", "symfony/security-bundle": "^5.4 || ^6.3 || ^7.0", "symfony/options-resolver": "^5.4 || ^6.3 || ^7.0", From 35c27bed051b7e994d237309257bb0d3726e1191 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Thu, 30 Nov 2023 16:46:07 +0100 Subject: [PATCH 2/5] Run cs-fixer on PHP 8.1 --- src/OAuth/RequestDataStorage/SessionStorage.php | 2 +- src/Security/Core/Authentication/Provider/OAuthProvider.php | 2 +- src/Security/Core/User/EntityUserProvider.php | 4 ++-- src/Security/Core/User/OAuthUserProvider.php | 4 ++-- src/Security/Http/Authenticator/OAuthAuthenticator.php | 6 +++--- .../ResourceOwner/GenericOAuth2ResourceOwnerTestCase.php | 2 +- tests/OAuth/RequestDataStorage/SessionStorageTest.php | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/OAuth/RequestDataStorage/SessionStorage.php b/src/OAuth/RequestDataStorage/SessionStorage.php index 7c22de5ff..8e2fb29c8 100644 --- a/src/OAuth/RequestDataStorage/SessionStorage.php +++ b/src/OAuth/RequestDataStorage/SessionStorage.php @@ -98,7 +98,7 @@ private function getStorageKey($value): string if (\is_array($value)) { $storageKey = reset($value); } elseif (\is_object($value)) { - $storageKey = \get_class($value); + $storageKey = $value::class; } else { $storageKey = $value; } diff --git a/src/Security/Core/Authentication/Provider/OAuthProvider.php b/src/Security/Core/Authentication/Provider/OAuthProvider.php index 99ec93ef0..a1874c436 100644 --- a/src/Security/Core/Authentication/Provider/OAuthProvider.php +++ b/src/Security/Core/Authentication/Provider/OAuthProvider.php @@ -137,7 +137,7 @@ private function createOAuthToken( OAuthToken $oldToken, ?UserInterface $user ): OAuthToken { - $tokenClass = \get_class($oldToken); + $tokenClass = $oldToken::class; if (null !== $user) { $token = new $tokenClass($data, $user->getRoles()); $token->setUser($user); diff --git a/src/Security/Core/User/EntityUserProvider.php b/src/Security/Core/User/EntityUserProvider.php index 81604b26f..07a902b19 100644 --- a/src/Security/Core/User/EntityUserProvider.php +++ b/src/Security/Core/User/EntityUserProvider.php @@ -94,8 +94,8 @@ public function refreshUser(UserInterface $user): UserInterface { $accessor = PropertyAccess::createPropertyAccessor(); $identifier = $this->properties['identifier']; - if (!$accessor->isReadable($user, $identifier) || !$this->supportsClass(\get_class($user))) { - throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); + if (!$accessor->isReadable($user, $identifier) || !$this->supportsClass($user::class)) { + throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class)); } $userId = $accessor->getValue($user, $identifier); diff --git a/src/Security/Core/User/OAuthUserProvider.php b/src/Security/Core/User/OAuthUserProvider.php index 5067f7302..8ae6ca175 100644 --- a/src/Security/Core/User/OAuthUserProvider.php +++ b/src/Security/Core/User/OAuthUserProvider.php @@ -45,8 +45,8 @@ public function loadUserByOAuthUserResponse(UserResponseInterface $response): Us public function refreshUser(UserInterface $user): UserInterface { - if (!$this->supportsClass(\get_class($user))) { - throw new UnsupportedUserException(sprintf('Unsupported user class "%s"', \get_class($user))); + if (!$this->supportsClass($user::class)) { + throw new UnsupportedUserException(sprintf('Unsupported user class "%s"', $user::class)); } // @phpstan-ignore-next-line Symfony <5.4 BC layer diff --git a/src/Security/Http/Authenticator/OAuthAuthenticator.php b/src/Security/Http/Authenticator/OAuthAuthenticator.php index 96a055bf3..bbe85e615 100644 --- a/src/Security/Http/Authenticator/OAuthAuthenticator.php +++ b/src/Security/Http/Authenticator/OAuthAuthenticator.php @@ -167,7 +167,7 @@ public function refreshToken(OAuthToken $token): OAuthToken if ($token->isExpired()) { $expiredToken = $token; if ($refreshToken = $expiredToken->getRefreshToken()) { - $tokenClass = \get_class($expiredToken); + $tokenClass = $expiredToken::class; $token = new $tokenClass($resourceOwner->refreshAccessToken($refreshToken)); $token->setResourceOwnerName($expiredToken->getResourceOwnerName()); if (!$token->getRefreshToken()) { @@ -213,7 +213,7 @@ public function recreateToken(OAuthToken $token, UserInterface $user = null): OA { $user = $user instanceof UserInterface ? $user : $token->getUser(); - $tokenClass = \get_class($token); + $tokenClass = $token::class; if ($user) { $newToken = new $tokenClass( $token->getRawToken(), @@ -254,7 +254,7 @@ public function createAuthenticatedToken($passport, string $firewallName): Token return $passport->getToken(); } - throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, SelfValidatedOAuthPassport::class, \get_class($passport))); + throw new \LogicException(sprintf('The first argument of "%s" must be instance of "%s", "%s" provided.', __METHOD__, SelfValidatedOAuthPassport::class, $passport::class)); } public function onAuthenticationSuccess(Request $request, TokenInterface $token, string $firewallName): ?Response diff --git a/src/Test/OAuth/ResourceOwner/GenericOAuth2ResourceOwnerTestCase.php b/src/Test/OAuth/ResourceOwner/GenericOAuth2ResourceOwnerTestCase.php index 37a7a0fcb..fcb3d6f2b 100644 --- a/src/Test/OAuth/ResourceOwner/GenericOAuth2ResourceOwnerTestCase.php +++ b/src/Test/OAuth/ResourceOwner/GenericOAuth2ResourceOwnerTestCase.php @@ -441,7 +441,7 @@ protected function createResourceOwner( /** @var GenericOAuth2ResourceOwner $resourceOwner */ $resourceOwner = parent::createResourceOwner($options, $paths, $responses); - $reflection = new \ReflectionClass(\get_class($resourceOwner)); + $reflection = new \ReflectionClass($resourceOwner::class); $stateProperty = $reflection->getProperty('state'); $stateProperty->setAccessible(true); $stateProperty->setValue($resourceOwner, $state ?: new State($this->state)); diff --git a/tests/OAuth/RequestDataStorage/SessionStorageTest.php b/tests/OAuth/RequestDataStorage/SessionStorageTest.php index 1e37294df..2b4bd6c7e 100644 --- a/tests/OAuth/RequestDataStorage/SessionStorageTest.php +++ b/tests/OAuth/RequestDataStorage/SessionStorageTest.php @@ -146,7 +146,7 @@ public function testFetchOtherThenToken(): void ->method('remove') ->with($key); - $data = $this->storage->fetch($this->resourceOwner, \get_class($class), 'state'); + $data = $this->storage->fetch($this->resourceOwner, $class::class, 'state'); self::assertEquals(serialize($class), $data); } } From f8d772d8a81e10e489e5a6c5548a9d3006b2dbb5 Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Thu, 30 Nov 2023 16:48:43 +0100 Subject: [PATCH 3/5] Run phpstan against Symfony 5.4 --- .github/workflows/ci.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b5edfc106..9734ce5b0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -52,7 +52,11 @@ jobs: tools: composer - name: Update project dependencies - run: composer update --no-interaction --no-progress --ansi + run: | + composer global config --no-plugins allow-plugins.symfony/flex true + composer global require symfony/flex --no-progress --no-scripts --no-plugins + composer config extra.symfony.require "5.4" + composer update --no-interaction --no-progress --ansi - name: Run phpstan run: composer phpstan From 9cebf6459f5a270a84c8796c956eb76010adb6af Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Thu, 30 Nov 2023 16:52:46 +0100 Subject: [PATCH 4/5] Fix phpstan reports --- src/DependencyInjection/Configuration.php | 1 + src/OAuth/Response/SensioConnectUserResponse.php | 10 ++++------ 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index d79faef62..ea8c79c35 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -144,6 +144,7 @@ public function getConfigTreeBuilder(): TreeBuilder private function addResourceOwnersConfiguration(ArrayNodeDefinition $node): void { + /* @phpstan-ignore-next-line */ $node ->fixXmlConfig('resource_owner') ->children() diff --git a/src/OAuth/Response/SensioConnectUserResponse.php b/src/OAuth/Response/SensioConnectUserResponse.php index 7a248e6a6..2bfc43f5d 100644 --- a/src/OAuth/Response/SensioConnectUserResponse.php +++ b/src/OAuth/Response/SensioConnectUserResponse.php @@ -23,19 +23,17 @@ final class SensioConnectUserResponse extends AbstractUserResponse * @var \DOMNode */ protected $data; - /** - * @var \DOMXPath|null - */ - private $xpath; + + private ?\DOMXPath $xpath; /** * {@inheritdoc} */ public function getUserIdentifier(): string { - /** @var \DOMAttr $attribute */ + /** @var \DOMAttr|null $attribute */ $attribute = $this->data->attributes->getNamedItem('id'); - if (null === $attribute->value) { + if (null === $attribute) { throw new \InvalidArgumentException('User identifier was not found in response.'); } From de71c531fd78af70060f66fe5d7f147f97c6326c Mon Sep 17 00:00:00 2001 From: Joseph Bielawski Date: Thu, 30 Nov 2023 17:00:20 +0100 Subject: [PATCH 5/5] Adjust README file to match supported PHP versions & remove mention of outdated 1.4 --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index 67552d536..7904a1040 100644 --- a/README.md +++ b/README.md @@ -12,9 +12,7 @@ Installation All the installation instructions are located in the documentation, check it for a specific version: -* [__2.x__](https://github.com/hwi/HWIOAuthBundle/blob/master/docs/1-setting_up_the_bundle.md) (current) - with support for Symfony: `^5.4`, `^6.3` & `^7.0` (PHP: `^7.4`, `^8.0`), - -* [__1.4__](https://github.com/hwi/HWIOAuthBundle/blob/1.4/Resources/doc/1-setting_up_the_bundle.md) (unsupported) - with support for Symfony: `^4.4` & `^5.1` (PHP: `^7.3` & `^8.0`), +* [__2.x__](https://github.com/hwi/HWIOAuthBundle/blob/master/docs/1-setting_up_the_bundle.md) (current) - with support for Symfony: `^5.4`, `^6.3` & `^7.0` (PHP: `^8.1`), Documentation ------------- @@ -23,7 +21,6 @@ The bulk of the documentation is stored in the `Resources/doc/index.md` file in this bundle. Read the documentation for version: * [__2.x__](https://github.com/hwi/HWIOAuthBundle/blob/master/docs/index.md) -* [__1.4__](https://github.com/hwi/HWIOAuthBundle/blob/1.4/Resources/doc/index.md) (unsupported) This bundle contains support for 58 different providers: * 37signals,