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 |
||
| 6 | class PhpIniCheck extends AbstractCheck |
||
| 7 | { |
||
| 8 | |||
| 9 | const TypeBoolean = 'boolean'; |
||
| 10 | const TypeMemory = 'memory'; |
||
| 11 | const TypeNumber = 'number'; |
||
| 12 | const TypeRegex = 'regex'; |
||
| 13 | const TypeString = 'string'; |
||
| 14 | |||
| 15 | protected $varName; |
||
| 16 | protected $varType; |
||
| 17 | protected $varValue; |
||
| 18 | protected $maxValue; |
||
| 19 | protected $iniValue; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * PhpIniCheck constructor. |
||
| 23 | * |
||
| 24 | * @param string $label |
||
| 25 | * @param string $varName <b>Name</b> of ini value - used for ini_get(...) |
||
| 26 | * @param string $varType <b>Type</b> of ini value - see class constant |
||
| 27 | * @param mixed $varValue <b>Value</b> which is expected |
||
| 28 | * @param null $maxValue <b>maximum</b> value is optional used for numbers |
||
| 29 | * |
||
| 30 | * @return PhpIniCheck |
||
|
|
|||
| 31 | */ |
||
| 32 | public function __construct(string $label, string $varName, string $varType, $varValue, $maxValue=null) |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param string $size |
||
| 44 | * @return int|bool(false) |
||
| 45 | */ |
||
| 46 | protected function stringToMegabyte(string $size) |
||
| 60 | |||
| 61 | |||
| 62 | /** |
||
| 63 | * @return Result |
||
| 64 | */ |
||
| 65 | public function check(): Result |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @return Result |
||
| 88 | */ |
||
| 89 | protected function checkBoolean() { |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @return Result |
||
| 98 | */ |
||
| 99 | protected function checkMemory() { |
||
| 108 | |||
| 109 | /** |
||
| 110 | * @return Result |
||
| 111 | */ |
||
| 112 | protected function checkNumber() { |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @return Result |
||
| 134 | */ |
||
| 135 | protected function checkRegex() { |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @return Result |
||
| 144 | */ |
||
| 145 | protected function checkString() { |
||
| 151 | |||
| 152 | } |
||
| 153 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.