Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php /** MicroFileACL */ | ||
| 22 | class FileAcl extends Acl | ||
| 23 | { | ||
| 24 | /** @var array $roles configured roles */ | ||
| 25 | protected $roles; | ||
| 26 | /** @var array $perms configured perms */ | ||
| 27 | protected $perms; | ||
| 28 | /** @var array $rolePermsCompare compare of permissions in roles */ | ||
| 29 | protected $rolePermsCompare; | ||
| 30 | |||
| 31 | |||
| 32 | /** | ||
| 33 | * Configured ACL with files | ||
| 34 | * | ||
| 35 | * @access public | ||
| 36 | * | ||
| 37 | * @param IConnection $db | ||
| 38 | * @param array $params configuration array | ||
| 39 | * | ||
| 40 | * @result void | ||
| 41 | */ | ||
| 42 | public function __construct(IConnection $db, array $params = []) | ||
| 51 | |||
| 52 | /** | ||
| 53 | * Check user access to permission | ||
| 54 | * | ||
| 55 | * @access public | ||
| 56 | * | ||
| 57 | * @param integer $userId user id | ||
| 58 | * @param string $permission checked permission | ||
| 59 | * @param array $data not used, added for compatible! | ||
| 60 | * | ||
| 61 | * @return bool | ||
| 62 | * @throws \Micro\Base\Exception | ||
| 63 | */ | ||
| 64 | public function check($userId, $permission, array $data = []) | ||
| 83 | |||
| 84 | /** | ||
| 85 | * Get assigned elements | ||
| 86 | * | ||
| 87 | * @access public | ||
| 88 | * | ||
| 89 | * @param integer $userId user ID | ||
| 90 | * | ||
| 91 | * @return mixed | ||
| 92 | * @throws \Micro\Base\Exception | ||
| 93 | */ | ||
| 94 | View Code Duplication | public function assigned($userId) | |
| 104 | |||
| 105 | /** | ||
| 106 | * Get permissions in role | ||
| 107 | * | ||
| 108 | * @access private | ||
| 109 | * | ||
| 110 | * @param integer $role role name | ||
| 111 | * | ||
| 112 | * @return array | ||
| 113 | */ | ||
| 114 | protected function rolePerms($role) | ||
| 118 | } | ||
| 119 | 
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.