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 |
||
| 15 | final class RulesetFileSystem implements RulesetFileSystemInterface |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | private $vendorDir; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var strings[] |
||
| 24 | */ |
||
| 25 | private $rulesets = []; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @param string $vendorDir |
||
| 29 | */ |
||
| 30 | 7 | public function __construct($vendorDir) |
|
| 34 | |||
| 35 | /** |
||
| 36 | * {@inheritdoc} |
||
| 37 | */ |
||
| 38 | 4 | public function getRulesetPathForStandardName($standardName) |
|
| 39 | { |
||
| 40 | 4 | if (isset($this->getRulesets()[$standardName])) { |
|
| 41 | 3 | return $this->getRulesets()[$standardName]; |
|
|
|
|||
| 42 | } |
||
| 43 | |||
| 44 | 1 | throw new Exception( |
|
| 45 | sprintf( |
||
| 46 | 1 | 'Ruleset for standard "%s" was not found. Found standards are: %s.', |
|
| 47 | $standardName, |
||
| 48 | 1 | implode($this->getRulesetNames(), ', ') |
|
| 49 | ) |
||
| 50 | ); |
||
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @return array |
||
| 55 | */ |
||
| 56 | 4 | private function getRulesets() |
|
| 71 | |||
| 72 | /** |
||
| 73 | * @return string[] |
||
| 74 | */ |
||
| 75 | 4 | View Code Duplication | private function findRulesetFiles() |
| 83 | |||
| 84 | /** |
||
| 85 | * @return string[] |
||
| 86 | */ |
||
| 87 | 1 | private function getRulesetNames() |
|
| 91 | } |
||
| 92 |