Skip to content

Commit

Permalink
PHP 8.1 minimum version prep
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi committed Mar 13, 2024
1 parent 8f874f3 commit 6480f56
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 54 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ jobs:

strategy:
matrix:
php: [8.3, 8.2, 8.1, 8.0, 7.4]
php: [8.3, 8.2, 8.1]
# prefer-lowest is causing unit tests to fail when php 7.2 is run against PHPunit 7.x,
# PHPUnit 8.x is the latest stable release that supports PHP 7.2 and that runs fine
# dependency-version: [prefer-lowest, prefer-stable]
dependency-version: [prefer-stable]
os: [ubuntu-20.04, ubuntu-22.04]
include:
- os: ubuntu-20.04
php: 7.4
- os: ubuntu-20.04
php: 8.0
- os: ubuntu-20.04
php: 8.1
- os: ubuntu-22.04
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.4.0"
"php": ">=8.1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^10.0",
"php-coveralls/php-coveralls": "^2.0",
"vimeo/psalm": "^5.4",
"rector/rector": "^1.0.0"
Expand Down
12 changes: 7 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./tests/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude/>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage" lowUpperBound="35" highLowerBound="70"/>
Expand All @@ -18,4 +14,10 @@
<logging>
<junit outputFile="build/logs/junit.xml"/>
</logging>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
<exclude/>
</source>
</phpunit>
10 changes: 2 additions & 8 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
$rectorConfigurator->import(SetList::PHP_72);
$rectorConfigurator->import(SetList::PHP_73);
$rectorConfigurator->import(SetList::PHP_74);
//$containerConfigurator->import(SetList::PHP_80);
//$containerConfigurator->import(SetList::PHP_81);
$rectorConfigurator->import(SetList::PHP_80);
$rectorConfigurator->import(SetList::PHP_81);
$rectorConfigurator->import(SetList::DEAD_CODE);
//$rectorConfigurator->import(SetList::PSR_4);
$rectorConfigurator->import(SetList::TYPE_DECLARATION);

$skipables = [
Expand All @@ -36,10 +35,5 @@
\Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector::class,
];

if(PHP_MAJOR_VERSION < 8) {

$skipables[] = \Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector::class;
}

