diff --git a/.State b/.State deleted file mode 100644 index a604de4..0000000 --- a/.State +++ /dev/null @@ -1 +0,0 @@ -finalized diff --git a/Acl.php b/Source/Acl.php similarity index 78% rename from Acl.php rename to Source/Acl.php index bc7d543..a7d8cfb 100644 --- a/Acl.php +++ b/Source/Acl.php @@ -1,5 +1,7 @@ getGroups()->deleteNode($group, $propagate); @@ -144,7 +132,7 @@ public function deleteGroup(Group $group, $propagate = self::DELETE_RESTRICT) throw new Exception( 'Apparently it is not possible to delete the group %s, ' . 'probably because it has at least one child.', - 42, + 1, $group->getId(), $e ); @@ -156,26 +144,19 @@ public function deleteGroup(Group $group, $propagate = self::DELETE_RESTRICT) /** * Check if a group exists or not, i.e. if a node in the underlying graph * exists. - * - * @param mixed $groupId Group ID. - * @return bool */ - public function groupExists($groupId) + public function groupExists($groupId): bool { return $this->getGroups()->nodeExists($groupId); } /** * Get a specific group, i.e. a specific node in the underlying graph. - * - * @param string $groupId Group ID. - * @return \Hoa\Acl\Group - * @throws \Hoa\Acl\Exception */ - protected function getGroup($groupId) + protected function getGroup(string $groupId): Group { if (false === $this->groupExists($groupId)) { - throw new Exception('Group %s does not exist.', 6, $groupId); + throw new Exception('Group %s does not exist.', 2, $groupId); } return $this->getGroups()->getNode($groupId); @@ -183,23 +164,16 @@ protected function getGroup($groupId) /** * Get all groups, i.e. get the underlying graph. - * - * @return \Hoa\Graph */ - protected function getGroups() + protected function getGroups(): Graph { return $this->_groups; } /** * Attach one or more permissions to a group. - * - * @param Group $group Group. - * @param array $permissions Collection of permissions. - * @return \Hoa\Acl\Acl - * @throws \Hoa\Acl\Exception */ - public function allow(Group $group, array $permissions = []) + public function allow(Group $group, array $permissions = []): self { $id = $group->getId(); @@ -207,7 +181,7 @@ public function allow(Group $group, array $permissions = []) throw new Exception( 'Group %s is not declared in the current ACL instance, ' . 'cannot add permissions.', - 2, + 3, $id ); } @@ -219,13 +193,8 @@ public function allow(Group $group, array $permissions = []) /** * Detach one or more permission to a group. - * - * @param Group $group Group. - * @param array $permissions Collection of permissions. - * @return \Hoa\Acl\Acl - * @throws \Hoa\Acl\Exception */ - public function deny(Group $group, array $permissions = []) + public function deny(Group $group, array $permissions = []): self { $id = $group->getId(); @@ -233,7 +202,7 @@ public function deny(Group $group, array $permissions = []) throw new Exception( 'Group %s is not declared in the current ACL instance, ' . 'cannot delete permissions.', - 3, + 4, $id ); } @@ -245,20 +214,13 @@ public function deny(Group $group, array $permissions = []) /** * Check if a user is allowed to do something according to the permission. - * - * @param mixed $userId User ID (or instance). - * @param mixed $permissionId Permission ID (or instance). - * @param mixed $serviceId Service ID (or instance). - * @param Hoa\Acl\Assertable $assert Assert. - * @return bool - * @throws \Hoa\Acl\Exception */ public function isAllowed( $userId, $permissionId, $serviceId = null, Assertable $assert = null - ) { + ): bool { if ($userId instanceof User) { $userId = $userId->getId(); } @@ -333,10 +295,8 @@ public function isAllowed( /** * Transform the groups to DOT language. - * - * @return string */ - public function __toString() + public function __toString(): string { return $this->getGroups()->__toString(); } @@ -345,4 +305,4 @@ public function __toString() /** * Flex entity. */ -Consistency::flexEntity('Hoa\Acl\Acl'); +Consistency::flexEntity(Acl::class); diff --git a/Assertable.php b/Source/Assertable.php similarity index 84% rename from Assertable.php rename to Source/Assertable.php index e1fe74b..62ecea4 100644 --- a/Assertable.php +++ b/Source/Assertable.php @@ -1,5 +1,7 @@ setId($id); $this->setLabel($label); @@ -105,12 +101,8 @@ public function __construct($id, $label = null) /** * Add users. - * - * @param array $users Users to add. - * @return \Hoa\Acl\Group - * @throws \Hoa\Acl\Exception */ - public function addUsers(array $users = []) + public function addUsers(array $users = []): self { foreach ($users as $user) { if (!($user instanceof User)) { @@ -135,12 +127,8 @@ public function addUsers(array $users = []) /** * Delete users. - * - * @param array $users User to add. - * @return \Hoa\Acl\Group - * @throws \Hoa\Acl\Exception */ - public function deleteUsers(array $users = []) + public function deleteUsers(array $users = []): self { foreach ($users as $user) { if (!($user instanceof User)) { @@ -165,11 +153,8 @@ public function deleteUsers(array $users = []) /** * Check if a user exists or not. - * - * @param muxed $userId User ID (or instance). - * @return bool */ - public function userExists($userId) + public function userExists($userId): bool { if ($userId instanceof User) { $userId = $userId->getId(); @@ -180,12 +165,8 @@ public function userExists($userId) /** * Get a specific user. - * - * @param string $userId User ID. - * @return \Hoa\Acl\User - * @throws \Hoa\Acl\Exception */ - public function getUser($userId) + public function getUser(string $userId): User { if (false === $this->userExists($userId)) { throw new Exception('User %s does not exist.', 2, $userId); @@ -196,22 +177,16 @@ public function getUser($userId) /** * Get all users. - * - * @return array */ - public function getUsers() + public function getUsers(): array { return $this->_users; } /** * Add permissions in this group. - * - * @param array $permissions Permissions to add. - * @return \Hoa\Acl\Group - * @throws \Hoa\Acl\Exception */ - public function addPermissions(array $permissions = []) + public function addPermissions(array $permissions = []): self { foreach ($permissions as $permission) { if (!($permission instanceof Permission)) { @@ -236,12 +211,8 @@ public function addPermissions(array $permissions = []) /** * Delete permissions in this group. - * - * @param array $permissions Permissions to add. - * @return \Hoa\Acl\Group - * @throws \Hoa\Acl\Exception */ - public function deletePermissions(array $permissions = []) + public function deletePermissions(array $permissions = []): self { foreach ($permissions as $permission) { if (!($permission instanceof Permission)) { @@ -266,23 +237,16 @@ public function deletePermissions(array $permissions = []) /** * Check if a permission exists in this group. - * - * @param mixed $permissionId Permission ID. - * @return bool */ - public function permissionExists($permissionId) + public function permissionExists($permissionId): bool { return isset($this->_permissions[$permissionId]); } /** * Get a specific permission of this group. - * - * @param mixed $permissionId Permission ID. - * @return \Hoa\Acl\Permission - * @throws \Hoa\Acl\Exception */ - public function getPermission($permissionId) + public function getPermission($permissionId): Permission { if (false === $this->permissionExists($permissionId)) { throw new Exception( @@ -297,22 +261,16 @@ public function getPermission($permissionId) /** * Get permissions of this group. - * - * @return array */ - public function getPermissions() + public function getPermissions(): array { return $this->_permissions; } /** * Add shared services. - * - * @param array $services Services to add. - * @return \Hoa\Acl\Group - * @throws \Hoa\Acl\Exception */ - public function addServices(array $services = []) + public function addServices(array $services = []): self { foreach ($services as $service) { if (!($service instanceof Service)) { @@ -337,12 +295,8 @@ public function addServices(array $services = []) /** * Delete shared services. - * - * @param array $services Service to add. - * @return \Hoa\Acl\Group - * @throws \Hoa\Acl\Exception */ - public function deleteServices(array $services = []) + public function deleteServices(array $services = []): self { foreach ($services as $service) { if (!($service instanceof Service)) { @@ -367,11 +321,8 @@ public function deleteServices(array $services = []) /** * Check if a shared service exists or not. - * - * @param muxed $serviceId Service ID (or instance). - * @return bool */ - public function serviceExists($serviceId) + public function serviceExists($serviceId): bool { if ($serviceId instanceof Service) { $serviceId = $serviceId->getId(); @@ -382,12 +333,8 @@ public function serviceExists($serviceId) /** * Get a specific shared service. - * - * @param string $serviceId Service ID. - * @return \Hoa\Acl\Service - * @throws \Hoa\Acl\Exception */ - protected function getService($serviceId) + protected function getService(string $serviceId): Service { if (false === $this->serviceExists($serviceId)) { throw new Exception('Service %s does not exist.', 8, $serviceId); @@ -398,19 +345,14 @@ protected function getService($serviceId) /** * Get all shared services. - * - * @return array */ - protected function getServices() + protected function getServices(): array { return $this->_services; } /** * Set group ID. - * - * @param mixed $id Group ID. - * @return mixed */ protected function setId($id) { @@ -422,8 +364,6 @@ protected function setId($id) /** * Get group ID. - * - * @return mixed */ public function getId() { @@ -432,11 +372,8 @@ public function getId() /** * Set group label. - * - * @param string $label Group label. - * @return string */ - public function setLabel($label) + public function setLabel(?string $label): ?string { $old = $this->_label; $this->_label = $label; @@ -446,18 +383,14 @@ public function setLabel($label) /** * Get group label. - * - * @return mixed */ - public function getLabel() + public function getLabel(): ?string { return $this->_label; } /** * Get node ID, i.e. group ID (see `Hoa\Graph\IGraph\Node`). - * - * @return mixed */ public function getNodeId() { diff --git a/Permission.php b/Source/Permission.php similarity index 83% rename from Permission.php rename to Source/Permission.php index bde73a1..db179ed 100644 --- a/Permission.php +++ b/Source/Permission.php @@ -1,5 +1,7 @@ setId($id); $this->setLabel($label); @@ -79,9 +75,6 @@ public function __construct($id, $label = null) /** * Set permission ID. - * - * @param mixed $id Permission ID. - * @return mixed */ protected function setId($id) { @@ -93,8 +86,6 @@ protected function setId($id) /** * Get permission ID. - * - * @return mixed */ public function getId() { @@ -103,11 +94,8 @@ public function getId() /** * Set permission label. - * - * @param string $label Permission label. - * @return string */ - public function setLabel($label) + public function setLabel(?string $label): ?string { $old = $this->_label; $this->_label = $label; @@ -117,10 +105,8 @@ public function setLabel($label) /** * Get permission label. - * - * @return mixed */ - public function getLabel() + public function getLabel(): ?string { return $this->_label; } diff --git a/Service.php b/Source/Service.php similarity index 83% rename from Service.php rename to Source/Service.php index fc5a346..54c6ef4 100644 --- a/Service.php +++ b/Source/Service.php @@ -1,5 +1,7 @@ setId($id); $this->setLabel($label); @@ -79,9 +75,6 @@ public function __construct($id, $label = null) /** * Set service ID. - * - * @param mixed $id Service ID. - * @return mixed */ protected function setId($id) { @@ -93,8 +86,6 @@ protected function setId($id) /** * Get service ID. - * - * @return mixed */ public function getId() { @@ -103,11 +94,8 @@ public function getId() /** * Set service label. - * - * @param string $label Service label. - * @return string */ - public function setLabel($label) + public function setLabel(?string $label): ?string { $old = $this->_label; $this->_label = $label; @@ -117,10 +105,8 @@ public function setLabel($label) /** * Get service label. - * - * @return mixed */ - public function getLabel() + public function getLabel(): ?string { return $this->_label; } diff --git a/User.php b/Source/User.php similarity index 77% rename from User.php rename to Source/User.php index d0f52d9..48648ef 100644 --- a/User.php +++ b/Source/User.php @@ -1,5 +1,7 @@ setId($id); $this->setLabel($label); @@ -86,12 +82,8 @@ public function __construct($id, $label = null) /** * Add services. - * - * @param array $services Services to add. - * @return \Hoa\Acl\User - * @throws \Hoa\Acl\Exception */ - public function addServices(array $services = []) + public function addServices(array $services = []): self { foreach ($services as $service) { if (!($service instanceof Service)) { @@ -116,12 +108,8 @@ public function addServices(array $services = []) /** * Delete services. - * - * @param array $services Service to add. - * @return \Hoa\Acl\User - * @throws \Hoa\Acl\Exception */ - public function deleteServices(array $services = []) + public function deleteServices(array $services = []): self { foreach ($services as $service) { if (!($service instanceof Service)) { @@ -146,11 +134,8 @@ public function deleteServices(array $services = []) /** * Check if a service exists or not. - * - * @param muxed $serviceId Service ID (or instance). - * @return bool */ - public function serviceExists($serviceId) + public function serviceExists($serviceId): bool { if ($serviceId instanceof Service) { $serviceId = $serviceId->getId(); @@ -161,12 +146,8 @@ public function serviceExists($serviceId) /** * Get a specific service. - * - * @param string $serviceId Service ID. - * @return \Hoa\Acl\Service - * @throws \Hoa\Acl\Exception */ - protected function getService($serviceId) + protected function getService(string $serviceId): Service { if (false === $this->serviceExists($serviceId)) { throw new Exception('Service %s does not exist.', 2, $serviceId); @@ -177,19 +158,14 @@ protected function getService($serviceId) /** * Get all services. - * - * @return array */ - protected function getServices() + protected function getServices() : array { return $this->_services; } /** * Set user ID. - * - * @param mixed $id User ID. - * @return mixed */ protected function setId($id) { @@ -201,8 +177,6 @@ protected function setId($id) /** * Get user ID. - * - * @return mixed */ public function getId() { @@ -211,11 +185,8 @@ public function getId() /** * Set user label. - * - * @param string $label User label. - * @return string */ - public function setLabel($label) + public function setLabel(?string $label): ?string { $old = $this->_label; $this->_label = $label; @@ -225,10 +196,8 @@ public function setLabel($label) /** * Get user label. - * - * @return mixed */ - public function getLabel() + public function getLabel(): ?string { return $this->_label; } diff --git a/Test/Integration/Documentation.php b/Test/Integration/Documentation.php index d05d108..097c95d 100644 --- a/Test/Integration/Documentation.php +++ b/Test/Integration/Documentation.php @@ -1,5 +1,7 @@ =5.5.0", - "hoa/consistency": "~1.0", - "hoa/exception" : "~1.0", - "hoa/graph" : "~1.0" + "php" : ">=7.1", + "hoa/consistency": "dev-master", + "hoa/exception" : "dev-master", + "hoa/graph" : "dev-master" }, "require-dev": { - "hoa/test": "~2.0" + "hoa/test": "dev-master" }, "autoload": { "psr-4": { - "Hoa\\Acl\\": "." + "Hoa\\Acl\\" : "Source", + "Hoa\\Acl\\Test\\": "Test" } }, "extra": {