Skip to content

Commit

Permalink
Rector tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
rotexdegba committed Jan 8, 2022
1 parent ecba721 commit a138e9e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 61 deletions.
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
"files": [ ]
},
"scripts": {
"test": "vendor/bin/phpunit --coverage-text"
"test": "vendor/bin/phpunit --coverage-text",
"rector": "vendor/bin/rector process src --dry-run",
"psalm": "vendor/bin/psalm",
"qa": "composer test && composer rector && composer psalm"
}
}
30 changes: 22 additions & 8 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,33 @@

return static function (ContainerConfigurator $containerConfigurator): void {

// get parameters
//$parameters = $containerConfigurator->parameters();

// Define what rule sets will be applied
$containerConfigurator->import(SetList::DEAD_CODE);

// here we can define, what sets of rules will be applied
// tip: use "SetList" class to autocomplete sets
$containerConfigurator->import(SetList::PHP_52);
$containerConfigurator->import(SetList::PHP_53);
$containerConfigurator->import(SetList::PHP_54);
$containerConfigurator->import(SetList::PHP_55);
$containerConfigurator->import(SetList::PHP_56);
$containerConfigurator->import(SetList::PHP_70);
$containerConfigurator->import(SetList::PHP_71);
$containerConfigurator->import(SetList::PHP_72);
$containerConfigurator->import(SetList::PHP_73);
//$containerConfigurator->import(SetList::PHP_74);
$containerConfigurator->import(SetList::PHP_74);
//$containerConfigurator->import(SetList::PHP_80);
//$containerConfigurator->import(SetList::PHP_81);
$containerConfigurator->import(SetList::DEAD_CODE);
$containerConfigurator->import(SetList::PSR_4);
$containerConfigurator->import(SetList::TYPE_DECLARATION);
$containerConfigurator->import(SetList::TYPE_DECLARATION_STRICT);

// get parameters
//$parameters = $containerConfigurator->parameters();

// register a single rule
//$services = $containerConfigurator->services();
//$services->set(TypedPropertyRector::class);
// get services (needed for register a single rule)
$services = $containerConfigurator->services();

//TODO:PHP8 comment once PHP 8 becomes minimum version
$services->remove(Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector::class);
};
7 changes: 1 addition & 6 deletions src/GenericBaseCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@

abstract class GenericBaseCollection implements CollectionInterface {

/**
*
* @var array
*
*/
protected $storage = [];
protected array $storage = [];

/**
* Retrieve an external iterator
Expand Down
28 changes: 4 additions & 24 deletions src/GenericPermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,11 @@

class GenericPermission implements PermissionInterface {

/**
*
* @var string
*
*/
protected $action = '';
protected string $action = '';

/**
*
* @var string
*
*/
protected $resource = '';
protected string $resource = '';

/**
*
* @var bool
*
*/
protected $allowActionOnResource = true;
protected bool $allowActionOnResource = true;

/**
*
Expand All @@ -41,12 +26,7 @@ class GenericPermission implements PermissionInterface {
*/
protected $additionalAssertions = null;

/**
*
* @var array
*
*/
protected $argsForCallback = [];
protected array $argsForCallback = [];

/**
* PermissionInterface constructor.
Expand Down
29 changes: 7 additions & 22 deletions src/GenericPermissionableEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,11 @@

class GenericPermissionableEntity implements PermissionableEntityInterface {

/**
*
* @var string
*
*/
protected $id;
protected string $id;

/**
*
* @var PermissionsCollectionInterface
*
*/
protected $permissions;
protected \VersatileAcl\Interfaces\PermissionsCollectionInterface $permissions;

/**
*
* @var PermissionableEntitiesCollectionInterface
*
*/
protected $parentEntities;
protected \VersatileAcl\Interfaces\PermissionableEntitiesCollectionInterface $parentEntities;


/**
Expand All @@ -61,8 +46,8 @@ public function __construct(string $id, PermissionsCollectionInterface $perms =
}

$this->id = Utils::strToLower($trimmedId);
$this->permissions = ($perms === null) ? GenericPermission::createCollection() : $perms;
$this->parentEntities = ($parentEntities === null) ? static::createCollection() : $parentEntities;
$this->permissions = $perms ?? GenericPermission::createCollection();
$this->parentEntities = $parentEntities ?? static::createCollection();
}

/**
Expand Down Expand Up @@ -395,7 +380,7 @@ public function getDirectPermissions(): PermissionsCollectionInterface {
public function getInheritedPermissions(PermissionsCollectionInterface $inheritedPerms=null): PermissionsCollectionInterface {

$allParentEntities = $this->getAllParents();
$inheritedPermsToReturn = ($inheritedPerms === null) ? GenericPermission::createCollection() : $inheritedPerms;
$inheritedPermsToReturn = $inheritedPerms ?? GenericPermission::createCollection();

foreach ($allParentEntities as $parent_entity) {
foreach ($parent_entity->getDirectPermissions() as $parent_permission) {
Expand All @@ -417,7 +402,7 @@ public function getInheritedPermissions(PermissionsCollectionInterface $inherite
*/
public function getAllPermissions(bool $directPermissionsFirst=true, PermissionsCollectionInterface $allPerms=null): PermissionsCollectionInterface {

$allPermissions = ($allPerms === null)? GenericPermission::createCollection() : $allPerms;
$allPermissions = $allPerms ?? GenericPermission::createCollection();
$directPerms = $this->getDirectPermissions();
$inheritedPerms = $this->getInheritedPermissions();
$collection1 = $directPerms;
Expand Down

0 comments on commit a138e9e

Please sign in to comment.