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 |
||
| 11 | class JsonServiceFactory implements ServiceFactoryInterface |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @var array $services |
||
| 15 | */ |
||
| 16 | private $services; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var array $serviceList |
||
| 20 | */ |
||
| 21 | private $serviceList; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Constructor |
||
| 25 | * |
||
| 26 | * @param string $jsonFile |
||
| 27 | * |
||
| 28 | * @return void |
||
|
|
|||
| 29 | */ |
||
| 30 | public function __construct($jsonFile) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $jsonFile |
||
| 37 | * |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | private function loadJsonFile($jsonFile) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param string $jsonFile |
||
| 48 | * |
||
| 49 | * @return void |
||
| 50 | */ |
||
| 51 | private function loadServiceList($jsonFile) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @inheritdoc |
||
| 62 | */ |
||
| 63 | View Code Duplication | public function create($service) |
|
| 79 | } |
||
| 80 |
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.