Skip to content

Commit e0532b9

Browse files
committed
Minimum PHP 8.2 refactoring
1 parent 4623b6e commit e0532b9

20 files changed

+107
-46
lines changed

.github/workflows/php.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
php: [8.4, 8.3, 8.2, 8.1]
19+
php: [8.5, 8.4, 8.3, 8.2]
2020
# prefer-lowest is causing unit tests to fail when php 7.2 is run against PHPunit 7.x,
2121
# PHPUnit 8.x is the latest stable release that supports PHP 7.2 and that runs fine
2222
# dependency-version: [prefer-lowest, prefer-stable]
@@ -39,7 +39,7 @@ jobs:
3939

4040
steps:
4141
- name: Checkout code
42-
uses: actions/checkout@v4
42+
uses: actions/checkout@v6
4343

4444
- name: Setup PHP
4545
uses: shivammathur/setup-php@v2

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ A simple, highly flexible and customizable access control package for PHP applic
3030
These are the branches in this repository:
3131

3232
- **master:** contains code for the latest major version of this package.
33+
- **5.x:** contains code for the **5.x** version of this package. No new features, only bug fixes.
3334
- **4.x:** contains code for the **4.x** version of this package. No new features, only bug fixes.
3435
- **1.X:** contains code for the **1.X** version of this package. Abandoned.
3536

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@
1919
"minimum-stability": "dev",
2020
"prefer-stable": true,
2121
"require": {
22-
"php": ">=8.1.0"
22+
"php": ">=8.2.0"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "^10.0",
26-
"php-coveralls/php-coveralls": "^2.0",
27-
"vimeo/psalm": "^5.4 || ^6.0.0",
28-
"rector/rector": "^1.0.0"
25+
"rector/rector": "^2.0",
26+
"vimeo/psalm" : "^6.0.0",
27+
"phpunit/phpunit": "^12.0 || ^11.0",
28+
"php-coveralls/php-coveralls": "^2.0"
2929
},
3030
"autoload": {
3131
"classmap": ["src/"]
@@ -35,8 +35,8 @@
3535
"files": [ ]
3636
},
3737
"scripts": {
38-
"test": "vendor/bin/phpunit --coverage-text",
39-
"rector": "vendor/bin/rector process src --dry-run -vvv",
38+
"test": "vendor/bin/phpunit --coverage-text --display-all-issues",
39+
"rector": "vendor/bin/rector process src --dry-run",
4040
"psalm": "vendor/bin/psalm --clear-cache && vendor/bin/psalm",
4141
"qa": "composer test && composer rector && composer psalm"
4242
}

rector.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@
2525
$rectorConfigurator->import(SetList::PHP_74);
2626
$rectorConfigurator->import(SetList::PHP_80);
2727
$rectorConfigurator->import(SetList::PHP_81);
28+
$rectorConfigurator->import(SetList::PHP_82);
2829
$rectorConfigurator->import(SetList::DEAD_CODE);
30+
//$rectorConfigurator->import(SetList::CODE_QUALITY); // causing too much logic refactoring that may break existing functionality
2931
$rectorConfigurator->import(SetList::TYPE_DECLARATION);
3032

3133
$skipables = [
3234
//\Rector\CodeQuality\Rector\If_\ShortenElseIfRector::class,
3335
//\Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector::class,
3436
//\Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector::class,
3537
\Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector::class,
38+
\Rector\DeadCode\Rector\Concat\RemoveConcatAutocastRector::class,
3639
];
3740

3841
$rectorConfigurator->skip($skipables);

