Skip to content

Commit

Permalink
Rector tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
rotimi authored and rotimi committed Apr 14, 2021
1 parent 7a4c6a0 commit af664c0
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 31 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ jobs:

strategy:
matrix:
php: [8.0, 7.4, 7.3, 7.2]
php: [8.0, 7.4, 7.3]
# 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-18.04, ubuntu-20.04]
include:
- os: ubuntu-18.04
php: 7.2
- os: ubuntu-18.04
php: 7.3
- os: ubuntu-18.04
Expand All @@ -36,8 +34,6 @@ jobs:
- os: ubuntu-20.04
php: 8.0
exclude:
- os: ubuntu-20.04
php: 7.2
- os: ubuntu-20.04
php: 7.3

Expand Down Expand Up @@ -73,10 +69,10 @@ jobs:

- name: Run Rector
# Run rector for PHP 7.X but not 8.0, rector is currently blowing up with PHP 8.0
if: matrix.php != '8.0'
#if: matrix.php != '8.0'
run: vendor/bin/rector process src --dry-run

- name: Run Psalm
# Run psalm for PHP 7.4 & 8.0 but not 7.2 & 7.3, psalm is currently blowing up with PHP 7.2 & 7.3
if: matrix.php != '7.2' && matrix.php != '7.3'
#if: matrix.php != '7.2' && matrix.php != '7.3'
run: vendor/bin/psalm
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ A simple, highly flexible and customizable access control package for PHP applic

## Installation

**Via composer:** (Requires PHP 7.2+ or PHP 8.0+).
**Via composer:** (Requires PHP 7.3+ or PHP 8.0+).

composer require rotexsoft/versatile-acl

Expand Down
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,22 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.2.0"
"php": ">=7.3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0 || ^8.0",
"phpunit/phpunit": "^9.0",
"php-coveralls/php-coveralls": "^2.0",
"vimeo/psalm": "^4.3 || ^3.8",
"rector/rector": "^0.8.56"
"vimeo/psalm": "^4.3",
"rector/rector": "^0.9"
},
"autoload": {
"classmap": ["src/"]
},
"autoload-dev": {
"classmap": ["src/", "tests/"],
"files": [ ]
},
"scripts": {
"test": "vendor/bin/phpunit --coverage-text"
}
}
5 changes: 4 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
SetList::PHP_73,
//SetList::PHP_74,
//SetList::PHP_80,
SetList::PERFORMANCE,
SetList::DEAD_CODE,
SetList::PSR_4,
SetList::TYPE_DECLARATION,
SetList::TYPE_DECLARATION_STRICT,
]);

