diff --git a/composer.json b/composer.json index 7359980..dd04039 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ "psr/http-message": "^1.0.1" }, "require-dev": { - "laminas/laminas-coding-standard": "~1.0.0", + "laminas/laminas-coding-standard": "~2.2.0", "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.5" }, diff --git a/composer.lock b/composer.lock index c2dec55..a1ed5ee 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "083c40b89c717c22bd9b3c3eb35e987d", + "content-hash": "e6ba3b11f474fde2732eed7f59ba9f96", "packages": [ { "name": "laminas/laminas-authentication", @@ -640,6 +640,76 @@ } ], "packages-dev": [ + { + "name": "dealerdirect/phpcodesniffer-composer-installer", + "version": "v0.7.1", + "source": { + "type": "git", + "url": "https://github.com/Dealerdirect/phpcodesniffer-composer-installer.git", + "reference": "fe390591e0241955f22eb9ba327d137e501c771c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Dealerdirect/phpcodesniffer-composer-installer/zipball/fe390591e0241955f22eb9ba327d137e501c771c", + "reference": "fe390591e0241955f22eb9ba327d137e501c771c", + "shasum": "" + }, + "require": { + "composer-plugin-api": "^1.0 || ^2.0", + "php": ">=5.3", + "squizlabs/php_codesniffer": "^2.0 || ^3.0 || ^4.0" + }, + "require-dev": { + "composer/composer": "*", + "phpcompatibility/php-compatibility": "^9.0", + "sensiolabs/security-checker": "^4.1.0" + }, + "type": "composer-plugin", + "extra": { + "class": "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin" + }, + "autoload": { + "psr-4": { + "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Franck Nijhof", + "email": "franck.nijhof@dealerdirect.com", + "homepage": "http://www.frenck.nl", + "role": "Developer / IT Manager" + } + ], + "description": "PHP_CodeSniffer Standards Composer Installer Plugin", + "homepage": "http://www.dealerdirect.com", + "keywords": [ + "PHPCodeSniffer", + "PHP_CodeSniffer", + "code quality", + "codesniffer", + "composer", + "installer", + "phpcs", + "plugin", + "qa", + "quality", + "standard", + "standards", + "style guide", + "stylecheck", + "tests" + ], + "support": { + "issues": "https://github.com/dealerdirect/phpcodesniffer-composer-installer/issues", + "source": "https://github.com/dealerdirect/phpcodesniffer-composer-installer" + }, + "time": "2020-12-07T18:04:37+00:00" + }, { "name": "doctrine/instantiator", "version": "1.4.0", @@ -711,31 +781,36 @@ }, { "name": "laminas/laminas-coding-standard", - "version": "1.0.0", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/laminas/laminas-coding-standard.git", - "reference": "08880ce2fbfe62d471cd3cb766a91da630b32539" + "reference": "af23a4ceca36b887415585040c6afaff081ccc33" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-coding-standard/zipball/08880ce2fbfe62d471cd3cb766a91da630b32539", - "reference": "08880ce2fbfe62d471cd3cb766a91da630b32539", + "url": "https://api.github.com/repos/laminas/laminas-coding-standard/zipball/af23a4ceca36b887415585040c6afaff081ccc33", + "reference": "af23a4ceca36b887415585040c6afaff081ccc33", "shasum": "" }, "require": { - "laminas/laminas-zendframework-bridge": "^1.0", - "squizlabs/php_codesniffer": "^2.7" + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", + "php": "^7.3 || ~8.0.0", + "slevomat/coding-standard": "^6.4.1", + "squizlabs/php_codesniffer": "^3.5.8", + "webimpress/coding-standard": "^1.1.6" }, - "replace": { - "zendframework/zend-coding-standard": "self.version" + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "LaminasCodingStandard\\": "src/LaminasCodingStandard/" + } }, - "type": "library", "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" ], - "description": "Laminas coding standard", + "description": "Laminas Coding Standard", "homepage": "https://laminas.dev", "keywords": [ "Coding Standard", @@ -749,7 +824,13 @@ "rss": "https://github.com/laminas/laminas-coding-standard/releases.atom", "source": "https://github.com/laminas/laminas-coding-standard" }, - "time": "2019-12-31T16:28:26+00:00" + "funding": [ + { + "url": "https://funding.communitybridge.org/projects/laminas-project", + "type": "community_bridge" + } + ], + "time": "2021-05-15T09:20:49+00:00" }, { "name": "myclabs/deep-copy", @@ -811,16 +892,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.10.4", + "version": "v4.10.5", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "c6d052fc58cb876152f89f532b95a8d7907e7f0e" + "reference": "4432ba399e47c66624bc73c8c0f811e5c109576f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/c6d052fc58cb876152f89f532b95a8d7907e7f0e", - "reference": "c6d052fc58cb876152f89f532b95a8d7907e7f0e", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4432ba399e47c66624bc73c8c0f811e5c109576f", + "reference": "4432ba399e47c66624bc73c8c0f811e5c109576f", "shasum": "" }, "require": { @@ -861,9 +942,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.4" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.10.5" }, - "time": "2020-12-20T10:01:03+00:00" + "time": "2021-05-03T19:11:20+00:00" }, { "name": "phar-io/manifest", @@ -1253,6 +1334,59 @@ }, "time": "2020-07-09T08:33:42+00:00" }, + { + "name": "phpstan/phpdoc-parser", + "version": "0.4.9", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpdoc-parser.git", + "reference": "98a088b17966bdf6ee25c8a4b634df313d8aa531" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/98a088b17966bdf6ee25c8a4b634df313d8aa531", + "reference": "98a088b17966bdf6ee25c8a4b634df313d8aa531", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "consistence/coding-standard": "^3.5", + "ergebnis/composer-normalize": "^2.0.2", + "jakub-onderka/php-parallel-lint": "^0.9.2", + "phing/phing": "^2.16.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^0.12.26", + "phpstan/phpstan-strict-rules": "^0.12", + "phpunit/phpunit": "^6.3", + "slevomat/coding-standard": "^4.7.2", + "symfony/process": "^4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.4-dev" + } + }, + "autoload": { + "psr-4": { + "PHPStan\\PhpDocParser\\": [ + "src/" + ] + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPDoc parser with support for nullable, intersection and generic types", + "support": { + "issues": "https://github.com/phpstan/phpdoc-parser/issues", + "source": "https://github.com/phpstan/phpdoc-parser/tree/master" + }, + "time": "2020-08-03T20:32:43+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.6", @@ -2638,66 +2772,100 @@ ], "time": "2020-09-28T06:39:44+00:00" }, + { + "name": "slevomat/coding-standard", + "version": "6.4.1", + "source": { + "type": "git", + "url": "https://github.com/slevomat/coding-standard.git", + "reference": "696dcca217d0c9da2c40d02731526c1e25b65346" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/696dcca217d0c9da2c40d02731526c1e25b65346", + "reference": "696dcca217d0c9da2c40d02731526c1e25b65346", + "shasum": "" + }, + "require": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", + "php": "^7.1 || ^8.0", + "phpstan/phpdoc-parser": "0.4.5 - 0.4.9", + "squizlabs/php_codesniffer": "^3.5.6" + }, + "require-dev": { + "phing/phing": "2.16.3", + "php-parallel-lint/php-parallel-lint": "1.2.0", + "phpstan/phpstan": "0.12.48", + "phpstan/phpstan-deprecation-rules": "0.12.5", + "phpstan/phpstan-phpunit": "0.12.16", + "phpstan/phpstan-strict-rules": "0.12.5", + "phpunit/phpunit": "7.5.20|8.5.5|9.4.0" + }, + "type": "phpcodesniffer-standard", + "extra": { + "branch-alias": { + "dev-master": "6.x-dev" + } + }, + "autoload": { + "psr-4": { + "SlevomatCodingStandard\\": "SlevomatCodingStandard" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", + "support": { + "issues": "https://github.com/slevomat/coding-standard/issues", + "source": "https://github.com/slevomat/coding-standard/tree/6.4.1" + }, + "funding": [ + { + "url": "https://github.com/kukulich", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/slevomat/coding-standard", + "type": "tidelift" + } + ], + "time": "2020-10-05T12:39:37+00:00" + }, { "name": "squizlabs/php_codesniffer", - "version": "2.9.2", + "version": "3.6.0", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "2acf168de78487db620ab4bc524135a13cfe6745" + "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/2acf168de78487db620ab4bc524135a13cfe6745", - "reference": "2acf168de78487db620ab4bc524135a13cfe6745", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ffced0d2c8fa8e6cdc4d695a743271fab6c38625", + "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625", "shasum": "" }, "require": { "ext-simplexml": "*", "ext-tokenizer": "*", "ext-xmlwriter": "*", - "php": ">=5.1.2" + "php": ">=5.4.0" }, "require-dev": { - "phpunit/phpunit": "~4.0" + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" }, "bin": [ - "scripts/phpcs", - "scripts/phpcbf" + "bin/phpcs", + "bin/phpcbf" ], "type": "library", "extra": { "branch-alias": { - "dev-master": "2.x-dev" + "dev-master": "3.x-dev" } }, - "autoload": { - "classmap": [ - "CodeSniffer.php", - "CodeSniffer/CLI.php", - "CodeSniffer/Exception.php", - "CodeSniffer/File.php", - "CodeSniffer/Fixer.php", - "CodeSniffer/Report.php", - "CodeSniffer/Reporting.php", - "CodeSniffer/Sniff.php", - "CodeSniffer/Tokens.php", - "CodeSniffer/Reports/", - "CodeSniffer/Tokenizers/", - "CodeSniffer/DocGenerators/", - "CodeSniffer/Standards/AbstractPatternSniff.php", - "CodeSniffer/Standards/AbstractScopeSniff.php", - "CodeSniffer/Standards/AbstractVariableSniff.php", - "CodeSniffer/Standards/IncorrectPatternException.php", - "CodeSniffer/Standards/Generic/Sniffs/", - "CodeSniffer/Standards/MySource/Sniffs/", - "CodeSniffer/Standards/PEAR/Sniffs/", - "CodeSniffer/Standards/PSR1/Sniffs/", - "CodeSniffer/Standards/PSR2/Sniffs/", - "CodeSniffer/Standards/Squiz/Sniffs/", - "CodeSniffer/Standards/Zend/Sniffs/" - ] - }, "notification-url": "https://packagist.org/downloads/", "license": [ "BSD-3-Clause" @@ -2709,7 +2877,7 @@ } ], "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", - "homepage": "http://www.squizlabs.com/php-codesniffer", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", "keywords": [ "phpcs", "standards" @@ -2719,7 +2887,7 @@ "source": "https://github.com/squizlabs/PHP_CodeSniffer", "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" }, - "time": "2018-11-07T22:31:41+00:00" + "time": "2021-04-09T00:54:41+00:00" }, { "name": "theseer/tokenizer", @@ -2770,6 +2938,61 @@ } ], "time": "2020-07-12T23:59:07+00:00" + }, + { + "name": "webimpress/coding-standard", + "version": "1.2.2", + "source": { + "type": "git", + "url": "https://github.com/webimpress/coding-standard.git", + "reference": "8f4a220de33f471a8101836f7ec72b852c3f9f03" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/webimpress/coding-standard/zipball/8f4a220de33f471a8101836f7ec72b852c3f9f03", + "reference": "8f4a220de33f471a8101836f7ec72b852c3f9f03", + "shasum": "" + }, + "require": { + "php": "^7.3 || ^8.0", + "squizlabs/php_codesniffer": "^3.6" + }, + "require-dev": { + "phpunit/phpunit": "^9.5.4" + }, + "type": "phpcodesniffer-standard", + "extra": { + "dev-master": "1.2.x-dev", + "dev-develop": "1.3.x-dev" + }, + "autoload": { + "psr-4": { + "WebimpressCodingStandard\\": "src/WebimpressCodingStandard/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "description": "Webimpress Coding Standard", + "keywords": [ + "Coding Standard", + "PSR-2", + "phpcs", + "psr-12", + "webimpress" + ], + "support": { + "issues": "https://github.com/webimpress/coding-standard/issues", + "source": "https://github.com/webimpress/coding-standard/tree/1.2.2" + }, + "funding": [ + { + "url": "https://github.com/michalbundyra", + "type": "github" + } + ], + "time": "2021-04-12T12:51:27+00:00" } ], "aliases": [], diff --git a/phpcs.xml b/phpcs.xml index 4da1eed..1efe663 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,8 +1,20 @@ - - + + + + + + + + + + src test + + + diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index b77251a..e2001b6 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -1,39 +1,31 @@ $this->getAuthenticationConfig(), - 'dependencies' => $this->getDependencies(), + 'dependencies' => $this->getDependencies(), ]; } - public function getAuthenticationConfig() : array + public function getAuthenticationConfig(): array { return [ 'redirect' => '', // URL to which to redirect for invalid credentials ]; } - public function getDependencies() : array + public function getDependencies(): array { return [ // Legacy Zend Framework aliases - 'aliases' => [ + 'aliases' => [ // @codingStandardsIgnoreStart \Zend\Expressive\Authentication\ZendAuthentication\ZendAuthentication::class => LaminasAuthentication::class, // @codingStandardsIgnoreEnd diff --git a/src/LaminasAuthentication.php b/src/LaminasAuthentication.php index f016abd..b576a9b 100644 --- a/src/LaminasAuthentication.php +++ b/src/LaminasAuthentication.php @@ -1,13 +1,5 @@ auth = $auth; + $this->auth = $auth; $this->config = $config; // Ensures type safety of the composed factory - $this->responseFactory = function () use ($responseFactory) : ResponseInterface { + $this->responseFactory = function () use ($responseFactory): ResponseInterface { return $responseFactory(); }; @@ -61,12 +45,12 @@ public function __construct( string $identity, array $roles = [], array $details = [] - ) use ($userFactory) : UserInterface { + ) use ($userFactory): UserInterface { return $userFactory($identity, $roles, $details); }; } - public function authenticate(ServerRequestInterface $request) : ?UserInterface + public function authenticate(ServerRequestInterface $request): ?UserInterface { if (! $this->auth->hasIdentity()) { if ('POST' === strtoupper($request->getMethod())) { @@ -78,7 +62,7 @@ public function authenticate(ServerRequestInterface $request) : ?UserInterface return ($this->userFactory)($this->auth->getIdentity()); } - public function unauthorizedResponse(ServerRequestInterface $request) : ResponseInterface + public function unauthorizedResponse(ServerRequestInterface $request): ResponseInterface { return ($this->responseFactory)() ->withHeader( @@ -88,9 +72,9 @@ public function unauthorizedResponse(ServerRequestInterface $request) : Response ->withStatus(301); } - private function initiateAuthentication(ServerRequestInterface $request) : ?UserInterface + private function initiateAuthentication(ServerRequestInterface $request): ?UserInterface { - $params = $request->getParsedBody(); + $params = $request->getParsedBody(); $username = $this->config['username'] ?? 'username'; $password = $this->config['password'] ?? 'password'; diff --git a/src/LaminasAuthenticationFactory.php b/src/LaminasAuthenticationFactory.php index fee5d71..5fb4431 100644 --- a/src/LaminasAuthenticationFactory.php +++ b/src/LaminasAuthenticationFactory.php @@ -1,13 +1,5 @@ has(AuthenticationService::class) ? $container->get(AuthenticationService::class) @@ -45,7 +37,8 @@ public function __invoke(ContainerInterface $container) : LaminasAuthentication ); } - if (! $container->has(UserInterface::class) + if ( + ! $container->has(UserInterface::class) && ! $container->has(\Zend\Expressive\Authentication\UserInterface::class) ) { throw new Exception\InvalidConfigException( diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index cbabfbe..50ee4e3 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -1,13 +1,5 @@ provider = new ConfigProvider(); } - public function testInvocationReturnsArray() + public function testInvocationReturnsArray(): array { $config = ($this->provider)(); $this->assertInternalType('array', $config); @@ -48,6 +40,7 @@ public function testReturnedArrayContainsAuthenticationConfig(array $config) $this->assertInternalType('array', $config['authentication']); } + /** @param mixed $actual */ private static function assertInternalType(string $expected, $actual, string $message = ''): void { static::assertThat( diff --git a/test/LaminasAuthenticationFactoryTest.php b/test/LaminasAuthenticationFactoryTest.php index 68a3be3..195b6b7 100644 --- a/test/LaminasAuthenticationFactoryTest.php +++ b/test/LaminasAuthenticationFactoryTest.php @@ -1,13 +1,5 @@ container = $this->prophesize(ContainerInterface::class); - $this->factory = new LaminasAuthenticationFactory(); - $this->authService = $this->prophesize(AuthenticationService::class); + $this->container = $this->prophesize(ContainerInterface::class); + $this->factory = new LaminasAuthenticationFactory(); + $this->authService = $this->prophesize(AuthenticationService::class); $this->responsePrototype = $this->prophesize(ResponseInterface::class); - $this->responseFactory = function () { + $this->responseFactory = function () { return $this->responsePrototype->reveal(); }; - $this->userPrototype = $this->prophesize(UserInterface::class); - $this->userFactory = function () { + $this->userPrototype = $this->prophesize(UserInterface::class); + $this->userFactory = function () { return $this->userPrototype->reveal(); }; } @@ -133,7 +125,7 @@ public function testInvokeWithContainerAndConfig() public static function assertResponseFactoryReturns( ResponseInterface $expected, LaminasAuthentication $service - ) : void { + ): void { $r = new ReflectionProperty($service, 'responseFactory'); $r->setAccessible(true); $responseFactory = $r->getValue($service); diff --git a/test/LaminasAuthenticationTest.php b/test/LaminasAuthenticationTest.php index 776e143..069be38 100644 --- a/test/LaminasAuthenticationTest.php +++ b/test/LaminasAuthenticationTest.php @@ -1,13 +1,5 @@ request = $this->prophesize(ServerRequestInterface::class); - $this->authService = $this->prophesize(AuthenticationService::class); - $this->authenticatedUser = $this->prophesize(UserInterface::class); + $this->request = $this->prophesize(ServerRequestInterface::class); + $this->authService = $this->prophesize(AuthenticationService::class); $this->responseFactory = function () { return $this->prophesize(ResponseInterface::class)->reveal(); }; - $this->userPrototype = $this->prophesize(UserInterface::class); - $this->userFactory = function () { + $this->userPrototype = $this->prophesize(UserInterface::class); + $this->userFactory = function () { return $this->userPrototype->reveal(); }; } @@ -83,7 +71,7 @@ public function testAuthenticateWithGetMethodAndIdentity() $this->responseFactory, $this->userFactory ); - $result = $laminasAuthentication->authenticate($this->request->reveal()); + $result = $laminasAuthentication->authenticate($this->request->reveal()); $this->assertInstanceOf(UserInterface::class, $result); } @@ -179,7 +167,7 @@ public function testAuthenticateWithPostMethodAndValidCredential() $this->responseFactory, $this->userFactory ); - $result = $laminasAuthentication->authenticate($this->request->reveal()); + $result = $laminasAuthentication->authenticate($this->request->reveal()); $this->assertInstanceOf(UserInterface::class, $result); } @@ -215,7 +203,7 @@ public function testAuthenticateWithPostMethodAndNoValidCredentialAndAlreadyAuth $this->responseFactory, $this->userFactory ); - $identity = $laminasAuthentication->authenticate($this->request->reveal()); + $identity = $laminasAuthentication->authenticate($this->request->reveal()); $this->assertInstanceOf(UserInterface::class, $identity); $this->assertEquals('string', $identity->getIdentity()); }