From fa368ed022d44f5bc8f8c0718b5025b36575d0df Mon Sep 17 00:00:00 2001 From: David Maicher Date: Mon, 2 Aug 2021 19:46:29 +0200 Subject: [PATCH] bump to phpstan level 3 --- OAuth/Response/LinkedinUserResponse.php | 4 +++- OAuth/Response/SensioConnectUserResponse.php | 6 ++++-- OAuth/Response/UserResponseInterface.php | 2 +- Security/Core/Authentication/Token/AbstractOAuthToken.php | 2 +- Security/Http/Authenticator/OAuthAuthenticator.php | 8 ++++---- Tests/Controller/LoginControllerTest.php | 4 ++-- Tests/DependencyInjection/HWIOAuthExtensionTest.php | 1 - Tests/Fixtures/OAuthAwareException.php | 4 +++- .../ResourceOwner/GenericOAuth2ResourceOwnerTest.php | 3 ++- phpstan.neon | 2 +- 10 files changed, 21 insertions(+), 15 deletions(-) diff --git a/OAuth/Response/LinkedinUserResponse.php b/OAuth/Response/LinkedinUserResponse.php index 347ccbb42..c491125ec 100644 --- a/OAuth/Response/LinkedinUserResponse.php +++ b/OAuth/Response/LinkedinUserResponse.php @@ -40,7 +40,8 @@ public function getProfilePicture() // https://docs.microsoft.com/en-us/linkedin/shared/references/v2/profile/profile-picture $profilePicture = $this->getValueForPath('profilepicture'); if ( - !isset($profilePicture['displayImage~']) + !is_array($profilePicture) + || !isset($profilePicture['displayImage~']) || !isset($profilePicture['displayImage~']['elements']) || 0 == \count($profilePicture['displayImage~']['elements']) ) { @@ -68,6 +69,7 @@ public function getProfilePicture() */ protected function getPreferredLocaleValue($path) { + /** @var array $multiLocaleString */ $multiLocaleString = $this->getValueForPath($path); $locale = ''; diff --git a/OAuth/Response/SensioConnectUserResponse.php b/OAuth/Response/SensioConnectUserResponse.php index b0e925ae4..335a2cbfb 100644 --- a/OAuth/Response/SensioConnectUserResponse.php +++ b/OAuth/Response/SensioConnectUserResponse.php @@ -123,7 +123,10 @@ public function setData($data) throw new AuthenticationException('Could not retrieve user info.'); } - $this->data = $user->item(0); + /** @var \DOMElement $userElement */ + $userElement = $user->item(0); + + $this->data = $userElement; } /** @@ -143,7 +146,6 @@ protected function getNodeValue($query, \DOMElement $element, $nodeType = 'norma $attribute = $node->attributes->getNamedItem('href'); $nodeValue = $attribute->value; break; - case 'normal': default: $nodeValue = $node->nodeValue; diff --git a/OAuth/Response/UserResponseInterface.php b/OAuth/Response/UserResponseInterface.php index 203b10e21..4314bcde2 100644 --- a/OAuth/Response/UserResponseInterface.php +++ b/OAuth/Response/UserResponseInterface.php @@ -98,7 +98,7 @@ public function getTokenSecret(); /** * Get the info when token will expire. * - * @return string|null + * @return int|null */ public function getExpiresIn(); diff --git a/Security/Core/Authentication/Token/AbstractOAuthToken.php b/Security/Core/Authentication/Token/AbstractOAuthToken.php index a5cf6c2f5..51da1243b 100644 --- a/Security/Core/Authentication/Token/AbstractOAuthToken.php +++ b/Security/Core/Authentication/Token/AbstractOAuthToken.php @@ -231,7 +231,7 @@ public function getCreatedAt() } /** - * @return int + * @return int|null */ public function getExpiresAt() { diff --git a/Security/Http/Authenticator/OAuthAuthenticator.php b/Security/Http/Authenticator/OAuthAuthenticator.php index 3e64a7f0b..196f93a09 100644 --- a/Security/Http/Authenticator/OAuthAuthenticator.php +++ b/Security/Http/Authenticator/OAuthAuthenticator.php @@ -70,22 +70,22 @@ final class OAuthAuthenticator implements AuthenticatorInterface private $failureHandler; /** - * @var mixed[] + * @var mixed[]|null */ private $rawToken; /** - * @var string + * @var string|null */ private $resourceOwnerName; /** - * @var string + * @var string|null */ private $refreshToken; /** - * @var string + * @var int|null */ private $createdAt; diff --git a/Tests/Controller/LoginControllerTest.php b/Tests/Controller/LoginControllerTest.php index c662b3498..be0170ec9 100644 --- a/Tests/Controller/LoginControllerTest.php +++ b/Tests/Controller/LoginControllerTest.php @@ -15,7 +15,7 @@ use HWI\Bundle\OAuthBundle\Security\Core\Exception\AccountNotLinkedException; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag; +use Symfony\Component\HttpFoundation\ParameterBag; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\HttpFoundation\Session\SessionInterface; @@ -45,7 +45,7 @@ class LoginControllerTest extends TestCase private $router; /** - * @var MockObject&AuthenticationUtils + * @var AuthenticationUtils */ private $authenticationUtils; diff --git a/Tests/DependencyInjection/HWIOAuthExtensionTest.php b/Tests/DependencyInjection/HWIOAuthExtensionTest.php index 98c6f3567..827b57d5f 100644 --- a/Tests/DependencyInjection/HWIOAuthExtensionTest.php +++ b/Tests/DependencyInjection/HWIOAuthExtensionTest.php @@ -44,7 +44,6 @@ protected function setUp(): void protected function tearDown(): void { - $this->containerBuilder = null; unset($this->containerBuilder); } diff --git a/Tests/Fixtures/OAuthAwareException.php b/Tests/Fixtures/OAuthAwareException.php index 4569be0ca..3b5bb5bc0 100644 --- a/Tests/Fixtures/OAuthAwareException.php +++ b/Tests/Fixtures/OAuthAwareException.php @@ -56,7 +56,7 @@ public function getExpiresIn() } /** - * @return OAuthToken + * {@inheritdoc} */ public function getRawToken() { @@ -88,6 +88,8 @@ public function setResourceOwnerName($resourceOwnerName) } /** + * @param OAuthToken $token + * * {@inheritdoc} */ public function setToken(TokenInterface $token) diff --git a/Tests/OAuth/ResourceOwner/GenericOAuth2ResourceOwnerTest.php b/Tests/OAuth/ResourceOwner/GenericOAuth2ResourceOwnerTest.php index e884074a0..ea1f0ec51 100644 --- a/Tests/OAuth/ResourceOwner/GenericOAuth2ResourceOwnerTest.php +++ b/Tests/OAuth/ResourceOwner/GenericOAuth2ResourceOwnerTest.php @@ -408,10 +408,11 @@ protected function getExpectedAuthorizationUrlWithState($stateParameter) * * @throws \ReflectionException * - * @return ResourceOwnerInterface + * @return GenericOAuth2ResourceOwner */ protected function createResourceOwner(string $name, array $options = [], array $paths = [], ?StateInterface $state = null) { + /** @var GenericOAuth2ResourceOwner $resourceOwner */ $resourceOwner = parent::createResourceOwner($name, $options, $paths); $reflection = new \ReflectionClass(\get_class($resourceOwner)); diff --git a/phpstan.neon b/phpstan.neon index 47c1b5c68..98f5cc547 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ parameters: - level: 2 + level: 3 paths: - . excludePaths: