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 |
||
| 20 | class CompositeFacet implements FacetInterface |
||
| 21 | { |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @var string |
||
| 25 | */ |
||
| 26 | protected $name; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * @var string |
||
| 30 | */ |
||
| 31 | protected $label; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @var array |
||
| 35 | */ |
||
| 36 | protected $suggestions = [ |
||
| 37 | '0' => 'LLL:EXT:vidi/Resources/Private/Language/locallang.xlf:active.0', |
||
| 38 | ]; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var array |
||
| 42 | */ |
||
| 43 | protected $configuration = []; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var string |
||
| 47 | */ |
||
| 48 | protected $dataType; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var bool |
||
| 52 | */ |
||
| 53 | protected $canModifyMatcher = true; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Constructor of a Generic Facet in Vidi. |
||
| 57 | * |
||
| 58 | * @param string $name |
||
| 59 | * @param string $label |
||
| 60 | * @param array $suggestions |
||
| 61 | * @param array $configuration |
||
| 62 | */ |
||
| 63 | public function __construct($name, $label = '', array $suggestions = [], $configuration = []) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @return string |
||
| 80 | */ |
||
| 81 | public function getName(): string |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @return string |
||
| 88 | */ |
||
| 89 | View Code Duplication | public function getLabel(): string |
|
| 105 | |||
| 106 | /** |
||
| 107 | * @return array |
||
| 108 | */ |
||
| 109 | View Code Duplication | public function getSuggestions(): array |
|
| 124 | |||
| 125 | /** |
||
| 126 | * @return LanguageService |
||
| 127 | */ |
||
| 128 | View Code Duplication | protected function getLanguageService(): LanguageService |
|
| 139 | |||
| 140 | /** |
||
| 141 | * @return bool |
||
| 142 | */ |
||
| 143 | public function hasSuggestions(): bool |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @param string $dataType |
||
| 150 | * @return $this |
||
| 151 | */ |
||
| 152 | public function setDataType($dataType): self |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @return bool |
||
| 160 | */ |
||
| 161 | public function canModifyMatcher(): bool |
||
| 165 | |||
| 166 | /** |
||
| 167 | * @param Matcher $matcher |
||
| 168 | * @param $value |
||
| 169 | * @return Matcher |
||
| 170 | */ |
||
| 171 | public function modifyMatcher(Matcher $matcher, $value): Matcher |
||
| 182 | |||
| 183 | } |
||
| 184 |
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.