From 104d3c967d84a4d82634de0e38a16ee86d0225eb Mon Sep 17 00:00:00 2001 From: Olawale Lawal Date: Tue, 27 Aug 2019 16:35:37 +0100 Subject: [PATCH] (Cleanup): Apply PSR coding convention --- migrations/m151005_151946_install.php | 24 +++++++++++++++---- ...m170914_110639_alter_roles_permissions.php | 1 - src/BasePermissionManager.php | 3 ++- src/DbPermissionManager.php | 21 +++++++++------- src/ManagerInterface.php | 22 ++++++++--------- src/libs/Constants.php | 7 ------ src/models/Permission.php | 2 +- src/models/Role.php | 5 ++-- src/models/RolePermission.php | 2 +- 9 files changed, 50 insertions(+), 37 deletions(-) diff --git a/migrations/m151005_151946_install.php b/migrations/m151005_151946_install.php index 2ca1285..5b58110 100644 --- a/migrations/m151005_151946_install.php +++ b/migrations/m151005_151946_install.php @@ -9,7 +9,6 @@ */ class m151005_151946_install extends Migration { - public function up() { $tableOptions = null; @@ -52,11 +51,28 @@ public function up() ], $tableOptions); // Add Indexes for performance optimization - $this->createIndex('rp_role_id_composite', Constants::TABLE_ROLE_PERMISSIONS, ['role_id', 'permission_id'], true); + $this->createIndex( + 'rp_role_id_composite', + Constants::TABLE_ROLE_PERMISSIONS, + ['role_id', 'permission_id'], + true + ); // Add Foreign Keys - $this->addForeignKey('rp_roles_role_id', Constants::TABLE_ROLE_PERMISSIONS, 'role_id', Constants::TABLE_ROLES, 'id'); - $this->addForeignKey('rp_roles_permission_id', Constants::TABLE_ROLE_PERMISSIONS, 'permission_id', Constants::TABLE_PERMISSIONS, 'id'); + $this->addForeignKey( + 'rp_roles_role_id', + Constants::TABLE_ROLE_PERMISSIONS, + 'role_id', + Constants::TABLE_ROLES, + 'id' + ); + $this->addForeignKey( + 'rp_roles_permission_id', + Constants::TABLE_ROLE_PERMISSIONS, + 'permission_id', + Constants::TABLE_PERMISSIONS, + 'id' + ); } public function down() diff --git a/migrations/m170914_110639_alter_roles_permissions.php b/migrations/m170914_110639_alter_roles_permissions.php index 4cc5462..cf1ce67 100644 --- a/migrations/m170914_110639_alter_roles_permissions.php +++ b/migrations/m170914_110639_alter_roles_permissions.php @@ -51,7 +51,6 @@ public function down() $this->boolean()->defaultValue(1) ); - $this->dropIndex( 'k_' . Constants::TABLE_PERMISSIONS . '_status', Constants::TABLE_PERMISSIONS diff --git a/src/BasePermissionManager.php b/src/BasePermissionManager.php index 1c2d74f..14f7dca 100644 --- a/src/BasePermissionManager.php +++ b/src/BasePermissionManager.php @@ -29,6 +29,7 @@ public function canAccess($permissionKey) } /** + * @param $roleKey * @author Adegoke Obasa */ public function setRoleByKey($roleKey) @@ -38,9 +39,9 @@ public function setRoleByKey($roleKey) } /** - * @author Adegoke Obasa * @param $roleId * @return void + * @author Adegoke Obasa */ public function setRoleById($roleId) { diff --git a/src/DbPermissionManager.php b/src/DbPermissionManager.php index 8055b37..688f3d5 100644 --- a/src/DbPermissionManager.php +++ b/src/DbPermissionManager.php @@ -8,12 +8,13 @@ use cottacush\rbac\libs\Constants; use cottacush\rbac\models\Permission; use cottacush\rbac\models\Role; +use Yii; class DbPermissionManager extends BasePermissionManager { /** - * @author Adegoke Obasa * @return mixed + * @author Adegoke Obasa */ public function getRoles() { @@ -21,9 +22,9 @@ public function getRoles() } /** - * @author Adegoke Obasa * @param $key * @return Role + * @author Adegoke Obasa */ public function getRole($key) { @@ -31,9 +32,9 @@ public function getRole($key) } /** - * @author Adegoke Obasa * @param $roleId * @return Role + * @author Adegoke Obasa */ public function getRoleById($roleId) { @@ -41,8 +42,8 @@ public function getRoleById($roleId) } /** - * @author Adegoke Obasa * @return mixed + * @author Adegoke Obasa */ public function getPermissions() { @@ -50,9 +51,9 @@ public function getPermissions() } /** - * @author Adegoke Obasa * @param $key * @return Permission + * @author Adegoke Obasa */ public function getPermission($key) { @@ -60,27 +61,29 @@ public function getPermission($key) } /** - * @author Adegoke Obasa * @param $permissionId * @return Permission + * @author Adegoke Obasa */ public function getPermissionById($permissionId) { - return Permission::find()->where(['id' => $permissionId, 'status' => Constants::STATUS_ACTIVE])->limit(1)->one(); + return Permission::find()->where(['id' => $permissionId, 'status' => Constants::STATUS_ACTIVE]) + ->limit(1)->one(); } /** - * @author Adegoke Obasa * @return mixed + * @author Adegoke Obasa */ public function getUserRole() { - $role = \Yii::$app->session->get($this->sessionPrefix . '::user_role'); + $role = Yii::$app->session->get($this->sessionPrefix . '::user_role'); return $role; } /** * @inheritdoc + * @throws \yii\base\InvalidConfigException * @author Adegoke Obasa */ public function getUserPermissions() diff --git a/src/ManagerInterface.php b/src/ManagerInterface.php index 347a890..0e594dc 100644 --- a/src/ManagerInterface.php +++ b/src/ManagerInterface.php @@ -10,75 +10,75 @@ interface ManagerInterface { /** * Checks if the user has the specified permission. - * @author Adegoke Obasa * @param $permissionKey * @return mixed + * @author Adegoke Obasa */ public function canAccess($permissionKey); /** - * @author Adegoke Obasa * @return mixed + * @author Adegoke Obasa */ public function getRoles(); /** - * @author Adegoke Obasa * @return mixed + * @author Adegoke Obasa */ public function getUserRole(); /** - * @author Adegoke Obasa * @param $key * @return mixed + * @author Adegoke Obasa */ public function getRole($key); /** - * @author Adegoke Obasa * @param $roleId * @return mixed + * @author Adegoke Obasa */ public function getRoleById($roleId); /** - * @author Adegoke Obasa * @return mixed + * @author Adegoke Obasa */ public function getPermissions(); /** - * @author Adegoke Obasa * @param $key * @return mixed + * @author Adegoke Obasa */ public function getPermission($key); /** - * @author Adegoke Obasa * @param $permissionId * @return mixed + * @author Adegoke Obasa */ public function getPermissionById($permissionId); /** - * @author Adegoke Obasa * @param $roleKey * @return mixed + * @author Adegoke Obasa */ public function setRoleByKey($roleKey); /** - * @author Adegoke Obasa * @param $roleId * @return mixed + * @author Adegoke Obasa */ public function setRoleById($roleId); /** - * @author Adegoke Obasa * @return mixed + * @author Adegoke Obasa */ public function getUserPermissions(); } \ No newline at end of file diff --git a/src/libs/Constants.php b/src/libs/Constants.php index d8b9020..9587bd6 100644 --- a/src/libs/Constants.php +++ b/src/libs/Constants.php @@ -1,14 +1,7 @@ hasMany(RolePermission::className(), ['permission_id' => 'id']); } -} \ No newline at end of file +} diff --git a/src/models/Role.php b/src/models/Role.php index b8004bc..f655979 100644 --- a/src/models/Role.php +++ b/src/models/Role.php @@ -68,8 +68,9 @@ public function getRolePermissions() /** * Get Permissions assigned to role - * @author Adegoke Obasa * @return mixed + * @throws \yii\base\InvalidConfigException + * @author Adegoke Obasa */ public function getPermissions() { @@ -79,4 +80,4 @@ public function getPermissions() ->asArray() ->all(); } -} \ No newline at end of file +} diff --git a/src/models/RolePermission.php b/src/models/RolePermission.php index e040a42..0ca3c02 100644 --- a/src/models/RolePermission.php +++ b/src/models/RolePermission.php @@ -72,4 +72,4 @@ public function getRole() { return $this->hasOne(Role::className(), ['id' => 'role_id']); } -} \ No newline at end of file +}