// get services (needed for register a single rule)
Expand Down
12 changes: 6 additions & 6 deletions src/GenericBaseCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ abstract class GenericBaseCollection implements CollectionInterface {

/**
* Retrieve an external iterator
*
*
* @link https://php.net/manual/en/iteratoraggregate.getiterator.php
*
* @return Traversable An instance of an object implementing Iterator or Traversable
*
* @return Traversable
*/
public function getIterator() {
public function getIterator(): Traversable {

return new ArrayIterator($this->storage);
}

/**
* Remove an item with the specified key from the collection if it exists and return the removed item or null if it doesn't exist.
*
*
* @param string|int $key
*
*
* @return mixed the removed item
*/
public function removeByKey($key) {
Expand Down
18 changes: 12 additions & 6 deletions src/GenericPermissionableEntitiesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,11 @@ public function has(PermissionableEntityInterface $entity): bool {
* Adds an instance of PermissionableEntityInterface to an instance of this class
*
* @param PermissionableEntityInterface $permissionEntity
* @psalm-suppress MethodSignatureMismatch
*
* @return $this
*/
public function add(PermissionableEntityInterface $permissionEntity): PermissionableEntitiesCollectionInterface {
public function add(PermissionableEntityInterface $permissionEntity): self {

if( !$this->has($permissionEntity) ) {

Expand Down Expand Up @@ -86,10 +87,11 @@ public function getKey(PermissionableEntityInterface $entity) {
* Removes an instance of PermissionableEntityInterface from an instance of this class.
*
* @param PermissionableEntityInterface $permissionEntity
* @psalm-suppress MethodSignatureMismatch
*
* @return $this
*/
public function remove(PermissionableEntityInterface $permissionEntity): PermissionableEntitiesCollectionInterface {
public function remove(PermissionableEntityInterface $permissionEntity): self {

$key = $this->getKey($permissionEntity);

Expand All @@ -103,9 +105,11 @@ public function remove(PermissionableEntityInterface $permissionEntity): Permiss
/**
* Remove all items in the collection and return $this
*
* @psalm-suppress MethodSignatureMismatch
*
* @return $this
*/
public function removeAll(): PermissionableEntitiesCollectionInterface {
public function removeAll(): self {

$this->storage = [];

Expand All @@ -117,10 +121,10 @@ public function removeAll(): PermissionableEntitiesCollectionInterface {
*
* @param PermissionableEntityInterface $permissionEntity
* @param string $key specified key for $permissionEntity in the collection
*
* @psalm-suppress MethodSignatureMismatch
* @return $this
*/
public function put(PermissionableEntityInterface $permissionEntity, string $key): PermissionableEntitiesCollectionInterface {
public function put(PermissionableEntityInterface $permissionEntity, string $key): self {

$this->storage[$key] = $permissionEntity;

Expand Down Expand Up @@ -156,9 +160,11 @@ public function get(string $key): ?PermissionableEntityInterface {
* considered to be respectively less than, equal to,
* or greater than the second.
*
* @psalm-suppress MethodSignatureMismatch
*
* @return $this
*/
public function sort(callable $comparator = null): PermissionableEntitiesCollectionInterface {
public function sort(callable $comparator = null): self {

if( $comparator === null ) {

Expand Down
13 changes: 9 additions & 4 deletions src/GenericPermissionsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ public function isAllowed(string $action, string $resource, callable $additional
* Adds an instance of PermissionInterface to an instance of this class.
*
* @param PermissionInterface $permission
* @psalm-suppress MethodSignatureMismatch
*
* @return $this
*/
public function add(PermissionInterface $permission): PermissionsCollectionInterface {
public function add(PermissionInterface $permission): self {

if( !$this->hasPermission($permission) ) {

Expand Down Expand Up @@ -133,10 +134,11 @@ public function getKey(PermissionInterface $permission) {
* Removes an instance of PermissionInterface from an instance of this class.
*
* @param PermissionInterface $permission
* @psalm-suppress MethodSignatureMismatch
*
* @return $this
*/
public function remove(PermissionInterface $permission): PermissionsCollectionInterface {
public function remove(PermissionInterface $permission): self {

$key = $this->getKey($permission);

Expand All @@ -148,10 +150,11 @@ public function remove(PermissionInterface $permission): PermissionsCollectionIn

/**
* Remove all items in the collection and return $this
* @psalm-suppress MethodSignatureMismatch
*
* @return $this
*/
public function removeAll(): PermissionsCollectionInterface {
public function removeAll(): self {

$this->storage = [];

Expand All @@ -163,10 +166,11 @@ public function removeAll(): PermissionsCollectionInterface {
*
* @param PermissionInterface $permission
* @param string $key specified key for $permission in the collection
* @psalm-suppress MethodSignatureMismatch
*
* @return $this
*/
public function put(PermissionInterface $permission, string $key): PermissionsCollectionInterface {
public function put(PermissionInterface $permission, string $key): self {

$this->storage[$key] = $permission;

Expand Down Expand Up @@ -208,6 +212,7 @@ public function get(string $key): ?PermissionInterface {
* @noRector
* @return $this
* @noinspection PhpDocSignatureInspection
* @psalm-suppress MethodSignatureMismatch
*/
public function sort(callable $comparator = null): PermissionsCollectionInterface {

Expand Down
4 changes: 2 additions & 2 deletions src/interfaces/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ interface CollectionInterface extends Countable, IteratorAggregate {

/**
* Remove an item with the specified key from the collection if it exists and return the removed item or null if it doesn't exist.
*
*
* @param string|int $key
*
*
* @return mixed the removed item
*/
public function removeByKey($key);
Expand Down

0 comments on commit af664c0

Please sign in to comment.