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 namespace Anomaly\Streams\Platform\Support; |
||
| 9 | class Authorizer |
||
| 10 | { |
||
| 11 | |||
| 12 | /** |
||
| 13 | * The auth utility. |
||
| 14 | * |
||
| 15 | * @var null|Guard |
||
| 16 | */ |
||
| 17 | protected $guard = null; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * The guest role. |
||
| 21 | * |
||
| 22 | * @var RoleInterface |
||
| 23 | */ |
||
| 24 | protected $guest; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * The config repository. |
||
| 28 | * |
||
| 29 | * @var Repository |
||
| 30 | */ |
||
| 31 | protected $config; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * The request object. |
||
| 35 | * |
||
| 36 | * @var Request |
||
| 37 | */ |
||
| 38 | protected $request; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Create a new Authorizer instance. |
||
| 42 | * |
||
| 43 | * @param Guard $guard |
||
| 44 | * @param Repository $config |
||
| 45 | * @param Request $request |
||
| 46 | */ |
||
| 47 | public function __construct(Guard $guard, Repository $config, Request $request) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Authorize a user against a permission. |
||
| 56 | * |
||
| 57 | * @param $permission |
||
| 58 | * @param UserInterface $user |
||
| 59 | * @return bool |
||
| 60 | */ |
||
| 61 | public function authorize($permission, UserInterface $user = null) |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Authorize a user against any permission. |
||
| 84 | * |
||
| 85 | * @param array $permissions |
||
| 86 | * @param UserInterface $user |
||
| 87 | * @param bool $strict |
||
| 88 | * @return bool |
||
| 89 | */ |
||
| 90 | View Code Duplication | public function authorizeAny(array $permissions, UserInterface $user = null, $strict = false) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Authorize a user against all permission. |
||
| 111 | * |
||
| 112 | * @param array $permissions |
||
| 113 | * @param UserInterface $user |
||
| 114 | * @param bool $strict |
||
| 115 | * @return bool |
||
| 116 | */ |
||
| 117 | View Code Duplication | public function authorizeAll(array $permissions, UserInterface $user = null, $strict = false) |
|
| 135 | |||
| 136 | /** |
||
| 137 | * Return a user's permission. |
||
| 138 | * |
||
| 139 | * @param $permission |
||
| 140 | * @param UserInterface $user |
||
| 141 | * @return bool |
||
| 142 | */ |
||
| 143 | protected function checkPermission($permission, UserInterface $user) |
||
| 229 | |||
| 230 | /** |
||
| 231 | * Get the guest role. |
||
| 232 | * |
||
| 233 | * @return RoleInterface |
||
| 234 | */ |
||
| 235 | public function getGuest() |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Set the guest role. |
||
| 242 | * |
||
| 243 | * @param RoleInterface $guest |
||
| 244 | * @return $this |
||
| 245 | */ |
||
| 246 | public function setGuest(RoleInterface $guest) |
||
| 252 | } |
||
| 253 |