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 |
||
12 | class Prize |
||
13 | { |
||
14 | use EventManagerAwareTrait; |
||
15 | |||
16 | /** |
||
17 | * @var prizeMapper |
||
18 | */ |
||
19 | protected $prizeMapper; |
||
20 | |||
21 | /** |
||
22 | * @var ServiceManager |
||
23 | */ |
||
24 | protected $serviceManager; |
||
25 | |||
26 | /** |
||
27 | * @var UserServiceOptionsInterface |
||
28 | */ |
||
29 | protected $options; |
||
30 | |||
31 | /** |
||
32 | * |
||
33 | * @var ServiceManager |
||
34 | */ |
||
35 | protected $serviceLocator; |
||
36 | |||
37 | public function __construct(ServiceLocatorInterface $locator) |
||
41 | |||
42 | /** |
||
43 | * |
||
44 | * This service is ready for all types of games |
||
45 | * |
||
46 | * @param array $data |
||
47 | * @param string $formClass |
||
48 | * @return \PlaygroundGame\Entity\Game |
||
49 | */ |
||
50 | public function create(array $data, $prize, $formClass) |
||
70 | |||
71 | /** |
||
72 | * |
||
73 | * @param array $data |
||
74 | * @param string $formClass |
||
75 | * @return \PlaygroundGame\Entity\Game |
||
76 | */ |
||
77 | public function edit(array $data, $prize, $formClass) |
||
104 | |||
105 | |||
106 | /** |
||
107 | * getPrizeMapper |
||
108 | * |
||
109 | * @return PrizeMapper |
||
110 | */ |
||
111 | View Code Duplication | public function getPrizeMapper() |
|
119 | |||
120 | /** |
||
121 | * setPrizeMapper |
||
122 | * |
||
123 | * @param PrizeMapper $prizeMapper |
||
124 | * @return Prize |
||
125 | */ |
||
126 | public function setPrizeMapper(PrizeMapper $prizeMapper) |
||
132 | |||
133 | public function setOptions(ModuleOptions $options) |
||
139 | |||
140 | public function getOptions() |
||
148 | |||
149 | /** |
||
150 | * Retrieve service manager instance |
||
151 | * |
||
152 | * @return ServiceManager |
||
153 | */ |
||
154 | public function getServiceManager() |
||
158 | |||
159 | /** |
||
160 | * Set service manager instance |
||
161 | * |
||
162 | * @param ServiceManager $serviceManager |
||
163 | * @return Prize |
||
164 | */ |
||
165 | public function setServiceManager(ServiceManager $serviceManager) |
||
171 | } |
||
172 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.