From 2f6c9342c711597e3b5f1f2468910336be5232d6 Mon Sep 17 00:00:00 2001 From: Victor Bocharsky Date: Mon, 18 Dec 2023 22:58:12 +0100 Subject: [PATCH] Drop legacy PHP 7.4-8.0 support (#426) * Drop legacy PHP 7.4-8.0 support * Tweak PHP constraint in composer.json * Bump min version of phpstan/phpstan to 1.0 * Do not override PHP version for CS and SCA jobs * Fix CS * Set php-version-lowest to 8.1.0 * Revert "Bump min version of phpstan/phpstan to 1.0" This reverts commit 26dedbdf4f6e836b4964af5c2b19f599c996df83. * Reapply "Bump min version of phpstan/phpstan to 1.0" This reverts commit e88453217b36fe2faf57da3742a66681bcb6a87d. * Fix PHPStan deprecation error * Fix PHPstan errors * Drop legacy treeBuilder->root() call * Simplify CI config thanks to upstream changes --- .github/workflows/ci.yaml | 7 ------ composer.json | 4 ++-- phpstan.neon.dist | 22 ++++++++----------- src/Client/Provider/PassageClient.php | 2 +- src/DependencyInjection/Configuration.php | 4 +--- .../KnpUOAuth2ClientExtension.php | 4 +--- src/Security/User/OAuthUserProvider.php | 2 +- 7 files changed, 15 insertions(+), 30 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3fd5b0f7..8ba9c7dd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -10,19 +10,12 @@ on: jobs: test: uses: SymfonyCasts/.github/.github/workflows/phpunit.yaml@main - with: - php-version-matrix: '["7.4", "8.0", "8.1", "8.2", "8.3"]' - php-version-lowest: '7.4' composer-validate: uses: SymfonyCasts/.github/.github/workflows/composer-validate.yaml@main cs: uses: SymfonyCasts/.github/.github/workflows/php-cs-fixer.yaml@main - with: - php: '7.4' sca: uses: SymfonyCasts/.github/.github/workflows/phpstan.yaml@main - with: - php: '8.0' diff --git a/composer.json b/composer.json index 6b2e1f84..eff2df0a 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ } ], "require": { - "php": ">=7.4", + "php": ">=8.1", "symfony/framework-bundle": "^4.4|^5.0|^6.0|^7.0", "symfony/dependency-injection": "^4.4|^5.0|^6.0|^7.0", "symfony/routing": "^4.4|^5.0|^6.0|^7.0", @@ -25,7 +25,7 @@ "symfony/phpunit-bridge": "^5.3.1|^6.0|^7.0", "symfony/security-guard": "^4.4|^5.0|^6.0|^7.0", "symfony/yaml": "^4.4|^5.0|^6.0|^7.0", - "phpstan/phpstan": "^0.12" + "phpstan/phpstan": "^1.0" }, "autoload": { "psr-4": { "KnpU\\OAuth2ClientBundle\\": "src/" } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index f09298c5..364c32a1 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,22 +3,23 @@ parameters: inferPrivatePropertyTypeFromConstructor: true paths: - ./src/ - excludes_analyse: + excludePaths: - */cache/* ignoreErrors: # False positive: clients are not dependencies of this project. - - message: '#Return typehint of method KnpU\\OAuth2ClientBundle\\Client\\Provider\\[a-zA-Z0-9\\_]+::fetchUserFromToken\(\) has invalid type [a-zA-Z0-9\\_]#' - path: ./src/Client/Provider + message: '#Method KnpU\\OAuth2ClientBundle\\Client\\Provider\\\w+::fetchUserFromToken\(\) has invalid return type .+#' + path: ./src/Client/Provider/ - - message: '#Return typehint of method KnpU\\OAuth2ClientBundle\\Client\\Provider\\[a-zA-Z0-9\\_]+::fetchUser\(\) has invalid type [a-zA-Z0-9\\_]#' - path: ./src/Client/Provider + message: '#Method KnpU\\OAuth2ClientBundle\\Client\\Provider\\\w+::fetchUser\(\) has invalid return type .+#' + path: ./src/Client/Provider/ - - message: '#Class League\\OAuth2\\Client\\Provider\\[a-zA-Z0-9\\_]+ not found\.#' + message: '#Class League\\OAuth2\\Client\\Provider\\Passage not found\.#' path: ./src/Client/Provider - - message: '#Call to method [a-zA-Z0-9\\_]+\(\) on an unknown class League\\OAuth2\\Client\\Provider\\[a-zA-Z0-9\\_]+\.#' + message: '#Call to method getLogoutUrl\(\) on an unknown class League\\OAuth2\\Client\\Provider\\Passage\.#' path: ./src/Client/Provider + # False positive: using `::class` is not an error for those providers `::getProviderClass()` method. - message: '#Class [a-zA-Z0-9\\_]+ not found#' @@ -28,14 +29,9 @@ parameters: - message: '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface::scalarNode\(\)\.#' path: ./src/DependencyInjection/Providers - - message: '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeParentInterface::arrayNode\(\)\.#' path: ./src/DependencyInjection/Providers - - message: '#.*NodeDefinition::children.*#' - path: ./src/DependencyInjection - # Searches for root(), for backward compatibility with Symfony <4.2. Removed in 5.0 - - - message: '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\TreeBuilder::root\(\)\.#' + message: '#Call to an undefined method Symfony\\Component\\Config\\Definition\\Builder\\NodeDefinition::children\(\)\.#' path: ./src/DependencyInjection diff --git a/src/Client/Provider/PassageClient.php b/src/Client/Provider/PassageClient.php index 7e3aaa2e..8c6fe76b 100644 --- a/src/Client/Provider/PassageClient.php +++ b/src/Client/Provider/PassageClient.php @@ -40,7 +40,7 @@ public function logout(): RedirectResponse $provider = $this->getOAuth2Provider(); if (!($provider instanceof Passage)) { - throw new \RuntimeException('Invalid provider "'.\get_class($provider).'", expected provider "'.Passage::class.'"'); + throw new \RuntimeException('Invalid provider "'.$provider::class.'", expected provider "'.Passage::class.'"'); } return new RedirectResponse($provider->getLogoutUrl()); diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index ca93d9f2..2e163494 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -18,9 +18,7 @@ class Configuration implements ConfigurationInterface public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('knpu_oauth2_client'); - $rootNode = method_exists($treeBuilder, 'getRootNode') - ? $treeBuilder->getRootNode() - : $treeBuilder->root('knpu_oauth2_client'); + $rootNode = $treeBuilder->getRootNode(); $rootNode ->children() diff --git a/src/DependencyInjection/KnpUOAuth2ClientExtension.php b/src/DependencyInjection/KnpUOAuth2ClientExtension.php index 7d3f988a..6c95e907 100644 --- a/src/DependencyInjection/KnpUOAuth2ClientExtension.php +++ b/src/DependencyInjection/KnpUOAuth2ClientExtension.php @@ -198,9 +198,7 @@ public function load(array $configs, ContainerBuilder $container): void // process the configuration $tree = new TreeBuilder('knpu_oauth2_client/clients/'.$key); - $node = method_exists($tree, 'getRootNode') - ? $tree->getRootNode() - : $tree->root('knpu_oauth2_client/clients/'.$key); + $node = $tree->getRootNode(); $this->buildConfigurationForType($node, $type); $processor = new Processor(); diff --git a/src/Security/User/OAuthUserProvider.php b/src/Security/User/OAuthUserProvider.php index fdd24c50..d909b600 100644 --- a/src/Security/User/OAuthUserProvider.php +++ b/src/Security/User/OAuthUserProvider.php @@ -36,7 +36,7 @@ public function loadUserByIdentifier(string $identifier): UserInterface public function refreshUser(UserInterface $user): UserInterface { if (!$user instanceof OAuthUser) { - throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user))); + throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $user::class)); } return $this->loadUserByUsername(