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 |
||
| 17 | class LimitationParser extends BaseParser |
||
| 18 | { |
||
| 19 | /** |
||
| 20 | * Name of the route parameter. |
||
| 21 | * Example: "sectionId" |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | private $limitationRouteParameterName; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Value object class built by the Parser. |
||
| 28 | * Example: "eZ\Publish\API\Repository\Values\User\Limitation\SectionLimitation" |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | private $limitationClass; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * LimitationParser constructor. |
||
| 35 | * |
||
| 36 | * @param $limitationRouteParameterName |
||
| 37 | * @param $limitationClass |
||
| 38 | */ |
||
| 39 | public function __construct($limitationRouteParameterName, $limitationClass) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Parse input structure. |
||
| 47 | * |
||
| 48 | * @param array $data |
||
| 49 | * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher |
||
| 50 | * |
||
| 51 | * @return \eZ\Publish\API\Repository\Values\ValueObject |
||
| 52 | */ |
||
| 53 | View Code Duplication | public function parse(array $data, ParsingDispatcher $parsingDispatcher) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * @return \eZ\Publish\API\Repository\Values\User\Limitation |
||
| 78 | */ |
||
| 79 | protected function buildLimitation() |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @param $limitationValue |
||
| 86 | * |
||
| 87 | * @return false|mixed |
||
| 88 | */ |
||
| 89 | protected function parseIdFromHref($limitationValue) |
||
| 96 | } |
||
| 97 |