diff --git a/.flintci.yml b/.flintci.yml index c1909882..2d574a28 100644 --- a/.flintci.yml +++ b/.flintci.yml @@ -1,3 +1,3 @@ services: phpcsfixer: - version: 1 + version: 2 diff --git a/.gitignore b/.gitignore index 1871506b..7ea123c7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /composer.lock /vendor/* /tests/app/cache +/.php_cs.cache diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 202bf6be..00000000 --- a/.php_cs +++ /dev/null @@ -1,38 +0,0 @@ - - -For the full copyright and license information, please view the LICENSE -file that was distributed with this source code. -EOF -); - -return Symfony\CS\Config::create() - ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) - ->fixers([ - '-psr0', - '-phpdoc_params', - '-phpdoc_separation', - '-phpdoc_var_without_name', - '-return', - 'concat_with_spaces', - 'header_comment', - 'newline_after_open_tag', - 'short_array_syntax', - 'strict_param', - ]) - ->finder( - Symfony\CS\Finder::create() - ->files() - ->name('*.php') - ->in(__DIR__ . '/src') - ->in(__DIR__ . '/tests') - ->exclude('tests/app/cache') - ) - ; \ No newline at end of file diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 00000000..49522e1b --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,30 @@ +in(__DIR__.'/src') +; + +return PhpCsFixer\Config::create() + ->setRules(array( + '@Symfony' => true, + '@Symfony:risky' => true, + 'array_syntax' => ['syntax' => 'short'], + 'protected_to_private' => false, + 'semicolon_after_instruction' => false, + 'header_comment' => [ + 'header' => << + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. +EOF + ] + )) + ->setRiskyAllowed(true) + ->setFinder($finder) +; diff --git a/.travis.yml b/.travis.yml index e2d58b14..2fb06e8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,4 +27,4 @@ install: composer update --prefer-dist $COMPOSER_FLAGS # Fail CI if repo is in dirty state after bin/update_readme before_script: ./bin/update_readme && git diff --exit-code README.md -script: ./vendor/bin/phpunit +script: ./vendor/bin/simple-phpunit diff --git a/composer.json b/composer.json index 98dd551b..b462d42a 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,8 @@ "symfony/dependency-injection": "^3.4|^4.0", "symfony/routing": "^3.4|^4.0", "symfony/http-foundation": "^3.4|^4.0", - "league/oauth2-client": "^1.0|^2.0" + "league/oauth2-client": "^1.0|^2.0", + "symfony/phpunit-bridge": "^4.3" }, "autoload": { "psr-4": { "KnpU\\OAuth2ClientBundle\\": "src/" } @@ -27,9 +28,9 @@ }, "require-dev": { "league/oauth2-facebook": "^1.1|^2.0", - "phpunit/phpunit": "^7.5", "symfony/security-guard": "^3.4|^4.0", - "symfony/yaml": "^3.4|^4.0" + "symfony/yaml": "^3.4|^4.0", + "phpspec/prophecy": "^1.8" }, "suggest": { "symfony/security-guard": "For integration with Symfony's Guard Security layer" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b066350c..3f0831ce 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -11,6 +11,7 @@ + diff --git a/src/Client/ClientRegistry.php b/src/Client/ClientRegistry.php index 65e2130d..da04b47d 100644 --- a/src/Client/ClientRegistry.php +++ b/src/Client/ClientRegistry.php @@ -24,7 +24,7 @@ class ClientRegistry * ClientRegistry constructor. * * @param ContainerInterface $container - * @param array $serviceMap + * @param array $serviceMap */ public function __construct(ContainerInterface $container, array $serviceMap) { @@ -36,6 +36,7 @@ public function __construct(ContainerInterface $container, array $serviceMap) * Easy accessor for client objects. * * @param string $key + * * @return OAuth2Client */ public function getClient($key) diff --git a/src/Client/OAuth2Client.php b/src/Client/OAuth2Client.php index 62125d7b..628941b8 100644 --- a/src/Client/OAuth2Client.php +++ b/src/Client/OAuth2Client.php @@ -35,7 +35,7 @@ class OAuth2Client implements OAuth2ClientInterface * OAuth2Client constructor. * * @param AbstractProvider $provider - * @param RequestStack $requestStack + * @param RequestStack $requestStack */ public function __construct(AbstractProvider $provider, RequestStack $requestStack) { @@ -57,6 +57,7 @@ public function setAsStateless() * * @param array $scopes The scopes you want (leave empty to use default) * @param array $options Extra options to pass to the "Provider" class + * * @return RedirectResponse */ public function redirect(array $scopes = [], array $options = []) @@ -85,7 +86,7 @@ public function redirect(array $scopes = [], array $options = []) * * @throws InvalidStateException * @throws MissingAuthorizationCodeException - * @throws IdentityProviderException If token cannot be fetched + * @throws IdentityProviderException If token cannot be fetched */ public function getAccessToken() { @@ -112,6 +113,7 @@ public function getAccessToken() * Returns the "User" information (called a resource owner). * * @param AccessToken $accessToken + * * @return \League\OAuth2\Client\Provider\ResourceOwnerInterface */ public function fetchUserFromToken(AccessToken $accessToken) @@ -159,7 +161,7 @@ private function getCurrentRequest() } /** - * @return null|\Symfony\Component\HttpFoundation\Session\SessionInterface + * @return \Symfony\Component\HttpFoundation\Session\SessionInterface|null */ private function getSession() { diff --git a/src/Client/OAuth2ClientInterface.php b/src/Client/OAuth2ClientInterface.php index 53c1ddda..7d060c62 100644 --- a/src/Client/OAuth2ClientInterface.php +++ b/src/Client/OAuth2ClientInterface.php @@ -25,6 +25,7 @@ public function setAsStateless(); * * @param array $scopes The scopes you want (leave empty to use default) * @param array $options Extra options to pass to the "Provider" class + * * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function redirect(array $scopes, array $options); @@ -36,7 +37,7 @@ public function redirect(array $scopes, array $options); * * @throws \KnpU\OAuth2ClientBundle\Exception\InvalidStateException * @throws \KnpU\OAuth2ClientBundle\Exception\MissingAuthorizationCodeException - * @throws \League\OAuth2\Client\Provider\Exception\IdentityProviderException If token cannot be fetched + * @throws \League\OAuth2\Client\Provider\Exception\IdentityProviderException If token cannot be fetched */ public function getAccessToken(); @@ -44,6 +45,7 @@ public function getAccessToken(); * Returns the "User" information (called a resource owner). * * @param AccessToken $accessToken + * * @return \League\OAuth2\Client\Provider\ResourceOwnerInterface */ public function fetchUserFromToken(AccessToken $accessToken); diff --git a/src/Client/Provider/AmazonClient.php b/src/Client/Provider/AmazonClient.php index 6a973185..ea06cdc7 100644 --- a/src/Client/Provider/AmazonClient.php +++ b/src/Client/Provider/AmazonClient.php @@ -18,6 +18,7 @@ class AmazonClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return AmazonResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/Auth0Client.php b/src/Client/Provider/Auth0Client.php index b1a9620e..33f42ffe 100644 --- a/src/Client/Provider/Auth0Client.php +++ b/src/Client/Provider/Auth0Client.php @@ -18,6 +18,7 @@ class Auth0Client extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return Auth0ResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/AzureClient.php b/src/Client/Provider/AzureClient.php index 6d6ed5fe..42e67b0f 100644 --- a/src/Client/Provider/AzureClient.php +++ b/src/Client/Provider/AzureClient.php @@ -18,6 +18,7 @@ class AzureClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return AzureResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/BitbucketClient.php b/src/Client/Provider/BitbucketClient.php index 73703983..6ce08492 100644 --- a/src/Client/Provider/BitbucketClient.php +++ b/src/Client/Provider/BitbucketClient.php @@ -18,6 +18,7 @@ class BitbucketClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return BitbucketResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/BoxClient.php b/src/Client/Provider/BoxClient.php index e2f41e46..59927324 100644 --- a/src/Client/Provider/BoxClient.php +++ b/src/Client/Provider/BoxClient.php @@ -18,6 +18,7 @@ class BoxClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return BoxResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/BufferClient.php b/src/Client/Provider/BufferClient.php index b19c9141..a1341017 100644 --- a/src/Client/Provider/BufferClient.php +++ b/src/Client/Provider/BufferClient.php @@ -18,6 +18,7 @@ class BufferClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return BufferUser */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/CanvasLMSClient.php b/src/Client/Provider/CanvasLMSClient.php index 401ea204..00d84653 100644 --- a/src/Client/Provider/CanvasLMSClient.php +++ b/src/Client/Provider/CanvasLMSClient.php @@ -18,6 +18,7 @@ class CanvasLMSClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return CanvasLMSResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/CleverClient.php b/src/Client/Provider/CleverClient.php index c0229bfd..1ec36fae 100644 --- a/src/Client/Provider/CleverClient.php +++ b/src/Client/Provider/CleverClient.php @@ -18,6 +18,7 @@ class CleverClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return CleverUser */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/DevianArtClient.php b/src/Client/Provider/DevianArtClient.php index 5e390c21..a1b6d325 100644 --- a/src/Client/Provider/DevianArtClient.php +++ b/src/Client/Provider/DevianArtClient.php @@ -18,6 +18,7 @@ class DevianArtClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return DeviantArtResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/DigitalOceanClient.php b/src/Client/Provider/DigitalOceanClient.php index 68f386fb..c3f52c6d 100644 --- a/src/Client/Provider/DigitalOceanClient.php +++ b/src/Client/Provider/DigitalOceanClient.php @@ -18,6 +18,7 @@ class DigitalOceanClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return DigitalOceanResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/DiscordClient.php b/src/Client/Provider/DiscordClient.php index 8b3e00ec..82ec3ecb 100644 --- a/src/Client/Provider/DiscordClient.php +++ b/src/Client/Provider/DiscordClient.php @@ -18,6 +18,7 @@ class DiscordClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return DiscordResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/DribbbleClient.php b/src/Client/Provider/DribbbleClient.php index f77e8ea1..2702c694 100644 --- a/src/Client/Provider/DribbbleClient.php +++ b/src/Client/Provider/DribbbleClient.php @@ -18,6 +18,7 @@ class DribbbleClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return DribbbleResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/DropboxClient.php b/src/Client/Provider/DropboxClient.php index 2db27a33..c3e1a589 100644 --- a/src/Client/Provider/DropboxClient.php +++ b/src/Client/Provider/DropboxClient.php @@ -18,6 +18,7 @@ class DropboxClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return DropboxResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/DrupalClient.php b/src/Client/Provider/DrupalClient.php index 99526498..da5ce0c2 100644 --- a/src/Client/Provider/DrupalClient.php +++ b/src/Client/Provider/DrupalClient.php @@ -18,6 +18,7 @@ class DrupalClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return DrupalResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/ElanceClient.php b/src/Client/Provider/ElanceClient.php index 85cbfb71..dccc8fdc 100644 --- a/src/Client/Provider/ElanceClient.php +++ b/src/Client/Provider/ElanceClient.php @@ -18,6 +18,7 @@ class ElanceClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return ElanceResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/EveOnlineClient.php b/src/Client/Provider/EveOnlineClient.php index da7e1906..d234e3fd 100644 --- a/src/Client/Provider/EveOnlineClient.php +++ b/src/Client/Provider/EveOnlineClient.php @@ -18,6 +18,7 @@ class EveOnlineClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return EveOnlineResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/EventbriteClient.php b/src/Client/Provider/EventbriteClient.php index 9d024294..f1464f19 100644 --- a/src/Client/Provider/EventbriteClient.php +++ b/src/Client/Provider/EventbriteClient.php @@ -18,6 +18,7 @@ class EventbriteClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return EventbriteResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/FacebookClient.php b/src/Client/Provider/FacebookClient.php index 2d99bcf8..9b6a4c64 100644 --- a/src/Client/Provider/FacebookClient.php +++ b/src/Client/Provider/FacebookClient.php @@ -18,6 +18,7 @@ class FacebookClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return FacebookUser */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/FitbitClient.php b/src/Client/Provider/FitbitClient.php index b8f3a5c4..fdfdacbf 100644 --- a/src/Client/Provider/FitbitClient.php +++ b/src/Client/Provider/FitbitClient.php @@ -18,6 +18,7 @@ class FitbitClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return FitbitUser */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/FoursquareClient.php b/src/Client/Provider/FoursquareClient.php index 3c110f5e..c9fae930 100644 --- a/src/Client/Provider/FoursquareClient.php +++ b/src/Client/Provider/FoursquareClient.php @@ -18,6 +18,7 @@ class FoursquareClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return FoursquareResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/GeocachingClient.php b/src/Client/Provider/GeocachingClient.php index e8eb701f..f36d1bf0 100644 --- a/src/Client/Provider/GeocachingClient.php +++ b/src/Client/Provider/GeocachingClient.php @@ -18,6 +18,7 @@ class GeocachingClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return GeocachingResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/GithubClient.php b/src/Client/Provider/GithubClient.php index eb8e8f8d..26abe273 100644 --- a/src/Client/Provider/GithubClient.php +++ b/src/Client/Provider/GithubClient.php @@ -18,6 +18,7 @@ class GithubClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return GithubResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/GitlabClient.php b/src/Client/Provider/GitlabClient.php index f0ae2814..c5b43c9e 100644 --- a/src/Client/Provider/GitlabClient.php +++ b/src/Client/Provider/GitlabClient.php @@ -23,6 +23,7 @@ class GitlabClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return GitlabResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/GoogleClient.php b/src/Client/Provider/GoogleClient.php index f8117dea..65035e37 100644 --- a/src/Client/Provider/GoogleClient.php +++ b/src/Client/Provider/GoogleClient.php @@ -18,6 +18,7 @@ class GoogleClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return GoogleUser */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/HeadHunterClient.php b/src/Client/Provider/HeadHunterClient.php index 16dcab1f..ec0adc55 100644 --- a/src/Client/Provider/HeadHunterClient.php +++ b/src/Client/Provider/HeadHunterClient.php @@ -18,6 +18,7 @@ class HeadHunterClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return HeadHunterResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/HerokuClient.php b/src/Client/Provider/HerokuClient.php index c7aa061b..faeaa194 100644 --- a/src/Client/Provider/HerokuClient.php +++ b/src/Client/Provider/HerokuClient.php @@ -18,6 +18,7 @@ class HerokuClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return HerokuResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/InstagramClient.php b/src/Client/Provider/InstagramClient.php index deb66655..5d365463 100644 --- a/src/Client/Provider/InstagramClient.php +++ b/src/Client/Provider/InstagramClient.php @@ -18,6 +18,7 @@ class InstagramClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return InstagramResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/JiraClient.php b/src/Client/Provider/JiraClient.php index fa4b0cdf..2a43d531 100644 --- a/src/Client/Provider/JiraClient.php +++ b/src/Client/Provider/JiraClient.php @@ -18,6 +18,7 @@ class JiraClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return JiraResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/KeycloakClient.php b/src/Client/Provider/KeycloakClient.php index b0f1bbf4..c2a556a2 100644 --- a/src/Client/Provider/KeycloakClient.php +++ b/src/Client/Provider/KeycloakClient.php @@ -18,6 +18,7 @@ class KeycloakClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return KeycloakResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/LinkedInClient.php b/src/Client/Provider/LinkedInClient.php index 68877c38..0587e604 100644 --- a/src/Client/Provider/LinkedInClient.php +++ b/src/Client/Provider/LinkedInClient.php @@ -18,6 +18,7 @@ class LinkedInClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return LinkedInResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/MailRuClient.php b/src/Client/Provider/MailRuClient.php index 7476eebf..5ea7cc25 100644 --- a/src/Client/Provider/MailRuClient.php +++ b/src/Client/Provider/MailRuClient.php @@ -18,6 +18,7 @@ class MailRuClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return MailruResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/MicrosoftClient.php b/src/Client/Provider/MicrosoftClient.php index f7a64dfe..0dfaa637 100644 --- a/src/Client/Provider/MicrosoftClient.php +++ b/src/Client/Provider/MicrosoftClient.php @@ -18,6 +18,7 @@ class MicrosoftClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return MicrosoftResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/MollieClient.php b/src/Client/Provider/MollieClient.php index 690605b0..e739d83f 100644 --- a/src/Client/Provider/MollieClient.php +++ b/src/Client/Provider/MollieClient.php @@ -18,6 +18,7 @@ class MollieClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return MollieResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/OdnoklassnikiClient.php b/src/Client/Provider/OdnoklassnikiClient.php index cb5ef385..0c208ac4 100644 --- a/src/Client/Provider/OdnoklassnikiClient.php +++ b/src/Client/Provider/OdnoklassnikiClient.php @@ -18,6 +18,7 @@ class OdnoklassnikiClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return OdnoklassnikiResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/PaypalClient.php b/src/Client/Provider/PaypalClient.php index d68b6d7b..853958a0 100644 --- a/src/Client/Provider/PaypalClient.php +++ b/src/Client/Provider/PaypalClient.php @@ -18,6 +18,7 @@ class PaypalClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return PaypalResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/PsnClient.php b/src/Client/Provider/PsnClient.php index e2374c71..2d046043 100644 --- a/src/Client/Provider/PsnClient.php +++ b/src/Client/Provider/PsnClient.php @@ -18,6 +18,7 @@ class PsnClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return PsnResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/SalesforceClient.php b/src/Client/Provider/SalesforceClient.php index 0a397e60..efa90002 100644 --- a/src/Client/Provider/SalesforceClient.php +++ b/src/Client/Provider/SalesforceClient.php @@ -18,6 +18,7 @@ class SalesforceClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return SalesforceResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/SlackClient.php b/src/Client/Provider/SlackClient.php index aa355639..627eb679 100644 --- a/src/Client/Provider/SlackClient.php +++ b/src/Client/Provider/SlackClient.php @@ -18,6 +18,7 @@ class SlackClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return SlackResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/StravaClient.php b/src/Client/Provider/StravaClient.php index bf7c5108..29ecd4b2 100644 --- a/src/Client/Provider/StravaClient.php +++ b/src/Client/Provider/StravaClient.php @@ -18,6 +18,7 @@ class StravaClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return StravaResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/StripeClient.php b/src/Client/Provider/StripeClient.php index abb7b193..d8824dd8 100644 --- a/src/Client/Provider/StripeClient.php +++ b/src/Client/Provider/StripeClient.php @@ -18,6 +18,7 @@ class StripeClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return StripeResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/UberClient.php b/src/Client/Provider/UberClient.php index e58a3b2a..3f4a794b 100644 --- a/src/Client/Provider/UberClient.php +++ b/src/Client/Provider/UberClient.php @@ -18,6 +18,7 @@ class UberClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return UberResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/UnsplashClient.php b/src/Client/Provider/UnsplashClient.php index 858b7397..a5687d1a 100644 --- a/src/Client/Provider/UnsplashClient.php +++ b/src/Client/Provider/UnsplashClient.php @@ -18,6 +18,7 @@ class UnsplashClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return UnsplashResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/VKontakteClient.php b/src/Client/Provider/VKontakteClient.php index 66bde58b..57d18057 100644 --- a/src/Client/Provider/VKontakteClient.php +++ b/src/Client/Provider/VKontakteClient.php @@ -18,6 +18,7 @@ class VKontakteClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return User */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/VimeoClient.php b/src/Client/Provider/VimeoClient.php index 37f8c0ed..25412d2b 100644 --- a/src/Client/Provider/VimeoClient.php +++ b/src/Client/Provider/VimeoClient.php @@ -18,6 +18,7 @@ class VimeoClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return VimeoResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/YahooClient.php b/src/Client/Provider/YahooClient.php index 5b3b840d..4a4388d8 100644 --- a/src/Client/Provider/YahooClient.php +++ b/src/Client/Provider/YahooClient.php @@ -18,6 +18,7 @@ class YahooClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return YahooUser */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/YandexClient.php b/src/Client/Provider/YandexClient.php index 7e03ba2b..40e7acb0 100644 --- a/src/Client/Provider/YandexClient.php +++ b/src/Client/Provider/YandexClient.php @@ -18,6 +18,7 @@ class YandexClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return YandexResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/Client/Provider/ZendeskClient.php b/src/Client/Provider/ZendeskClient.php index 0158d79d..7d1ccd4c 100644 --- a/src/Client/Provider/ZendeskClient.php +++ b/src/Client/Provider/ZendeskClient.php @@ -18,6 +18,7 @@ class ZendeskClient extends OAuth2Client { /** * @param AccessToken $accessToken + * * @return ZendeskResourceOwner */ public function fetchUserFromToken(AccessToken $accessToken) diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 6207d362..b114662b 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -15,7 +15,7 @@ class Configuration implements ConfigurationInterface { - public function getConfigTreeBuilder() + public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('knpu_oauth2_client'); $rootNode = method_exists($treeBuilder, 'getRootNode') diff --git a/src/DependencyInjection/KnpUOAuth2ClientExtension.php b/src/DependencyInjection/KnpUOAuth2ClientExtension.php index 44fc8da2..e296a310 100644 --- a/src/DependencyInjection/KnpUOAuth2ClientExtension.php +++ b/src/DependencyInjection/KnpUOAuth2ClientExtension.php @@ -146,7 +146,7 @@ public function __construct($checkExternalClassExistence = true) /** * Load the bundle configuration. * - * @param array $configs + * @param array $configs * @param ContainerBuilder $container */ public function load(array $configs, ContainerBuilder $container) @@ -155,7 +155,7 @@ public function load(array $configs, ContainerBuilder $container) $configuration = new Configuration(); $config = $processor->processConfiguration($configuration, $configs); - $loader = new XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); + $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.xml'); $httpClient = $config['http_client']; @@ -183,10 +183,10 @@ public function load(array $configs, ContainerBuilder $container) } // process the configuration - $tree = new TreeBuilder('knpu_oauth2_client/clients/' . $key); + $tree = new TreeBuilder('knpu_oauth2_client/clients/'.$key); $node = method_exists($tree, 'getRootNode') ? $tree->getRootNode() - : $tree->root('knpu_oauth2_client/clients/' . $key); + : $tree->root('knpu_oauth2_client/clients/'.$key); $this->buildConfigurationForType($node, $type); $processor = new Processor(); @@ -226,16 +226,17 @@ public function load(array $configs, ContainerBuilder $container) /** * @param ContainerBuilder $container - * @param string $providerType The "type" used in the config - e.g. "facebook" - * @param string $providerKey The config key used for this - e.g. "facebook_client", "my_facebook" - * @param string $providerClass Provider class - * @param string $clientClass Class to use for the Client - * @param string $packageName Packagist package name required - * @param array $options Options passed to when constructing the provider - * @param string $redirectRoute Route name for the redirect URL - * @param array $redirectParams Route params for the redirect URL - * @param bool $useState - * @param array $collaborators + * @param string $providerType The "type" used in the config - e.g. "facebook" + * @param string $providerKey The config key used for this - e.g. "facebook_client", "my_facebook" + * @param string $providerClass Provider class + * @param string $clientClass Class to use for the Client + * @param string $packageName Packagist package name required + * @param array $options Options passed to when constructing the provider + * @param string $redirectRoute Route name for the redirect URL + * @param array $redirectParams Route params for the redirect URL + * @param bool $useState + * @param array $collaborators + * * @return string The client service id */ private function configureProviderAndClient(ContainerBuilder $container, $providerType, $providerKey, $providerClass, $clientClass, $packageName, array $options, $redirectRoute, array $redirectParams, $useState, array $collaborators) @@ -286,7 +287,7 @@ private function configureProviderAndClient(ContainerBuilder $container, $provid } // add an alias, but only if a provider type is used only 1 time - if (!in_array($providerType, $this->duplicateProviderTypes, true)) { + if (!\in_array($providerType, $this->duplicateProviderTypes, true)) { // alias already exists? This is a duplicate type, record it if ($container->hasAlias($clientClass)) { $this->duplicateProviderTypes[] = $providerType; @@ -304,20 +305,21 @@ public static function getAllSupportedTypes() return array_keys(self::$supportedProviderTypes); } - /** - * @param string $type - * @return ProviderConfiguratorInterface - */ - public function getConfigurator($type) - { - if (!isset($this->configurators[$type])) { - $class = self::$supportedProviderTypes[$type]; + /** + * @param string $type + * + * @return ProviderConfiguratorInterface + */ + public function getConfigurator($type) + { + if (!isset($this->configurators[$type])) { + $class = self::$supportedProviderTypes[$type]; - $this->configurators[$type] = new $class(); - } + $this->configurators[$type] = new $class(); + } - return $this->configurators[$type]; - } + return $this->configurators[$type]; + } /** * Overridden so the alias isn't "knp_uo_auth2_client". diff --git a/src/DependencyInjection/ProviderFactory.php b/src/DependencyInjection/ProviderFactory.php index cf019412..ae7438ac 100644 --- a/src/DependencyInjection/ProviderFactory.php +++ b/src/DependencyInjection/ProviderFactory.php @@ -36,10 +36,11 @@ public function __construct(UrlGeneratorInterface $generator) * Creates a provider of the given class. * * @param string $class - * @param array $options + * @param array $options * @param string $redirectUri - * @param array $redirectParams - * @param array $collaborators + * @param array $redirectParams + * @param array $collaborators + * * @return mixed */ public function createProvider($class, array $options, $redirectUri, array $redirectParams = [], array $collaborators = []) diff --git a/src/DependencyInjection/Providers/CanvasLMSProviderConfigurator.php b/src/DependencyInjection/Providers/CanvasLMSProviderConfigurator.php index c0130fa7..764bb424 100644 --- a/src/DependencyInjection/Providers/CanvasLMSProviderConfigurator.php +++ b/src/DependencyInjection/Providers/CanvasLMSProviderConfigurator.php @@ -25,7 +25,7 @@ public function buildConfiguration(NodeBuilder $node) ->defaultValue('') ->info( 'This can be used to help the user identify which instance of an application this token is ' - . 'for. For example, a mobile device application could provide the name of the device.' + .'for. For example, a mobile device application could provide the name of the device.' ) ->end() diff --git a/src/DependencyInjection/Providers/LinkedInProviderConfigurator.php b/src/DependencyInjection/Providers/LinkedInProviderConfigurator.php index 235ff2de..538c6f76 100644 --- a/src/DependencyInjection/Providers/LinkedInProviderConfigurator.php +++ b/src/DependencyInjection/Providers/LinkedInProviderConfigurator.php @@ -40,7 +40,7 @@ public function getProviderOptions(array $config) 'clientSecret' => $config['client_secret'], ]; - if (!is_null($config['api_version'])) { + if (null !== $config['api_version']) { $options['resourceOwnerVersion'] = $config['api_version']; } diff --git a/src/DependencyInjection/Providers/ProviderConfiguratorInterface.php b/src/DependencyInjection/Providers/ProviderConfiguratorInterface.php index 0c82e289..748e1203 100644 --- a/src/DependencyInjection/Providers/ProviderConfiguratorInterface.php +++ b/src/DependencyInjection/Providers/ProviderConfiguratorInterface.php @@ -24,6 +24,7 @@ public function buildConfiguration(NodeBuilder $node); /** * @param array $configuration + * * @return string */ public function getProviderClass(array $configuration); @@ -35,12 +36,14 @@ public function getProviderClass(array $configuration); * default to OAuth2Client. * * @param array $config + * * @return string */ public function getClientClass(array $config); /** * @param array $configuration + * * @return array */ public function getProviderOptions(array $configuration); diff --git a/src/Security/Authenticator/SocialAuthenticator.php b/src/Security/Authenticator/SocialAuthenticator.php index 931d9271..b10fabd9 100644 --- a/src/Security/Authenticator/SocialAuthenticator.php +++ b/src/Security/Authenticator/SocialAuthenticator.php @@ -42,13 +42,13 @@ protected function fetchAccessToken(OAuth2ClientInterface $client) } } - public function checkCredentials($credentials, UserInterface $user) + public function checkCredentials($credentials, UserInterface $user): bool { // do nothing - the fact that the access token works is enough return true; } - public function supportsRememberMe() + public function supportsRememberMe(): bool { return true; } diff --git a/src/Security/Exception/FinishRegistrationException.php b/src/Security/Exception/FinishRegistrationException.php index e261ba80..eebd57ce 100644 --- a/src/Security/Exception/FinishRegistrationException.php +++ b/src/Security/Exception/FinishRegistrationException.php @@ -21,9 +21,9 @@ class FinishRegistrationException extends AuthenticationException private $userInformation; /** - * @param mixed $userInfo Any info to be used to help registration - * @param string $message - * @param int $code + * @param mixed $userInfo Any info to be used to help registration + * @param string $message + * @param int $code * @param \Exception $previous */ public function __construct($userInfo, $message = '', $code = 0, Exception $previous = null) @@ -45,7 +45,7 @@ public function getUserInformation() * this message is shown to your user, then you're missing * this piece of your code. */ - public function getMessageKey() + public function getMessageKey(): string { return 'You need to finish registration to login.'; } diff --git a/src/Security/Exception/IdentityProviderAuthenticationException.php b/src/Security/Exception/IdentityProviderAuthenticationException.php index 1cc78e8d..7da243db 100644 --- a/src/Security/Exception/IdentityProviderAuthenticationException.php +++ b/src/Security/Exception/IdentityProviderAuthenticationException.php @@ -23,7 +23,7 @@ public function __construct(IdentityProviderException $e) parent::__construct($e->getMessage(), $e->getCode(), $e); } - public function getMessageKey() + public function getMessageKey(): string { return 'Error fetching OAuth credentials: "%error%".'; } diff --git a/src/Security/Exception/InvalidStateAuthenticationException.php b/src/Security/Exception/InvalidStateAuthenticationException.php index b849a130..22512a77 100644 --- a/src/Security/Exception/InvalidStateAuthenticationException.php +++ b/src/Security/Exception/InvalidStateAuthenticationException.php @@ -23,7 +23,7 @@ public function __construct(InvalidStateException $e) parent::__construct($e->getMessage(), $e->getCode(), $e); } - public function getMessageKey() + public function getMessageKey(): string { return 'Invalid state parameter passed in callback URL.'; } diff --git a/src/Security/Exception/NoAuthCodeAuthenticationException.php b/src/Security/Exception/NoAuthCodeAuthenticationException.php index d5a39afe..72156b3e 100644 --- a/src/Security/Exception/NoAuthCodeAuthenticationException.php +++ b/src/Security/Exception/NoAuthCodeAuthenticationException.php @@ -20,7 +20,7 @@ */ class NoAuthCodeAuthenticationException extends AuthenticationException { - public function getMessageKey() + public function getMessageKey(): string { return 'Authentication failed! Did you authorize our app?'; } diff --git a/src/Security/Helper/FinishRegistrationBehavior.php b/src/Security/Helper/FinishRegistrationBehavior.php index 9853d761..e84a2c08 100644 --- a/src/Security/Helper/FinishRegistrationBehavior.php +++ b/src/Security/Helper/FinishRegistrationBehavior.php @@ -23,8 +23,9 @@ trait FinishRegistrationBehavior /** * Call this from within your onAuthenticationFailure() method. * - * @param Request $request + * @param Request $request * @param FinishRegistrationException $e + * * @return RedirectResponse */ protected function saveUserInfoToSession(Request $request, FinishRegistrationException $e) @@ -40,6 +41,7 @@ protected function saveUserInfoToSession(Request $request, FinishRegistrationExc * Useful during registration to get your user information back out. * * @param Request $request + * * @return mixed */ public function getUserInfoFromSession(Request $request) diff --git a/src/Security/Helper/PreviousUrlHelper.php b/src/Security/Helper/PreviousUrlHelper.php index 640c5449..56da8660 100644 --- a/src/Security/Helper/PreviousUrlHelper.php +++ b/src/Security/Helper/PreviousUrlHelper.php @@ -17,8 +17,8 @@ trait PreviousUrlHelper /** * Returns the URL (if any) the user visited that forced them to login. * - * @param Request $request - * @param string $providerKey + * @param Request $request + * @param string $providerKey * * @return string */ @@ -26,6 +26,6 @@ public function getPreviousUrl(Request $request, $providerKey) { // if the user hit a secure page and start() was called, this was // the URL they were on, and probably where you want to redirect to - return $request->getSession()->get('_security.' . $providerKey . '.target_path'); + return $request->getSession()->get('_security.'.$providerKey.'.target_path'); } } diff --git a/src/Security/User/OAuthUser.php b/src/Security/User/OAuthUser.php index 79249978..305531d8 100644 --- a/src/Security/User/OAuthUser.php +++ b/src/Security/User/OAuthUser.php @@ -28,17 +28,17 @@ public function getRoles() return $this->roles; } - public function getPassword() + public function getPassword(): ?string { return ''; } - public function getSalt() + public function getSalt(): ?string { return null; } - public function getUsername() + public function getUsername(): string { return $this->username; } diff --git a/src/Security/User/OAuthUserProvider.php b/src/Security/User/OAuthUserProvider.php index fffba96e..44156037 100644 --- a/src/Security/User/OAuthUserProvider.php +++ b/src/Security/User/OAuthUserProvider.php @@ -23,21 +23,21 @@ public function __construct(array $roles = ['ROLE_USER', 'ROLE_OAUTH_USER']) $this->roles = $roles; } - public function loadUserByUsername($username) + public function loadUserByUsername($username): UserInterface { return new OAuthUser($username, $this->roles); } - public function refreshUser(UserInterface $user) + 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.', \get_class($user))); } return $this->loadUserByUsername($user->getUsername()); } - public function supportsClass($class) + public function supportsClass($class): bool { return OAuthUser::class === $class; } diff --git a/tests/Client/OAuth2ClientTest.php b/tests/Client/OAuth2ClientTest.php index 611ed957..6809ceb1 100644 --- a/tests/Client/OAuth2ClientTest.php +++ b/tests/Client/OAuth2ClientTest.php @@ -11,6 +11,8 @@ namespace KnpU\OAuth2ClientBundle\tests\Client; use KnpU\OAuth2ClientBundle\Client\OAuth2Client; +use KnpU\OAuth2ClientBundle\Exception\InvalidStateException; +use KnpU\OAuth2ClientBundle\Exception\MissingAuthorizationCodeException; use League\OAuth2\Client\Provider\FacebookUser; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -24,7 +26,7 @@ class OAuth2ClientTest extends TestCase private $session; private $provider; - public function setup() + public function setup(): void { $this->requestStack = new RequestStack(); $this->session = $this->prophesize('Symfony\Component\HttpFoundation\Session\SessionInterface'); @@ -152,11 +154,9 @@ public function testGetAccessTokenFromPOST() $this->assertSame($expectedToken->reveal(), $actualToken); } - /** - * @expectedException \KnpU\OAuth2ClientBundle\Exception\InvalidStateException - */ public function testGetAccessTokenThrowsInvalidStateException() { + $this->expectException(InvalidStateException::class); $this->request->query->set('state', 'ACTUAL_STATE'); $this->session->get(OAuth2Client::OAUTH2_SESSION_STATE_KEY) ->willReturn('OTHER_STATE'); @@ -168,11 +168,9 @@ public function testGetAccessTokenThrowsInvalidStateException() $client->getAccessToken(); } - /** - * @expectedException \KnpU\OAuth2ClientBundle\Exception\MissingAuthorizationCodeException - */ public function testGetAccessTokenThrowsMissingAuthCodeException() { + $this->expectException(MissingAuthorizationCodeException::class); $this->request->query->set('state', 'ACTUAL_STATE'); $this->session->get(OAuth2Client::OAUTH2_SESSION_STATE_KEY) ->willReturn('ACTUAL_STATE'); diff --git a/tests/DependencyInjection/KnpUOAuth2ClientExtensionTest.php b/tests/DependencyInjection/KnpUOAuth2ClientExtensionTest.php index 5908f74d..5ec6834e 100644 --- a/tests/DependencyInjection/KnpUOAuth2ClientExtensionTest.php +++ b/tests/DependencyInjection/KnpUOAuth2ClientExtensionTest.php @@ -15,6 +15,8 @@ use Symfony\Component\Config\Definition\ArrayNode; use Symfony\Component\Config\Definition\BooleanNode; use Symfony\Component\Config\Definition\Builder\TreeBuilder; +use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; +use Symfony\Component\Config\Definition\IntegerNode; use Symfony\Component\Config\Definition\NodeInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; @@ -131,13 +133,14 @@ public function testAllClientsCreateDefinition($type, array $inputConfig) public function provideTypesAndConfig() { - $tests = []; $extension = new KnpUOAuth2ClientExtension(); foreach (KnpUOAuth2ClientExtension::getAllSupportedTypes() as $type) { $configurator = $extension->getConfigurator($type); - $tree = new TreeBuilder(); - $configNode = $tree->root('testing'); + $tree = new TreeBuilder('testing'); + $configNode = method_exists($tree, 'getRootNode') + ? $tree->getRootNode() + : $tree->root('testing'); $configurator->buildConfiguration($configNode->children(), $type); /** @var ArrayNode $arrayNode */ @@ -156,15 +159,15 @@ public function provideTypesAndConfig() $config[$child->getName()] = []; } elseif ($child instanceof BooleanNode) { $config[$child->getName()] = (bool) rand(0, 1); - } else { + } elseif ($child instanceof IntegerNode) { $config[$child->getName()] = rand(); + } else { + $config[$child->getName()] = 'random_'.rand(); } } - $tests[] = [$type, $config]; + yield $type => [$type, $config]; } - - return $tests; } public function testGenericProvider() @@ -224,11 +227,11 @@ public function testGenericProvider() } /** - * @expectedException \Symfony\Component\Config\Definition\Exception\InvalidConfigurationException * @dataProvider provideBadConfiguration */ public function testBadClientsConfiguration(array $badClientsConfig) { + $this->expectException(InvalidConfigurationException::class); $this->configuration = new ContainerBuilder(); $loader = new KnpUOAuth2ClientExtension(false); $config = ['clients' => $badClientsConfig]; @@ -291,7 +294,7 @@ public function testGetAlias() $this->assertEquals('knpu_oauth2_client', $extension->getAlias()); } - protected function tearDown() + protected function tearDown(): void { unset($this->configuration); } diff --git a/tests/Security/Authenticator/SocialAuthenticatorTest.php b/tests/Security/Authenticator/SocialAuthenticatorTest.php index e9505c19..ce4d252f 100644 --- a/tests/Security/Authenticator/SocialAuthenticatorTest.php +++ b/tests/Security/Authenticator/SocialAuthenticatorTest.php @@ -13,7 +13,9 @@ use KnpU\OAuth2ClientBundle\Exception\MissingAuthorizationCodeException; use KnpU\OAuth2ClientBundle\Security\Authenticator\SocialAuthenticator; use KnpU\OAuth2ClientBundle\Client\OAuth2Client; +use KnpU\OAuth2ClientBundle\Security\Exception\NoAuthCodeAuthenticationException; use Symfony\Component\HttpFoundation\Request; +use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; use Symfony\Component\Security\Core\Exception\AuthenticationException; use Symfony\Component\Security\Core\User\UserInterface; @@ -33,11 +35,9 @@ public function testFetchAccessTokenSimplyReturns() $this->assertEquals('expected_access_token', $actualToken); } - /** - * @expectedException \KnpU\OAuth2ClientBundle\Security\Exception\NoAuthCodeAuthenticationException - */ public function testFetchAccessTokenThrowsAuthenticationException() { + $this->expectException(NoAuthCodeAuthenticationException::class); $authenticator = new StubSocialAuthenticator(); $client = $this->prophesize('KnpU\OAuth2ClientBundle\Client\OAuth2Client'); $client->getAccessToken() @@ -67,22 +67,22 @@ public function doFetchAccessToken(OAuth2Client $client) return $this->fetchAccessToken($client); } - public function start(Request $request, AuthenticationException $authException = null) + public function start(Request $request, AuthenticationException $authException = null): Response { } - public function supports(Request $request) + public function supports(Request $request): bool { } public function getCredentials(Request $request) { } - public function getUser($credentials, UserProviderInterface $userProvider) + public function getUser($credentials, UserProviderInterface $userProvider): ?UserInterface { } - public function onAuthenticationFailure(Request $request, AuthenticationException $exception) + public function onAuthenticationFailure(Request $request, AuthenticationException $exception): ?Response { } - public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey) + public function onAuthenticationSuccess(Request $request, TokenInterface $token, $providerKey): ?Response { } } @@ -93,15 +93,15 @@ public function getRoles() { } - public function getPassword() + public function getPassword(): ?string { } - public function getSalt() + public function getSalt(): ?string { } - public function getUsername() + public function getUsername(): string { } diff --git a/tests/Security/Exception/FinishRegistrationExceptionTest.php b/tests/Security/Exception/FinishRegistrationExceptionTest.php index 69cde0d2..c95a38ed 100644 --- a/tests/Security/Exception/FinishRegistrationExceptionTest.php +++ b/tests/Security/Exception/FinishRegistrationExceptionTest.php @@ -24,6 +24,5 @@ public function testException() $e = new FinishRegistrationException($userInfo, '', 0); $this->assertEquals($e->getUserInformation(), $userInfo); - $this->assertInternalType('string', $e->getMessageKey()); } } diff --git a/tests/Security/Exception/NoAuthCodeAuthenticationExceptionTest.php b/tests/Security/Exception/NoAuthCodeAuthenticationExceptionTest.php index 91e345b0..88957d0b 100644 --- a/tests/Security/Exception/NoAuthCodeAuthenticationExceptionTest.php +++ b/tests/Security/Exception/NoAuthCodeAuthenticationExceptionTest.php @@ -22,6 +22,10 @@ public function testException() { $e = new NoAuthCodeAuthenticationException(); - $this->assertInternalType('string', $e->getMessageKey()); + if (method_exists($this, 'assertIsString')) { + $this->assertIsString($e->getMessageKey()); + } else { + $this->assertInternalType('string', $e->getMessageKey()); + } } } diff --git a/tests/Security/Helper/FinishRegistrationBehaviorTest.php b/tests/Security/Helper/FinishRegistrationBehaviorTest.php index 41cc21bf..99872793 100644 --- a/tests/Security/Helper/FinishRegistrationBehaviorTest.php +++ b/tests/Security/Helper/FinishRegistrationBehaviorTest.php @@ -20,7 +20,7 @@ class FinishRegistrationBehaviorTest extends TestCase { private $traitObject; - public function setUp() + public function setUp(): void { $this->traitObject = $this ->getMockForTrait('KnpU\OAuth2ClientBundle\Security\Helper\FinishRegistrationBehavior'); diff --git a/tests/Security/Helper/PreviousUrlHelperTest.php b/tests/Security/Helper/PreviousUrlHelperTest.php index 76c8ba4f..220ba231 100644 --- a/tests/Security/Helper/PreviousUrlHelperTest.php +++ b/tests/Security/Helper/PreviousUrlHelperTest.php @@ -20,7 +20,7 @@ class PreviousUrlHelperTest extends TestCase { private $traitObject; - public function setUp() + public function setUp(): void { $this->traitObject = $this ->getMockForTrait('KnpU\OAuth2ClientBundle\Security\Helper\PreviousUrlHelper'); diff --git a/tests/Security/User/OAuthUserProviderTest.php b/tests/Security/User/OAuthUserProviderTest.php index 6f7d4076..24b9a9cb 100644 --- a/tests/Security/User/OAuthUserProviderTest.php +++ b/tests/Security/User/OAuthUserProviderTest.php @@ -12,6 +12,7 @@ use KnpU\OAuth2ClientBundle\Security\User\OAuthUser; use KnpU\OAuth2ClientBundle\Security\User\OAuthUserProvider; +use Symfony\Component\Security\Core\Exception\UnsupportedUserException; use Symfony\Component\Security\Core\User\User; use Symfony\Component\Security\Core\User\UserInterface; use PHPUnit\Framework\TestCase; @@ -37,11 +38,9 @@ public function testRefreshUser() $this->assertEquals($expected, $userProvider->refreshUser($user)); } - /** - * @expectedException \Symfony\Component\Security\Core\Exception\UnsupportedUserException - */ public function testRefreshOtherUser() { + $this->expectException(UnsupportedUserException::class); $userProvider = new OAuthUserProvider(); $userProvider->refreshUser($this->createMock(UserInterface::class)); diff --git a/tests/app/TestKernel.php b/tests/app/TestKernel.php index 24aef89c..62bb1346 100644 --- a/tests/app/TestKernel.php +++ b/tests/app/TestKernel.php @@ -8,7 +8,7 @@ * file that was distributed with this source code. */ -namespace KnpU\OAuth2ClientBundle\tests\app; +namespace KnpU\OAuth2ClientBundle\Tests\app; use GuzzleHttp\Client; use KnpU\OAuth2ClientBundle\KnpUOAuth2ClientBundle; @@ -20,7 +20,7 @@ class TestKernel extends Kernel { - public function registerBundles() + public function registerBundles(): iterable { return [ new FrameworkBundle(), @@ -62,7 +62,7 @@ public function registerContainerConfiguration(LoaderInterface $loader) }); } - public function getCacheDir() + public function getCacheDir(): string { if (method_exists($this, 'getProjectDir')) { return $this->getProjectDir() . '/tests/app/cache/' . $this->getEnvironment(); @@ -71,7 +71,7 @@ public function getCacheDir() return parent::getCacheDir(); } - public function getLogDir() + public function getLogDir(): string { if (method_exists($this, 'getProjectDir')) { return $this->getProjectDir() . '/tests/app/cache/' . $this->getEnvironment();