src/GenericBaseCollection.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ abstract class GenericBaseCollection implements CollectionInterface {
2323
*
2424
* @link https://php.net/manual/en/iteratoraggregate.getiterator.php
2525
*/
26+
#[\Override]
2627
public function getIterator(): Traversable {
2728

2829
return new ArrayIterator($this->storage);
@@ -35,6 +36,7 @@ public function getIterator(): Traversable {
3536
*
3637
* @return mixed the removed item
3738
*/
39+
#[\Override]
3840
public function removeByKey($key) {
3941

4042
$item = null;
@@ -55,6 +57,7 @@ public function removeByKey($key) {
5557
*
5658
* @psalm-suppress RedundantConditionGivenDocblockType
5759
*/
60+
#[\Override]
5861
public function keyExists($key): bool {
5962

6063
return (is_int($key) || is_string($key)) && array_key_exists($key, $this->storage);
@@ -67,6 +70,7 @@ public function keyExists($key): bool {
6770
*
6871
* @return int The custom count as an integer.
6972
*/
73+
#[\Override]
7074
public function count(): int {
7175

7276
return count($this->storage);

src/GenericPermission.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use function str_replace;
1212
use function var_export;
1313

14+
/**
15+
* @psalm-suppress ClassMustBeFinal
16+
*/
1417
class GenericPermission implements PermissionInterface {
1518

1619
protected string $action = '';
@@ -38,7 +41,7 @@ class GenericPermission implements PermissionInterface {
3841
* You must add default values for each parameter the callback accepts.
3942
* @param mixed ...$argsForCallback zero or more arguments to be used to invoke $additionalAssertions
4043
*/
41-
public function __construct(string $action, string $resource, protected bool $allowActionOnResource = true, callable $additionalAssertions = null, mixed ...$argsForCallback) {
44+
public function __construct(string $action, string $resource, protected bool $allowActionOnResource = true, ?callable $additionalAssertions = null, mixed ...$argsForCallback) {
4245

4346
$this->action = Utils::strToLower($action);
4447
$this->resource = Utils::strToLower($resource);
@@ -53,6 +56,7 @@ public function __construct(string $action, string $resource, protected bool $a
5356
*
5457
* @return PermissionsCollectionInterface a new and empty collection that is meant to house one or more instances of PermissionInterface
5558
*/
59+
#[\Override]
5660
public static function createCollection(PermissionInterface ...$permissions): PermissionsCollectionInterface {
5761

5862
return new GenericPermissionsCollection(...$permissions);
@@ -65,6 +69,7 @@ public static function createCollection(PermissionInterface ...$permissions): Pe
6569
*
6670
* @return string a string representing an action that can be performed on a resource in the system
6771
*/
72+
#[\Override]
6873
public function getAction(): string {
6974

7075
return $this->action;
@@ -80,6 +85,7 @@ public function getAction(): string {
8085
*
8186
* @return string a string value that represents all actions that can be performed on all resources in the system.
8287
*/
88+
#[\Override]
8389
public static function getAllActionsIdentifier(): string {
8490

8591
return '*';
@@ -92,6 +98,7 @@ public static function getAllActionsIdentifier(): string {
9298
*
9399
* @return string a string representing a resource in the system
94100
*/
101+
#[\Override]
95102
public function getResource(): string {
96103

97104
return $this->resource;
@@ -107,6 +114,7 @@ public function getResource(): string {
107114
*
108115
* @return string a string value that represents all resources in the system.
109116
*/
117+
#[\Override]
110118
public static function getAllResourcesIdentifier(): string {
111119

112120
return '*';
@@ -119,6 +127,7 @@ public static function getAllResourcesIdentifier(): string {
119127
*
120128
* @return bool a boolean value indicating whether or not an instance of this class signifies that an action can be performed on a resource.
121129
*/
130+
#[\Override]
122131
public function getAllowActionOnResource(): bool {
123132

124133
return $this->allowActionOnResource;
@@ -131,6 +140,7 @@ public function getAllowActionOnResource(): bool {
131140
*
132141
* @return $this
133142
*/
143+
#[\Override]
134144
public function setAllowActionOnResource(bool $allowActionOnResource): PermissionInterface {
135145

136146
$this->allowActionOnResource = $allowActionOnResource;
@@ -155,7 +165,8 @@ public function setAllowActionOnResource(bool $allowActionOnResource): Permissio
155165
*
156166
* @return bool return true if an instance of this class signifies that a specified action can be performed on a specified resource, or false otherwise
157167
*/
158-
public function isAllowed(string $action, string $resource, callable $additionalAssertions = null, mixed ...$argsForCallback): bool {
168+
#[\Override]
169+
public function isAllowed(string $action, string $resource, ?callable $additionalAssertions = null, mixed ...$argsForCallback): bool {
159170

160171
if( $additionalAssertions === null && $this->additionalAssertions !== null ) {
161172

@@ -197,6 +208,7 @@ public function isAllowed(string $action, string $resource, callable $additional
197208
*
198209
*
199210
*/
211+
#[\Override]
200212
public function isEqualTo(PermissionInterface $permission): bool {
201213

202214
return Utils::strSameIgnoreCase($this->getAction(), $permission->getAction())

src/GenericPermissionableEntitiesCollection.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
/**
1313
* @property PermissionableEntityInterface[] $storage
14+
* @psalm-suppress ClassMustBeFinal
1415
*/
1516
class GenericPermissionableEntitiesCollection extends GenericBaseCollection implements PermissionableEntitiesCollectionInterface {
1617

@@ -34,6 +35,7 @@ public function __construct(PermissionableEntityInterface ...$permissionEntities
3435
*
3536
* @return bool true if there is another entity `$x` in the current instance where $x->isEqualTo($entity) === true, otherwise return false
3637
*/
38+
#[\Override]
3739
public function has(PermissionableEntityInterface $entity): bool {
3840

3941
/** @var PermissionableEntityInterface $other_entity **/
@@ -52,6 +54,7 @@ public function has(PermissionableEntityInterface $entity): bool {
5254
*
5355
* @return $this
5456
*/
57+
#[\Override]
5558
public function add(PermissionableEntityInterface $permissionEntity): PermissionableEntitiesCollectionInterface {
5659

5760
if( !$this->has($permissionEntity) ) {
@@ -74,6 +77,7 @@ public function add(PermissionableEntityInterface $permissionEntity): Permission
7477
*
7578
* @return string|int|null
7679
*/
80+
#[\Override]
7781
public function getKey(PermissionableEntityInterface $entity) {
7882

7983
/** @var PermissionableEntityInterface $other_entity **/
@@ -92,6 +96,7 @@ public function getKey(PermissionableEntityInterface $entity) {
9296
*
9397
* @return $this
9498
*/
99+
#[\Override]
95100
public function remove(PermissionableEntityInterface $permissionEntity): PermissionableEntitiesCollectionInterface {
96101

97102
$key = $this->getKey($permissionEntity);
@@ -109,6 +114,7 @@ public function remove(PermissionableEntityInterface $permissionEntity): Permiss
109114
*
110115
* @return $this
111116
*/
117+
#[\Override]
112118
public function removeAll(): PermissionableEntitiesCollectionInterface {
113119

114120
$this->storage = [];
@@ -124,6 +130,7 @@ public function removeAll(): PermissionableEntitiesCollectionInterface {
124130
*
125131
* @return $this
126132
*/
133+
#[\Override]
127134
public function put(PermissionableEntityInterface $permissionEntity, string $key): PermissionableEntitiesCollectionInterface {
128135

129136
$this->storage[$key] = $permissionEntity;
@@ -135,6 +142,7 @@ public function put(PermissionableEntityInterface $permissionEntity, string $key
135142
* Retrieves the entity in the collection associated with the specified key.
136143
* If the key is not present in the collection, NULL should be returned
137144
*/
145+
#[\Override]
138146
public function get(string $key): ?PermissionableEntityInterface {
139147

140148
return array_key_exists($key, $this->storage) ? $this->storage[$key] : null;
@@ -159,7 +167,8 @@ public function get(string $key): ?PermissionableEntityInterface {
159167
*
160168
* @return $this
161169
*/
162-
public function sort(callable $comparator = null): PermissionableEntitiesCollectionInterface {
170+
#[\Override]
171+
public function sort(?callable $comparator = null): PermissionableEntitiesCollectionInterface {
163172

164173
if( $comparator === null ) {
165174

@@ -199,6 +208,7 @@ public function sort(callable $comparator = null): PermissionableEntitiesCollect
199208
*
200209
* @return PermissionableEntityInterface|null an entity that matches the specified $entityId or NULL if such an entity was not found in the collection
201210
*/
211+
#[\Override]
202212
public function find(string $entityId): ?PermissionableEntityInterface {
203213

204214
/** @var PermissionableEntityInterface $entity */

0 commit comments

Comments
 (0)