$rectorConfigurator->skip($skipables);
};
7 changes: 2 additions & 5 deletions src/GenericPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class GenericPermission implements PermissionInterface {

protected string $resource = '';

protected bool $allowActionOnResource = true;

/**
*
* @var callable|null
Expand All @@ -40,11 +38,10 @@ class GenericPermission implements PermissionInterface {
* You must add default values for each parameter the callback accepts.
* @param mixed ...$argsForCallback zero or more arguments to be used to invoke $additionalAssertions
*/
public function __construct(string $action, string $resource, bool $allowActionOnResource = true, callable $additionalAssertions = null, ...$argsForCallback) {
public function __construct(string $action, string $resource, protected bool $allowActionOnResource = true, callable $additionalAssertions = null, mixed ...$argsForCallback) {

$this->action = Utils::strToLower($action);
$this->resource = Utils::strToLower($resource);
$this->allowActionOnResource = $allowActionOnResource;
$this->additionalAssertions = $additionalAssertions;
$this->argsForCallback = $argsForCallback;
}
Expand Down Expand Up @@ -158,7 +155,7 @@ public function setAllowActionOnResource(bool $allowActionOnResource): Permissio
*
* @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
*/
public function isAllowed(string $action, string $resource, callable $additionalAssertions = null, ...$argsForCallback): bool {
public function isAllowed(string $action, string $resource, callable $additionalAssertions = null, mixed ...$argsForCallback): bool {

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

Expand Down
2 changes: 1 addition & 1 deletion src/GenericPermissionableEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(string $id, PermissionsCollectionInterface $perms =
if( $trimmedId === '' ) {

throw new EmptyEntityIdException(
"An instance of " . get_class($this)
"An instance of " . static::class
. " cannot be created with an empty `Id`."
);
}
Expand Down
5 changes: 2 additions & 3 deletions src/GenericPermissionsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use VersatileAcl\Interfaces\PermissionInterface;
use VersatileAcl\Interfaces\PermissionsCollectionInterface;
use function array_key_exists;
use function get_class;
use function uasort;

/**
Expand Down Expand Up @@ -64,13 +63,13 @@ public function hasPermission(PermissionInterface $permission): bool {
*
* @return bool return true if one or more items in an instance of this class signifies that a specified action can be performed on a specified resource, or false otherwise
*/
public function isAllowed(string $action, string $resource, callable $additionalAssertions = null, ...$argsForCallback): bool {
public function isAllowed(string $action, string $resource, callable $additionalAssertions = null, mixed ...$argsForCallback): bool {

/** @var PermissionInterface $permission */
foreach ($this->storage as $permission) {

/** @var PermissionInterface $permissionClass */
$permissionClass = get_class($permission); // for late static binding
$permissionClass = $permission::class; // for late static binding

if(
(
Expand Down
38 changes: 16 additions & 22 deletions src/VersatileAcl.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use function array_key_exists;
use function array_shift;
use function func_get_args;
use function get_class;
use function gettype;
use function is_object;
use function is_subclass_of;
Expand Down Expand Up @@ -108,28 +107,28 @@ public function __construct(
if(!is_subclass_of($permissionableEntityInterfaceClassName, PermissionableEntityInterface::class)) {

$this->throwInvalidArgExceptionDueToWrongClassName(
get_class($this), __FUNCTION__, $permissionableEntityInterfaceClassName, PermissionableEntityInterface::class, 'first'
static::class, __FUNCTION__, $permissionableEntityInterfaceClassName, PermissionableEntityInterface::class, 'first'
);
}

if(!is_subclass_of($permissionInterfaceClassName, PermissionInterface::class)) {

$this->throwInvalidArgExceptionDueToWrongClassName(
get_class($this), __FUNCTION__, $permissionInterfaceClassName, PermissionInterface::class, 'second'
static::class, __FUNCTION__, $permissionInterfaceClassName, PermissionInterface::class, 'second'
);
}

if(!is_subclass_of($permissionableEntitiesCollectionInterfaceClassName, PermissionableEntitiesCollectionInterface::class)) {

$this->throwInvalidArgExceptionDueToWrongClassName(
get_class($this), __FUNCTION__, $permissionableEntitiesCollectionInterfaceClassName, PermissionableEntitiesCollectionInterface::class, 'third'
static::class, __FUNCTION__, $permissionableEntitiesCollectionInterfaceClassName, PermissionableEntitiesCollectionInterface::class, 'third'
);
}

if(!is_subclass_of($permissionsCollectionInterfaceClassName, PermissionsCollectionInterface::class)) {

$this->throwInvalidArgExceptionDueToWrongClassName(
get_class($this), __FUNCTION__, $permissionsCollectionInterfaceClassName, PermissionsCollectionInterface::class, 'fourth'
static::class, __FUNCTION__, $permissionsCollectionInterfaceClassName, PermissionsCollectionInterface::class, 'fourth'
);
}

Expand Down Expand Up @@ -164,10 +163,10 @@ public function addEntity(string $entityId): self {

$this->auditActivities
&& $this->logActivity(
"Initialized " . get_class($this)
"Initialized " . static::class
. '::entitiesCollection to a new empty instance of '
. get_class($this->entitiesCollection),
"Initialized " . get_class($this) . '::entitiesCollection'
. $this->entitiesCollection::class,
"Initialized " . static::class . '::entitiesCollection'
);
}

Expand Down Expand Up @@ -285,7 +284,7 @@ public function addParentEntity(string $entityId, string $parentEntityId): self
// We should never really get here in most cases.
// Something weird happened, we could not create or retrieve
// the entity to which a parent is to be added
$class = get_class($this);
$class = static::class;
$function = __FUNCTION__;
$msg = "Error [{$class}::{$function}(...)]:"
. " Could not create or retrieve the entity with an ID of `{$entityId}`"
Expand Down Expand Up @@ -413,13 +412,12 @@ public function getAllEntities() : ?PermissionableEntitiesCollectionInterface {
}

/**
* Add a permission to an entity with the ID value of $entityId.
* Add a permission to an entity with the ID value of $entityId.
* This entity will be created and added to the instance of this class upon
* which this method is being invoked if the entity does not exist.
*
* @param string $entityId the ID of the entity to which the permission is to be added
* @param callable|null $additionalAssertions
* @param mixed $argsForCallback
* @noinspection PhpUnhandledExceptionInspection
* @see PermissionInterface::__construct($action, $resource, $allowActionOnResource, $additionalAssertions, ...$argsForCallback)
* for definitions of all but the first parameter
Expand All @@ -432,7 +430,7 @@ public function addPermission(
string $resource,
bool $allowActionOnResource = true,
callable $additionalAssertions = null,
...$argsForCallback
mixed ...$argsForCallback
): self {

$this->auditActivities
Expand Down Expand Up @@ -493,7 +491,7 @@ public function addPermission(

// We should never really get here in most cases. Something weird happened,
// we could not create or retrieve the entity to which a parent is to be added
$class = get_class($this);
$class = static::class;
$function = __FUNCTION__;
$msg = "Error [{$class}::{$function}(...)]:"
. " Could not create or retrieve the entity with an ID of `{$entityId}`"
Expand Down Expand Up @@ -522,7 +520,6 @@ public function addPermission(
* or return null if either the entity and / or permission do not exist.
*
* @param callable|null $additionalAssertions
* @param mixed $argsForCallback
*
* @noinspection PhpUnhandledExceptionInspection
* @see PermissionInterface::__construct($action, $resource, $allowActionOnResource, $additionalAssertions, $argsForCallback)
Expand All @@ -536,7 +533,7 @@ public function removePermission(
string $resource,
bool $allowActionOnResource = true,
callable $additionalAssertions = null,
...$argsForCallback
mixed ...$argsForCallback
): ?PermissionInterface {

$this->auditActivities
Expand Down Expand Up @@ -630,7 +627,7 @@ public function removePermission(
* @noinspection PhpUnhandledExceptionInspection
* @noinspection PhpDocMissingThrowsInspection
*/
public function isAllowed(string $entityId, string $action, string $resource, callable $additionalAssertions = null, ...$argsForCallback): bool {
public function isAllowed(string $entityId, string $action, string $resource, callable $additionalAssertions = null, mixed ...$argsForCallback): bool {

$this->auditActivities
&& ++$this->numTabsForIndentingAudit // increment on first call to logActivity within a method
Expand Down Expand Up @@ -824,12 +821,11 @@ public function createEntity(string $entityId): PermissionableEntityInterface {
* for definitions of all the parameters of this method
*
* @param callable|null $additionalAssertions
* @param mixed ...$argsForCallback
*
* @psalm-suppress MoreSpecificReturnType
*/
public function createPermission(
string $action, string $resource, bool $allowActionOnResource = true, callable $additionalAssertions = null, ...$argsForCallback
string $action, string $resource, bool $allowActionOnResource = true, callable $additionalAssertions = null, mixed ...$argsForCallback
): PermissionInterface {

$permissionClassName = $this->permissionInterfaceClassName;
Expand Down Expand Up @@ -976,11 +972,9 @@ protected function getMethodParameterNamesAndVals(string $methodName, array $par
/**
* Helper method to describe the value in $returnVal
*
* @param mixed $returnVal
*
* @return string description of the value in $returnVal
*/
protected function formatReturnValueForAudit($returnVal): string {
protected function formatReturnValueForAudit(mixed $returnVal): string {

$returnType = gettype($returnVal);
$formattedSentence =
Expand All @@ -991,7 +985,7 @@ protected function formatReturnValueForAudit($returnVal): string {

$formattedSentence =
" with a return type of `object` that is an instance of"
. " `" . get_class($returnVal) . "` with the following"
. " `" . $returnVal::class . "` with the following"
. " string representation: "
. PHP_EOL
.
Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/PermissionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface PermissionInterface
* @param callable|null $additionalAssertions an optional callback function that must return a boolean further indicating whether or not an action can be performed on the resource.
* @param mixed ...$argsForCallback zero or more arguments to be used to invoke $additionalAssertions
*/
public function __construct(string $action, string $resource, bool $allowActionOnResource=true, callable $additionalAssertions=null, ...$argsForCallback);
public function __construct(string $action, string $resource, bool $allowActionOnResource=true, callable $additionalAssertions=null, mixed ...$argsForCallback);

/**
* Create a new and empty collection that is meant to house one or more instances of PermissionInterface
Expand Down Expand Up @@ -103,7 +103,7 @@ public function setAllowActionOnResource(bool $allowActionOnResource): self;
*
* @return bool return true if an instance of this interface signifies that a specified action can be performed on a specified resource, or false otherwise
*/
public function isAllowed(string $action, string $resource, callable $additionalAssertions=null, ...$argsForCallback): bool;
public function isAllowed(string $action, string $resource, callable $additionalAssertions=null, mixed ...$argsForCallback): bool;

/**
* Checks whether the specified permission object has an equal value to the current instance.
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/PermissionsCollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function hasPermission(PermissionInterface $permission): bool;
*
* @return bool return true if one or more items in an instance of this interface signifies that a specified action can be performed on a specified resource, or false otherwise
*/
public function isAllowed(string $action, string $resource, callable $additionalAssertions=null, ...$argsForCallback): bool;
public function isAllowed(string $action, string $resource, callable $additionalAssertions=null, mixed ...$argsForCallback): bool;

/**
* Sort the collection.
Expand Down

0 comments on commit 6480f56

Please sign in to comment.