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 |
||
| 19 | class CookieFieldStrategy extends AbstractHttpStrategy |
||
| 20 | { |
||
| 21 | /** @var string */ |
||
| 22 | const COOKIE_FIELD_NAME = 'username'; |
||
| 23 | |||
| 24 | /** @var string */ |
||
| 25 | const COOKIE_VALUE_CORE_ID = 'finnova_id'; |
||
| 26 | |||
| 27 | /** @var string */ |
||
| 28 | const CONFIGURATION_PARAMETER_CORE_ID = 'graviton.security.core_id'; |
||
| 29 | |||
| 30 | /** @var string */ |
||
| 31 | const CONFIGURATION_PARAMETER_USER_ID = 'graviton.security.user_id'; |
||
| 32 | |||
| 33 | /** @var string */ |
||
| 34 | protected $field; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param string $field cookie field to be examined |
||
| 38 | */ |
||
| 39 | 4 | public function __construct($field) |
|
| 43 | |||
| 44 | /** |
||
| 45 | * Applies the defined strategy on the provided request. |
||
| 46 | * Value may contain a coma separated string values, we use first as identifier. |
||
| 47 | * |
||
| 48 | * @param Request $request request to handle |
||
| 49 | * |
||
| 50 | * @return string |
||
| 51 | */ |
||
| 52 | 2 | public function apply(Request $request) |
|
| 61 | |||
| 62 | /** |
||
| 63 | * Provides the list of registered roles. |
||
| 64 | * |
||
| 65 | * @return Role[] |
||
| 66 | */ |
||
| 67 | 2 | public function getRoles() |
|
| 71 | |||
| 72 | /** |
||
| 73 | * Finds and extracts the ad username from the cookie. |
||
| 74 | * |
||
| 75 | * @param Request $request Request stack that controls the lifecycle of requests |
||
| 76 | * @param string $value The string the value of self::COOKIE_FIELD_NAME shall be extracted from. |
||
| 77 | * |
||
| 78 | * @return string |
||
| 79 | */ |
||
| 80 | 2 | View Code Duplication | protected function extractAdUsername(Request $request, $value) |
| 93 | |||
| 94 | /** |
||
| 95 | * Finds and extracts the core system id from tha cookie. |
||
| 96 | * |
||
| 97 | * @param Request $request Request stack that controls the lifecycle of requests |
||
| 98 | * @param string $text String to be examined for the core id. |
||
| 99 | * |
||
| 100 | * @return string |
||
| 101 | */ |
||
| 102 | 2 | View Code Duplication | protected function extractCoreId(Request $request, $text) |
| 115 | } |
||
| 116 |