diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8d37006..4e2321a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,7 @@ on: - 2.x - 2.next - 3.x + - 4.x pull_request: branches: - '*' @@ -16,9 +17,9 @@ permissions: jobs: testsuite: - uses: cakephp/.github/.github/workflows/testsuite-without-db.yml@5.x + uses: cakephp/.github/.github/workflows/testsuite-without-db.yml@6.x secrets: inherit cs-stan: - uses: cakephp/.github/.github/workflows/cs-stan.yml@5.x + uses: cakephp/.github/.github/workflows/cs-stan.yml@6.x secrets: inherit diff --git a/.phive/phars.xml b/.phive/phars.xml index 848f478..12f581a 100644 --- a/.phive/phars.xml +++ b/.phive/phars.xml @@ -1,4 +1,4 @@ - + diff --git a/composer.json b/composer.json index 931a794..5633cee 100644 --- a/composer.json +++ b/composer.json @@ -23,19 +23,19 @@ "docs": "https://cakephp.org/authorization/2/en/" }, "require": { - "php": ">=8.1", - "cakephp/http": "^5.1", + "php": ">=8.4", + "cakephp/http": "^6.0", "psr/http-client": "^1.0", "psr/http-message": "^1.1 || ^2.0", "psr/http-server-handler": "^1.0", "psr/http-server-middleware": "^1.0" }, "require-dev": { - "cakephp/authentication": "^3.0 || ^4.0", - "cakephp/bake": "^3.2", - "cakephp/cakephp": "^5.1", - "cakephp/cakephp-codesniffer": "^5.3", - "phpunit/phpunit": "^10.5.58 || ^11.5.3 || ^12.4 || ^13.0" + "cakephp/authentication": "^5.0", + "cakephp/bake": "^4.0", + "cakephp/cakephp": "^6.0", + "cakephp/cakephp-codesniffer": "^6.0", + "phpunit/phpunit": "^13.0" }, "suggest": { "cakephp/http": "To use \"RequestPolicyInterface\" (Not needed separately if using full CakePHP framework).", @@ -73,12 +73,12 @@ "stan": "@phpstan", "stan-baseline": "tools/phpstan --generate-baseline", "stan-setup": "phive install", - "rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.3.1\" && mv composer.backup composer.json", + "rector-setup": "cp composer.json composer.backup && composer require --dev rector/rector:\"~2.6.0\" && mv composer.backup composer.json", "rector-check": "vendor/bin/rector process --dry-run", "rector-fix": "vendor/bin/rector process", "test": "phpunit", "test-coverage": "phpunit --coverage-clover=clover.xml" }, - "minimum-stability": "stable", + "minimum-stability": "dev", "prefer-stable": true } diff --git a/docs/.vitepress/config.js b/docs/.vitepress/config.js index b6cee93..cd8f0e1 100644 --- a/docs/.vitepress/config.js +++ b/docs/.vitepress/config.js @@ -8,9 +8,10 @@ const tocFr = require('./toc_fr.json') const tocJa = require('./toc_ja.json') const versions = { - text: '3.x', + text: '4.x', items: [ - { text: '3.x (current)', link: 'https://book.cakephp.org/authorization/3/', target: '_self' }, + { text: '4.x (current)', link: 'https://book.cakephp.org/authorization/4/', target: '_self' }, + { text: '3.x', link: 'https://book.cakephp.org/authorization/3/', target: '_self' }, { text: '2.x', link: 'https://book.cakephp.org/authorization/2/en/', target: '_self' }, ], } @@ -20,12 +21,12 @@ export default { srcDir: '.', title: 'Authorization', description: 'CakePHP Authorization Documentation', - base: '/authorization/3/', + base: '/authorization/4/', rewrites: { 'en/:slug*': ':slug*', }, sitemap: { - hostname: 'https://book.cakephp.org/authorization/3/', + hostname: 'https://book.cakephp.org/authorization/4/', }, themeConfig: { siteTitle: false, @@ -34,7 +35,7 @@ export default { { icon: 'github', link: 'https://github.com/cakephp/authorization' }, ], editLink: { - pattern: 'https://github.com/cakephp/authorization/edit/3.x/docs/:path', + pattern: 'https://github.com/cakephp/authorization/edit/4.x/docs/:path', text: 'Edit this page on GitHub', }, sidebar: tocEn, diff --git a/docs/.vitepress/toc_en.json b/docs/.vitepress/toc_en.json index b973bf1..975c39b 100644 --- a/docs/.vitepress/toc_en.json +++ b/docs/.vitepress/toc_en.json @@ -18,7 +18,8 @@ "collapsed": false, "items": [ { "text": "2.0 Migration Guide", "link": "/2-0-migration-guide" }, - { "text": "3.0 Migration Guide", "link": "/3-0-migration-guide" } + { "text": "3.0 Migration Guide", "link": "/3-0-migration-guide" }, + { "text": "4.0 Migration Guide", "link": "/4-0-migration-guide" } ] } ] diff --git a/docs/en/4-0-migration-guide.md b/docs/en/4-0-migration-guide.md new file mode 100644 index 0000000..daea05a --- /dev/null +++ b/docs/en/4-0-migration-guide.md @@ -0,0 +1,74 @@ +# 4.0 Migration Guide + +Authorization 4.0 supports CakePHP 6. + +## Requirements + +Authorization 4.0 requires CakePHP 6.0 and PHP 8.4.0 or higher. + +## Container Classes Moved + +`Cake\Core\Container` and `Cake\Core\ContainerInterface` moved to the +`Cake\Container` namespace: + +- `Cake\Core\Container` is now `Cake\Container\Container` +- `Cake\Core\ContainerInterface` is now `Cake\Container\ContainerInterface` + +`AuthorizationMiddleware`, `MapResolver`, and `OrmResolver` accept a container +as their constructor argument, and now type hint `Cake\Container\ContainerInterface`. +Update your imports, including where you subclass these classes and override +their constructors. + +## Protected Properties Renamed + +CakePHP 6 dropped the underscore prefix from protected properties. The +following properties were renamed. This only affects applications that +subclass these classes: + +- `AuthorizationComponent`, `AuthorizationMiddleware`, and + `RequestAuthorizationMiddleware`: `$_defaultConfig` is now `$defaultConfig` +- `AuthorizationComponent`: `$_config`, from `InstanceConfigTrait`, is now + `$config` +- `MissingIdentityException`, `AuthorizationRequiredException`, + `ForbiddenException`, `MissingMethodException`, and `MissingPolicyException`: + `$_defaultCode` and `$_messageTemplate` are now `$defaultCode` and + `$messageTemplate` + +The exception properties must match the names used by +`Cake\Http\Exception\HttpException`, otherwise the status codes and message +templates defined by these classes are ignored. + +## Fluent Methods Declare Static Return Types + +The following methods now declare a `static` return type. Subclasses that +override them must declare a compatible return type: + +- `AuthorizationComponent::skipAuthorization()` +- `AuthorizationComponent::mapAction()` +- `AuthorizationComponent::mapActions()` +- `AuthorizationComponent::authorizeModel()` +- `MapResolver::map()` +- `ResolverCollection::add()` + +## Constructor Changes + +`IdentityDecorator::__construct()` renamed its first parameter from `$service` +to `$authorization` to match the promoted property. Positional arguments are +unaffected. Calls using named arguments must be updated. + +`AuthorizationService`, `IdentityDecorator`, `AuthorizationMiddleware`, +`ForbiddenException`, `MapResolver`, `OrmResolver`, and `Result` now declare +their constructor-assigned properties as promoted properties. The visibility +and default values of these properties are unchanged. + +## Bake Command + +`Authorization\Command\PolicyCommand` targets the Bake 6 API: + +- `templateData()` no longer accepts an `Arguments` instance, it reads the name + and type from the command's stored arguments. +- `bakeTest()` now only accepts a class name. +- `buildOptionParser()` is now `protected`. + +Only applications that subclass `PolicyCommand` are affected. The +`bin/cake bake policy` command line interface is unchanged. diff --git a/docs/en/index.md b/docs/en/index.md index e4fd143..49b8685 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -6,10 +6,10 @@ Install the plugin with [Composer](https://getcomposer.org/) from your CakePHP project root, where `composer.json` is located: ```bash -php composer.phar require "cakephp/authorization:^3.0" +php composer.phar require "cakephp/authorization:^4.0" ``` -Authorization 3.x is compatible with CakePHP 5. +Authorization 4.x is compatible with CakePHP 6. Load the plugin in `src/Application.php`: diff --git a/docs/es/index.md b/docs/es/index.md index 5b97cae..ae1bcb2 100644 --- a/docs/es/index.md +++ b/docs/es/index.md @@ -6,7 +6,7 @@ Instale el plugin con [Composer](https://getcomposer.org/) desde el directorio raíz de su proyecto CakePHP: ```bash -php composer.phar require "cakephp/authorization:^3.0" +php composer.phar require "cakephp/authorization:^4.0" ``` Cargue el plugin en `src/Application.php`: diff --git a/docs/fr/index.md b/docs/fr/index.md index 8de561c..885884f 100644 --- a/docs/fr/index.md +++ b/docs/fr/index.md @@ -6,10 +6,10 @@ Installez le plugin avec [Composer](https://getcomposer.org/) depuis le répertoire racine de votre projet CakePHP, là où se trouve `composer.json` : ```bash -php composer.phar require "cakephp/authorization:^3.0" +php composer.phar require "cakephp/authorization:^4.0" ``` -La version 3 du plugin Authorization est compatible avec CakePHP 5. +La version 4 du plugin Authorization est compatible avec CakePHP 6. Chargez le plugin dans `src/Application.php` : diff --git a/docs/ja/index.md b/docs/ja/index.md index b431dc2..8c5f961 100644 --- a/docs/ja/index.md +++ b/docs/ja/index.md @@ -6,10 +6,10 @@ CakePHP プロジェクトのルートディレクトリで [Composer](https://getcomposer.org/) を使ってプラグインを追加します。 ```bash -php composer.phar require "cakephp/authorization:^3.0" +php composer.phar require "cakephp/authorization:^4.0" ``` -Authorization 3.x は CakePHP 5 に対応しています。 +Authorization 4.x は CakePHP 6 に対応しています。 `src/Application.php` でプラグインを読み込みます。 diff --git a/phpcs.xml b/phpcs.xml index 8e40281..9c28450 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -5,7 +5,7 @@ src/ tests/ - + diff --git a/readme.md b/readme.md index c9715be..10234ab 100644 --- a/readme.md +++ b/readme.md @@ -32,4 +32,4 @@ bin/cake plugin load Authorization ## Documentation Documentation for this plugin can be found in the [CakePHP -Cookbook](https://book.cakephp.org/authorization/3/en/) +Cookbook](https://book.cakephp.org/authorization/4/) diff --git a/rector.php b/rector.php index 3290f03..afe1c07 100644 --- a/rector.php +++ b/rector.php @@ -2,26 +2,102 @@ declare(strict_types=1); use Rector\Caching\ValueObject\Storage\FileCacheStorage; +use Rector\CodeQuality\Rector\BooleanNot\NegatedAndsToPositiveOrsRector; +use Rector\CodeQuality\Rector\Catch_\ThrowWithPreviousExceptionRector; +use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector; +use Rector\CodeQuality\Rector\ClassMethod\ExplicitReturnNullRector; +use Rector\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector; +use Rector\CodeQuality\Rector\Equal\UseIdenticalOverEqualWithSameTypeRector; +use Rector\CodeQuality\Rector\Foreach_\ForeachToInArrayRector; use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector; -use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector; -use Rector\CodingStyle\Rector\Assign\SplitDoubleAssignRector; +use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector; +use Rector\CodeQuality\Rector\If_\ConsecutiveNullCompareReturnsToNullCoalesceQueueRector; +use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector; +use Rector\CodeQuality\Rector\Include_\AbsolutizeRequireAndIncludePathRector; +use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector; +use Rector\CodeQuality\Rector\Property\FixClassCaseSensitivityVarDocblockRector; use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector; +use Rector\CodingStyle\Rector\ClassLike\NewlineBetweenClassLikeStmtsRector; use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; +use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector; +use Rector\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector; +use Rector\CodingStyle\Rector\FuncCall\StrictArraySearchRector; +use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector; use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector; +use Rector\CodingStyle\Rector\String_\UseClassKeywordForClassNameResolutionRector; use Rector\Config\RectorConfig; +use Rector\DeadCode\Rector\Assign\RemoveDoubleAssignRector; +use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector; +use Rector\DeadCode\Rector\Cast\RecastingRemovalRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveDuplicatedReturnSelfDocblockRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveMixedDocblockOverruledByNativeTypeRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveParentDelegatingClassMethodRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveReturnTagIncompatibleWithNativeTypeRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector; use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector; +use Rector\DeadCode\Rector\ClassMethod\RemoveUselessUnionReturnDocblockRector; +use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector; +use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector; +use Rector\DeadCode\Rector\For_\RemoveDeadIfForeachForRector; +use Rector\DeadCode\Rector\For_\RemoveDeadLoopRector; +use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector; +use Rector\DeadCode\Rector\If_\RemoveDeadInstanceOfRector; +use Rector\DeadCode\Rector\If_\UnwrapFutureCompatibleIfPhpVersionRector; +use Rector\DeadCode\Rector\MethodCall\RemoveNullArgOnNullDefaultParamRector; +use Rector\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector; +use Rector\DeadCode\Rector\Property\RemoveDefaultValueFromAssignedPropertyRector; +use Rector\DeadCode\Rector\Property\RemoveUselessVarTagRector; +use Rector\DeadCode\Rector\StmtsAwareInterface\RemoveDeadInstanceOfAssertRector; +use Rector\DeadCode\Rector\Ternary\RemoveUselessTernaryRector; +use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; +use Rector\Php56\Rector\FuncCall\PowToExpRector; +use Rector\Php73\Rector\FuncCall\ArrayKeyFirstLastRector; +use Rector\Php73\Rector\FuncCall\SetCookieRector; +use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector; +use Rector\Php73\Rector\String_\SensitiveHereNowDocRector; use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; -use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector; +use Rector\Php74\Rector\Property\RestoreDefaultNullToNullableTypePropertyRector; +use Rector\Php80\Rector\FuncCall\ClassOnObjectRector; +use Rector\Php80\Rector\NotIdentical\MbStrContainsRector; +use Rector\Php81\Rector\Property\ReadOnlyPropertyRector; use Rector\Set\ValueObject\SetList; +use Rector\TypeDeclaration\Rector\ArrowFunction\AddArrowFunctionReturnTypeRector; +use Rector\TypeDeclaration\Rector\BooleanAnd\BinaryOpNullableToInstanceofRector; use Rector\TypeDeclaration\Rector\Class_\TypedPropertyFromCreateMockAssignRector; +use Rector\TypeDeclaration\Rector\ClassMethod\AddParamStringTypeFromSprintfUseRector; +use Rector\TypeDeclaration\Rector\ClassMethod\AddParamTypeBasedOnPHPUnitDataProviderRector; +use Rector\TypeDeclaration\Rector\ClassMethod\AddVoidReturnTypeWhereNoReturnRector; +use Rector\TypeDeclaration\Rector\ClassMethod\ArrayParamTypeByMethodCallTypeRector; +use Rector\TypeDeclaration\Rector\ClassMethod\BoolReturnTypeFromBooleanConstReturnsRector; +use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByMethodCallTypeRector; +use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector; +use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromMockObjectRector; use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictFluentReturnRector; +use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector; +use Rector\TypeDeclaration\Rector\ClassMethod\ReturnUnionTypeRector; +use Rector\TypeDeclaration\Rector\ClassMethod\ScalarParamTypeByMethodCallTypeRector; +use Rector\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector; +use Rector\TypeDeclaration\Rector\Closure\AddClosureNeverReturnTypeRector; +use Rector\TypeDeclaration\Rector\Closure\ClosureReturnTypeFromAssertInstanceOfRector; +use Rector\TypeDeclaration\Rector\Closure\ClosureReturnTypeRector; +use Rector\TypeDeclaration\Rector\FunctionLike\AddClosureParamTypeForArrayMapRector; +use Rector\TypeDeclaration\Rector\FunctionLike\AddClosureParamTypeFromVariableCallRector; +use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; +use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector; +use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictSetUpRector; +use Rector\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector; +use Rector\TypeDeclaration\Rector\While_\WhileNullableToInstanceofRector; $cacheDir = getenv('RECTOR_CACHE_DIR') ?: sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'rector'; return RectorConfig::configure() ->withPaths([ __DIR__ . '/src', - __DIR__ . '/tests', + __DIR__ . '/tests/TestCase', ]) ->withCache( @@ -36,30 +112,105 @@ SetList::CODE_QUALITY, SetList::CODING_STYLE, SetList::DEAD_CODE, - SetList::EARLY_RETURN, - SetList::INSTANCEOF, SetList::TYPE_DECLARATION, ]) ->withSkip([ - __DIR__ . '/tests/comparisons', - ClassPropertyAssignToConstructorPromotionRector::class, + ThrowWithPreviousExceptionRector::class, + ExplicitReturnNullRector::class, + OptionalParametersAfterRequiredRector::class, + CompleteDynamicPropertiesRector::class, + ForeachToInArrayRector::class, + CompactToVariablesRector::class, + FlipTypeControlToUseExclusiveTypeRector::class, + ConsecutiveNullCompareReturnsToNullCoalesceQueueRector::class, + SimplifyIfReturnBoolRector::class, + AbsolutizeRequireAndIncludePathRector::class, + IssetOnPropertyObjectToPropertyExistsRector::class, CatchExceptionNameMatchingTypeRector::class, - ClosureToArrowFunctionRector::class, + MakeInheritedMethodVisibilitySameAsParentRector::class, + NewlineBeforeNewAssignSetRector::class, + StrictArraySearchRector::class, + VersionCompareFuncCallToConstantRector::class, + FunctionFirstClassCallableRector::class, + NewlineAfterStatementRector::class, + UseClassKeywordForClassNameResolutionRector::class, + RemoveDoubleAssignRector::class, + RemoveUnusedVariableAssignRector::class, + RecastingRemovalRector::class, + RemoveEmptyClassMethodRector::class, + RemoveNullTagValueNodeRector::class, + RemoveUnusedConstructorParamRector::class, + RemoveUnusedPrivateMethodRector::class, + RemoveUselessParamTagRector::class, RemoveUselessReturnTagRector::class, - CompactToVariablesRector::class, + RemovePhpVersionIdCheckRector::class, + RemoveDeadStmtRector::class, + RemoveDeadIfForeachForRector::class, + RemoveDeadLoopRector::class, + RemoveAlwaysTrueIfConditionRector::class, + RemoveDeadInstanceOfRector::class, + UnwrapFutureCompatibleIfPhpVersionRector::class, + RemoveNullArgOnNullDefaultParamRector::class, + RemoveNonExistingVarAnnotationRector::class, + RemoveUselessVarTagRector::class, + PowToExpRector::class, + ArrayKeyFirstLastRector::class, + SetCookieRector::class, + StringifyStrNeedlesRector::class, + SensitiveHereNowDocRector::class, + ClosureToArrowFunctionRector::class, + ReadOnlyPropertyRector::class, + AddArrowFunctionReturnTypeRector::class, + BinaryOpNullableToInstanceofRector::class, + NewlineBetweenClassLikeStmtsRector::class, + AddParamStringTypeFromSprintfUseRector::class, + AddParamTypeBasedOnPHPUnitDataProviderRector::class, + AddVoidReturnTypeWhereNoReturnRector::class, + BoolReturnTypeFromBooleanConstReturnsRector::class, + ParamTypeByMethodCallTypeRector::class, + ReturnNeverTypeRector::class, + ReturnTypeFromMockObjectRector::class, ReturnTypeFromStrictFluentReturnRector::class, - SplitDoubleAssignRector::class, - NewlineAfterStatementRector::class, - ExplicitBoolCompareRector::class, + ReturnTypeFromStrictTypedCallRector::class, + ReturnUnionTypeRector::class, + StrictArrayParamDimFetchRector::class, TypedPropertyFromCreateMockAssignRector::class, + AddClosureNeverReturnTypeRector::class, + ClosureReturnTypeRector::class, + TypedPropertyFromAssignsRector::class, + TypedPropertyFromStrictConstructorRector::class, + TypedPropertyFromStrictSetUpRector::class, + WhileNullableToInstanceofRector::class, + RestoreDefaultNullToNullableTypePropertyRector::class, + + // Manual - only appliable for part of the code + UseIdenticalOverEqualWithSameTypeRector::class, + StringClassNameToClassConstantRector::class, + ClassOnObjectRector::class, + + // Newly aggressive in rector 2.4 - keep the bump behavior-neutral: + // adds declare(strict_types=1) to test fixtures/config (out of scope here), + SafeDeclareStrictTypesRector::class, + // and rewrites `$x ?: []` in ways that can change behavior on undefined/empty values. + RemoveUselessTernaryRector::class, - // Parent SimpleBakeCommand::buildOptionParser() switched from public - // to protected in cakephp/bake 3.6.4. Narrowing this override would - // break installs on bake 3.2 - 3.6.3 since PHP forbids reducing a - // parent's visibility. Keeping the override public is forward- and - // backward-compatible (widening is always allowed). - MakeInheritedMethodVisibilitySameAsParentRector::class => [ - __DIR__ . '/src/Command/PolicyCommand.php', - ], + // New in rector 2.5 - skipped to keep the version bump behavior-neutral. + // These mostly rewrite or remove docblocks. Whether to apply them is a + // separate decision from getting CI green again. + NegatedAndsToPositiveOrsRector::class, + FixClassCaseSensitivityVarDocblockRector::class, + RemoveDuplicatedReturnSelfDocblockRector::class, + RemoveMixedDocblockOverruledByNativeTypeRector::class, + RemoveParentDelegatingClassMethodRector::class, + RemoveReturnTagIncompatibleWithNativeTypeRector::class, + RemoveUselessUnionReturnDocblockRector::class, + RemoveDefaultValueFromAssignedPropertyRector::class, + RemoveDeadInstanceOfAssertRector::class, + MbStrContainsRector::class, + ArrayParamTypeByMethodCallTypeRector::class, + ScalarParamTypeByMethodCallTypeRector::class, + ClosureReturnTypeFromAssertInstanceOfRector::class, + AddClosureParamTypeForArrayMapRector::class, + AddClosureParamTypeFromVariableCallRector::class, ]); diff --git a/src/AuthorizationService.php b/src/AuthorizationService.php index c5815b0..0b4c596 100644 --- a/src/AuthorizationService.php +++ b/src/AuthorizationService.php @@ -27,11 +27,6 @@ class AuthorizationService implements AuthorizationServiceInterface { - /** - * Authorization policy resolver. - */ - protected ResolverInterface $resolver; - /** * Track whether authorization was checked. */ @@ -40,9 +35,8 @@ class AuthorizationService implements AuthorizationServiceInterface /** * @param \Authorization\Policy\ResolverInterface $resolver Authorization policy resolver. */ - public function __construct(ResolverInterface $resolver) + public function __construct(protected ResolverInterface $resolver) { - $this->resolver = $resolver; } /** diff --git a/src/Command/PolicyCommand.php b/src/Command/PolicyCommand.php index 6bbb6f5..ca52553 100644 --- a/src/Command/PolicyCommand.php +++ b/src/Command/PolicyCommand.php @@ -18,8 +18,6 @@ use Authorization\IdentityInterface; use Bake\Command\SimpleBakeCommand; -use Cake\Console\Arguments; -use Cake\Console\ConsoleIo; use Cake\Console\ConsoleOptionParser; use Cake\ORM\Query\SelectQuery; use Cake\Utility\Inflector; @@ -68,17 +66,18 @@ public function template(): string /** * @inheritDoc */ - public function templateData(Arguments $arguments): array + public function templateData(): array { - $data = parent::templateData($arguments); + $data = parent::templateData(); - $name = $arguments->getArgument('name'); + $name = $this->args->getArgument('name'); if (!$name) { throw new RuntimeException('You must specify name of policy to create.'); } - $name = $this->_getName($name); - $type = $this->type = (string)$arguments->getOption('type'); + $name = $this->getNameWithoutPrefix($name); + $this->type = (string)$this->args->getOption('type'); + $type = $this->type; $suffix = ''; if ($type === 'table') { @@ -119,9 +118,9 @@ public function templateData(Arguments $arguments): array * @param \Cake\Console\ConsoleOptionParser $parser The parser to update. * @return \Cake\Console\ConsoleOptionParser */ - public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser + protected function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionParser { - $parser = $this->_setCommonOptions($parser); + $parser = $this->setCommonOptions($parser); return $parser ->setDescription('Bake policy classes for various supported object types.') @@ -140,11 +139,9 @@ public function buildOptionParser(ConsoleOptionParser $parser): ConsoleOptionPar * Do nothing (for now) * * @param string $className The class to bake a test for. - * @param \Cake\Console\Arguments $args The arguments object - * @param \Cake\Console\ConsoleIo $io The consoleio object * @return void */ - public function bakeTest(string $className, Arguments $args, ConsoleIo $io): void + public function bakeTest(string $className): void { } } diff --git a/src/Controller/Component/AuthorizationComponent.php b/src/Controller/Component/AuthorizationComponent.php index c87a5e8..2596d4c 100644 --- a/src/Controller/Component/AuthorizationComponent.php +++ b/src/Controller/Component/AuthorizationComponent.php @@ -40,7 +40,7 @@ class AuthorizationComponent extends Component * * @var array */ - protected array $_defaultConfig = [ + protected array $defaultConfig = [ 'identityAttribute' => 'identity', 'serviceAttribute' => 'authorization', 'authorizationEvent' => 'Controller.startup', @@ -126,9 +126,7 @@ protected function performCheck( string $method = 'can', ): ResultInterface|bool { $request = $this->getController()->getRequest(); - if ($action === null) { - $action = $this->getDefaultAction($request); - } + $action ??= $this->getDefaultAction($request); $identity = $this->getIdentity($request); if (!$identity instanceof IdentityInterface) { @@ -152,9 +150,7 @@ protected function performCheck( public function applyScope(mixed $resource, ?string $action = null, mixed ...$optionalArgs): mixed { $request = $this->getController()->getRequest(); - if ($action === null) { - $action = $this->getDefaultAction($request); - } + $action ??= $this->getDefaultAction($request); $identity = $this->getIdentity($request); if (!$identity instanceof IdentityInterface) { return $this->getService($request)->applyScope(null, $action, $resource); @@ -168,7 +164,7 @@ public function applyScope(mixed $resource, ?string $action = null, mixed ...$op * * @return $this */ - public function skipAuthorization() + public function skipAuthorization(): static { $request = $this->getController()->getRequest(); $service = $this->getService($request); @@ -187,9 +183,9 @@ public function skipAuthorization() * @param string $policyAction Policy action. * @return $this */ - public function mapAction(string $controllerAction, string $policyAction) + public function mapAction(string $controllerAction, string $policyAction): static { - $this->_config['actionMap'][$controllerAction] = $policyAction; + $this->config['actionMap'][$controllerAction] = $policyAction; return $this; } @@ -201,7 +197,7 @@ public function mapAction(string $controllerAction, string $policyAction) * @param bool $overwrite Set to true to override configuration. False will merge with current configuration. * @return $this */ - public function mapActions(array $actions, bool $overwrite = false) + public function mapActions(array $actions, bool $overwrite = false): static { $this->setConfig('actionMap', $actions, !$overwrite); @@ -214,9 +210,9 @@ public function mapActions(array $actions, bool $overwrite = false) * @param string ...$actions Controller action to authorize against table policy. * @return $this */ - public function authorizeModel(string ...$actions) + public function authorizeModel(string ...$actions): static { - $this->_config['authorizeModel'] = array_merge($this->_config['authorizeModel'], $actions); + $this->config['authorizeModel'] = array_merge($this->config['authorizeModel'], $actions); return $this; } diff --git a/src/Exception/AuthorizationRequiredException.php b/src/Exception/AuthorizationRequiredException.php index 5f528e5..9a63e26 100644 --- a/src/Exception/AuthorizationRequiredException.php +++ b/src/Exception/AuthorizationRequiredException.php @@ -24,5 +24,5 @@ class AuthorizationRequiredException extends Exception /** * @inheritDoc */ - protected string $_messageTemplate = 'The request to `%s` did not apply any authorization checks.'; + protected string $messageTemplate = 'The request to `%s` did not apply any authorization checks.'; } diff --git a/src/Exception/ForbiddenException.php b/src/Exception/ForbiddenException.php index 1d14416..5c5f385 100644 --- a/src/Exception/ForbiddenException.php +++ b/src/Exception/ForbiddenException.php @@ -24,35 +24,28 @@ class ForbiddenException extends Exception /** * @inheritDoc */ - protected int $_defaultCode = 403; + protected int $defaultCode = 403; /** * @inheritDoc */ - protected string $_messageTemplate = 'Identity is not authorized to perform `%s` on `%s`.'; - - /** - * Policy check result. - */ - protected ?ResultInterface $result = null; + protected string $messageTemplate = 'Identity is not authorized to perform `%s` on `%s`.'; /** * Constructor * * @param \Authorization\Policy\ResultInterface|null $result Policy check result. * @param array|string $message Either the string of the error message, or an array of attributes - * that are made available in the view, and sprintf()'d into Exception::$_messageTemplate + * that are made available in the view, and sprintf()'d into Exception::$messageTemplate * @param int|null $code The code of the error, is also the HTTP status code for the error. * @param \Throwable|null $previous the previous exception. */ public function __construct( - ?ResultInterface $result = null, + protected ?ResultInterface $result = null, string|array $message = '', ?int $code = null, ?Throwable $previous = null, ) { - $this->result = $result; - parent::__construct($message, $code, $previous); } diff --git a/src/Exception/MissingIdentityException.php b/src/Exception/MissingIdentityException.php index 39e1f8d..b9d81ff 100644 --- a/src/Exception/MissingIdentityException.php +++ b/src/Exception/MissingIdentityException.php @@ -22,10 +22,10 @@ class MissingIdentityException extends Exception /** * @inheritDoc */ - protected int $_defaultCode = 403; + protected int $defaultCode = 403; /** * @inheritDoc */ - protected string $_messageTemplate = 'Identity is not present in `%s` request attribute.'; + protected string $messageTemplate = 'Identity is not present in `%s` request attribute.'; } diff --git a/src/IdentityDecorator.php b/src/IdentityDecorator.php index 424ca38..bad3e10 100644 --- a/src/IdentityDecorator.php +++ b/src/IdentityDecorator.php @@ -30,28 +30,16 @@ */ class IdentityDecorator implements IdentityInterface { - /** - * Identity data - * - * @var \ArrayAccess|array - */ - protected ArrayAccess|array $identity; - - /** - * Authorization Service - */ - protected AuthorizationServiceInterface $authorization; - /** * Constructor * - * @param \Authorization\AuthorizationServiceInterface $service The authorization service. + * @param \Authorization\AuthorizationServiceInterface $authorization The authorization service. * @param \ArrayAccess|array $identity Identity data */ - public function __construct(AuthorizationServiceInterface $service, ArrayAccess|array $identity) - { - $this->authorization = $service; - $this->identity = $identity; + public function __construct( + protected AuthorizationServiceInterface $authorization, + protected ArrayAccess|array $identity, + ) { } /** diff --git a/src/Middleware/AuthorizationMiddleware.php b/src/Middleware/AuthorizationMiddleware.php index 0ef52eb..8cc9652 100644 --- a/src/Middleware/AuthorizationMiddleware.php +++ b/src/Middleware/AuthorizationMiddleware.php @@ -27,8 +27,8 @@ use Authorization\IdentityDecorator; use Authorization\IdentityInterface; use Authorization\Middleware\UnauthorizedHandler\UnauthorizedHandlerTrait; +use Cake\Container\ContainerInterface; use Cake\Core\ContainerApplicationInterface; -use Cake\Core\ContainerInterface; use Cake\Core\InstanceConfigTrait; use Closure; use Psr\Http\Message\ResponseInterface; @@ -62,44 +62,29 @@ class AuthorizationMiddleware implements MiddlewareInterface * * @var array */ - protected array $_defaultConfig = [ + protected array $defaultConfig = [ 'identityDecorator' => null, 'identityAttribute' => 'identity', 'requireAuthorizationCheck' => true, 'unauthorizedHandler' => 'Authorization.Exception', ]; - /** - * Authorization service or application instance. - */ - protected AuthorizationServiceInterface|AuthorizationServiceProviderInterface $subject; - - /** - * The container instance from the application - */ - protected ?ContainerInterface $container = null; - /** * Constructor. * * @param \Authorization\AuthorizationServiceInterface|\Authorization\AuthorizationServiceProviderInterface $subject Authorization service or provider instance. * @param array $config Config array. - * @param \Cake\Core\ContainerInterface|null $container The container instance from the application + * @param \Cake\Container\ContainerInterface|null $container The container instance from the application * @throws \InvalidArgumentException */ public function __construct( - AuthorizationServiceInterface|AuthorizationServiceProviderInterface $subject, + protected AuthorizationServiceInterface|AuthorizationServiceProviderInterface $subject, array $config = [], - ?ContainerInterface $container = null, + protected ?ContainerInterface $container = null, ) { - if ($this->_defaultConfig['identityDecorator'] === null) { - $this->_defaultConfig['identityDecorator'] = interface_exists(AuthenIdentityInterface::class) - ? Identity::class - : IdentityDecorator::class; - } - - $this->subject = $subject; - $this->container = $container; + $this->defaultConfig['identityDecorator'] ??= interface_exists(AuthenIdentityInterface::class) + ? Identity::class + : IdentityDecorator::class; $this->setConfig($config); } @@ -118,7 +103,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface if ($this->subject instanceof ContainerApplicationInterface) { $container = $this->subject->getContainer(); $container->add(AuthorizationService::class, $service); - } elseif ($this->container) { + } elseif ($this->container instanceof ContainerInterface) { $this->container->add(AuthorizationService::class, $service); } diff --git a/src/Middleware/RequestAuthorizationMiddleware.php b/src/Middleware/RequestAuthorizationMiddleware.php index 95a9f41..511b074 100644 --- a/src/Middleware/RequestAuthorizationMiddleware.php +++ b/src/Middleware/RequestAuthorizationMiddleware.php @@ -47,7 +47,7 @@ class RequestAuthorizationMiddleware implements MiddlewareInterface * * @var array */ - protected array $_defaultConfig = [ + protected array $defaultConfig = [ 'authorizationAttribute' => 'authorization', 'identityAttribute' => 'identity', 'method' => 'access', diff --git a/src/Middleware/UnauthorizedHandler/RedirectHandler.php b/src/Middleware/UnauthorizedHandler/RedirectHandler.php index 9a302c2..6a7228b 100644 --- a/src/Middleware/UnauthorizedHandler/RedirectHandler.php +++ b/src/Middleware/UnauthorizedHandler/RedirectHandler.php @@ -78,18 +78,12 @@ public function handle( * Checks if an exception matches one of the classes. * * @param \Authorization\Exception\Exception $exception Exception instance. - * @param array<\Exception> $exceptions A list of exception classes. + * @param array> $exceptions A list of exception classes. * @return bool */ protected function checkException(Exception $exception, array $exceptions): bool { - foreach ($exceptions as $class) { - if ($exception instanceof $class) { - return true; - } - } - - return false; + return array_any($exceptions, fn(string $class) => $exception instanceof $class); } /** diff --git a/src/Policy/Exception/MissingMethodException.php b/src/Policy/Exception/MissingMethodException.php index 22b1893..c29577a 100644 --- a/src/Policy/Exception/MissingMethodException.php +++ b/src/Policy/Exception/MissingMethodException.php @@ -23,5 +23,5 @@ class MissingMethodException extends Exception /** * Template string that has attributes sprintf()'ed into it. */ - protected string $_messageTemplate = 'Method `%s` for invoking action `%s` has not been defined in `%s`.'; + protected string $messageTemplate = 'Method `%s` for invoking action `%s` has not been defined in `%s`.'; } diff --git a/src/Policy/Exception/MissingPolicyException.php b/src/Policy/Exception/MissingPolicyException.php index 8885ba1..b08b573 100644 --- a/src/Policy/Exception/MissingPolicyException.php +++ b/src/Policy/Exception/MissingPolicyException.php @@ -25,11 +25,11 @@ class MissingPolicyException extends Exception /** * Template string that has attributes sprintf()'ed into it. */ - protected string $_messageTemplate = 'Policy for `%s` has not been defined.'; + protected string $messageTemplate = 'Policy for `%s` has not been defined.'; /** * @param object|array|string $resource Either the resource instance, a string of the error message, or an array of attributes - * that are made available in the view, and sprintf()'d into Exception::$_messageTemplate + * that are made available in the view, and sprintf()'d into Exception::$messageTemplate * @param int|null $code The code of the error, is also the HTTP status code for the error. * @param \Throwable|null $previous the previous exception. */ @@ -43,7 +43,7 @@ public function __construct(object|string|array $resource, ?int $code = null, ?T $resource->getRepository() instanceof RepositoryInterface ) { $repositoryClass = $resource->getRepository()::class; - $resource = sprintf($this->_messageTemplate, $resourceClass); + $resource = sprintf($this->messageTemplate, $resourceClass); $queryMessage = ' This resource looks like a `Query`. If you are using `OrmResolver`, ' . 'you should create a new policy class for your `%s` class in `src/Policy/`.'; $resource .= sprintf($queryMessage, $repositoryClass); diff --git a/src/Policy/MapResolver.php b/src/Policy/MapResolver.php index 2a9b209..e88794b 100644 --- a/src/Policy/MapResolver.php +++ b/src/Policy/MapResolver.php @@ -17,7 +17,7 @@ namespace Authorization\Policy; use Authorization\Policy\Exception\MissingPolicyException; -use Cake\Core\ContainerInterface; +use Cake\Container\ContainerInterface; use InvalidArgumentException; /** @@ -33,11 +33,6 @@ class MapResolver implements ResolverInterface */ protected array $map = []; - /** - * The DIC instance from the application - */ - protected ?ContainerInterface $container; - /** * Constructor. * @@ -51,11 +46,10 @@ class MapResolver implements ResolverInterface * ``` * * @param array $map Resource class name to policy map. - * @param \Cake\Core\ContainerInterface|null $container The DIC instance from the application + * @param \Cake\Container\ContainerInterface|null $container The DIC instance from the application */ - public function __construct(array $map = [], ?ContainerInterface $container = null) + public function __construct(array $map = [], protected ?ContainerInterface $container = null) { - $this->container = $container; foreach ($map as $resourceClass => $policy) { $this->map($resourceClass, $policy); } @@ -69,7 +63,7 @@ public function __construct(array $map = [], ?ContainerInterface $container = nu * @return $this * @throws \InvalidArgumentException When a resource class does not exist or policy is invalid. */ - public function map(string $resourceClass, callable|object|string $policy) + public function map(string $resourceClass, callable|object|string $policy): static { if (!class_exists($resourceClass)) { $message = sprintf('Resource class `%s` does not exist.', $resourceClass); diff --git a/src/Policy/OrmResolver.php b/src/Policy/OrmResolver.php index a078802..c34047b 100644 --- a/src/Policy/OrmResolver.php +++ b/src/Policy/OrmResolver.php @@ -17,8 +17,8 @@ namespace Authorization\Policy; use Authorization\Policy\Exception\MissingPolicyException; +use Cake\Container\ContainerInterface; use Cake\Core\App; -use Cake\Core\ContainerInterface; use Cake\Datasource\EntityInterface; use Cake\Datasource\QueryInterface; use Cake\Datasource\RepositoryInterface; @@ -30,38 +30,18 @@ */ class OrmResolver implements ResolverInterface { - /** - * Application namespace. - */ - protected string $appNamespace = 'App'; - - /** - * Plugin name overrides. - * - * @var array - */ - protected array $overrides = []; - - /** - * The DIC instance from the application - */ - protected ?ContainerInterface $container; - /** * Constructor * * @param string $appNamespace The application namespace * @param array $overrides A list of plugin name overrides. - * @param \Cake\Core\ContainerInterface|null $container The DIC instance from the application + * @param \Cake\Container\ContainerInterface|null $container The DIC instance from the application */ public function __construct( - string $appNamespace = 'App', - array $overrides = [], - ?ContainerInterface $container = null, + protected string $appNamespace = 'App', + protected array $overrides = [], + protected ?ContainerInterface $container = null, ) { - $this->appNamespace = $appNamespace; - $this->overrides = $overrides; - $this->container = $container; } /** @@ -116,7 +96,14 @@ protected function getEntityPolicy(string $class): mixed { $entityNamespace = '\Model\Entity\\'; $namespace = str_replace('\\', '/', substr($class, 0, (int)strpos($class, $entityNamespace))); - $name = str_replace('\\', '/', substr($class, (int)strpos($class, $entityNamespace) + strlen($entityNamespace))); + $name = str_replace( + '\\', + '/', + substr( + $class, + (int)strpos($class, $entityNamespace) + strlen($entityNamespace), + ), + ); return $this->findPolicy($class, $name, $namespace); } @@ -157,9 +144,7 @@ protected function findPolicy(string $class, string $name, string $namespace): m } // Check the application/plugin. - if ($policyClass === null) { - $policyClass = App::className($namespace . '.' . $name, 'Policy', 'Policy'); - } + $policyClass ??= App::className($namespace . '.' . $name, 'Policy', 'Policy'); if ($policyClass === null) { throw new MissingPolicyException([$class]); diff --git a/src/Policy/ResolverCollection.php b/src/Policy/ResolverCollection.php index 339c56c..22a01c4 100644 --- a/src/Policy/ResolverCollection.php +++ b/src/Policy/ResolverCollection.php @@ -67,7 +67,7 @@ public function __construct(array $resolvers = []) * @param \Authorization\Policy\ResolverInterface $resolver Resolver instance. * @return $this */ - public function add(ResolverInterface $resolver) + public function add(ResolverInterface $resolver): static { $this->resolvers[] = $resolver; diff --git a/src/Policy/Result.php b/src/Policy/Result.php index 510f06a..f86497a 100644 --- a/src/Policy/Result.php +++ b/src/Policy/Result.php @@ -21,11 +21,6 @@ */ class Result implements ResultInterface { - /** - * Check status. - */ - protected bool $status; - /** * Failure reason. */ @@ -37,9 +32,8 @@ class Result implements ResultInterface * @param bool $status Check status. * @param string|null $reason Failure reason. */ - public function __construct(bool $status, ?string $reason = null) + public function __construct(protected bool $status, ?string $reason = null) { - $this->status = $status; if ($reason !== null) { $this->reason = $reason; } diff --git a/tests/TestCase/Middleware/AuthorizationMiddlewareTest.php b/tests/TestCase/Middleware/AuthorizationMiddlewareTest.php index bc50c7d..4114199 100644 --- a/tests/TestCase/Middleware/AuthorizationMiddlewareTest.php +++ b/tests/TestCase/Middleware/AuthorizationMiddlewareTest.php @@ -24,7 +24,7 @@ use Authorization\IdentityDecorator; use Authorization\IdentityInterface; use Authorization\Middleware\AuthorizationMiddleware; -use Cake\Core\Container; +use Cake\Container\Container; use Cake\Http\Response; use Cake\Http\ServerRequest; use Cake\Http\ServerRequestFactory; @@ -65,7 +65,7 @@ public function testInvokeAuthorizationRequiredError(): void ->method('authorizationChecked') ->willReturn(false); - $request = (new ServerRequest())->withAttribute('identity', ['id' => 1]); + $request = new ServerRequest()->withAttribute('identity', ['id' => 1]); $handler = new TestRequestHandler(); $middleware = new AuthorizationMiddleware($service, [ @@ -111,7 +111,7 @@ public function testInvokeServiceWithIdentity(): void ]); $service = $this->createStub(AuthorizationServiceInterface::class); - $request = (new ServerRequest())->withAttribute('identity', $identity); + $request = new ServerRequest()->withAttribute('identity', $identity); $handler = new TestRequestHandler(function ($request) use ($service): Response { $this->assertInstanceOf(RequestInterface::class, $request); $this->assertSame($service, $request->getAttribute('authorization')); @@ -135,7 +135,7 @@ public function testIdentityInstance(): void 'id' => 1, ]); - $request = (new ServerRequest())->withAttribute('identity', $identity); + $request = new ServerRequest()->withAttribute('identity', $identity); $handler = new TestRequestHandler(function ($request) use ($service, $identity): Response { $this->assertInstanceOf(RequestInterface::class, $request); $this->assertSame($service, $request->getAttribute('authorization')); @@ -156,7 +156,7 @@ public function testCustomIdentity(): void ]; $service = $this->createStub(AuthorizationServiceInterface::class); - $request = (new ServerRequest())->withAttribute('user', $identity); + $request = new ServerRequest()->withAttribute('user', $identity); $handler = new TestRequestHandler(function ($request) use ($service): Response { $this->assertInstanceOf(RequestInterface::class, $request); $this->assertSame($service, $request->getAttribute('authorization')); @@ -184,7 +184,7 @@ public function testCustomIdentityDecorator(): void ]); $service = $this->createStub(AuthorizationServiceInterface::class); - $request = (new ServerRequest())->withAttribute('identity', $identity); + $request = new ServerRequest()->withAttribute('identity', $identity); $handler = new TestRequestHandler(function ($request) use ($service, $identity): Response { $this->assertInstanceOf(RequestInterface::class, $request); $this->assertSame($service, $request->getAttribute('authorization')); @@ -213,7 +213,7 @@ public function testInvalidIdentity(): void ]; $service = $this->createStub(AuthorizationServiceInterface::class); - $request = (new ServerRequest())->withAttribute('identity', $identity); + $request = new ServerRequest()->withAttribute('identity', $identity); $handler = new TestRequestHandler(); $middleware = new AuthorizationMiddleware($service, [ @@ -326,7 +326,7 @@ public function testRequireAuthorizationCheckCallableReturnsTrue(): void ->method('authorizationChecked') ->willReturn(false); - $request = (new ServerRequest())->withAttribute('identity', ['id' => 1]); + $request = new ServerRequest()->withAttribute('identity', ['id' => 1]); $handler = new TestRequestHandler(); $middleware = new AuthorizationMiddleware($service, [ @@ -344,7 +344,7 @@ public function testRequireAuthorizationCheckCallableReturnsFalse(): void $service->expects($this->never()) ->method('authorizationChecked'); - $request = (new ServerRequest())->withAttribute('identity', ['id' => 1]); + $request = new ServerRequest()->withAttribute('identity', ['id' => 1]); $handler = new TestRequestHandler(); $middleware = new AuthorizationMiddleware($service, [ diff --git a/tests/TestCase/Middleware/RequestAuthorizationMiddlewareTest.php b/tests/TestCase/Middleware/RequestAuthorizationMiddlewareTest.php index b03bcc5..2c7e1e0 100644 --- a/tests/TestCase/Middleware/RequestAuthorizationMiddlewareTest.php +++ b/tests/TestCase/Middleware/RequestAuthorizationMiddlewareTest.php @@ -45,9 +45,9 @@ public function testRuntimeExceptionWhenServiceIsMissing(): void public function testInvokeService(): void { - $request = (new ServerRequest([ + $request = new ServerRequest([ 'url' => '/articles/index', - ])) + ]) ->withParam('action', 'index') ->withParam('controller', 'Articles'); @@ -79,9 +79,9 @@ public function testInvokeService(): void public function testInvokeServiceWithResult(): void { - $request = (new ServerRequest([ + $request = new ServerRequest([ 'url' => '/articles/index', - ])) + ]) ->withParam('action', 'index') ->withParam('controller', 'Articles'); @@ -124,9 +124,9 @@ public function testInvokeServiceWithResult(): void public function testUnauthorizedHandlerSuppress(): void { - $request = (new ServerRequest([ + $request = new ServerRequest([ 'url' => '/articles/index', - ])) + ]) ->withParam('action', 'add') ->withParam('controller', 'Articles'); @@ -149,9 +149,9 @@ public function testUnauthorizedHandlerSuppress(): void public function testPolicyExceptionRoutedThroughUnauthorizedHandler(): void { - $request = (new ServerRequest([ + $request = new ServerRequest([ 'url' => '/articles/index', - ])) + ]) ->withParam('action', 'index') ->withParam('controller', 'Articles'); diff --git a/tests/TestCase/Policy/MapResolverTest.php b/tests/TestCase/Policy/MapResolverTest.php index 82325fb..ae01f99 100644 --- a/tests/TestCase/Policy/MapResolverTest.php +++ b/tests/TestCase/Policy/MapResolverTest.php @@ -20,7 +20,7 @@ use Authorization\IdentityDecorator; use Authorization\Policy\Exception\MissingPolicyException; use Authorization\Policy\MapResolver; -use Cake\Core\Container; +use Cake\Container\Container; use Cake\TestSuite\TestCase; use InvalidArgumentException; use TestApp\Model\Entity\Article; diff --git a/tests/TestCase/Policy/OrmResolverTest.php b/tests/TestCase/Policy/OrmResolverTest.php index 6ef74a9..86a470c 100644 --- a/tests/TestCase/Policy/OrmResolverTest.php +++ b/tests/TestCase/Policy/OrmResolverTest.php @@ -20,7 +20,7 @@ use Authorization\IdentityDecorator; use Authorization\Policy\Exception\MissingPolicyException; use Authorization\Policy\OrmResolver; -use Cake\Core\Container; +use Cake\Container\Container; use Cake\Datasource\RepositoryInterface; use Cake\ORM\Entity; use Cake\ORM\Locator\LocatorAwareTrait;