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 |
||
23 | abstract class AbstractFixture extends BaseAbstractFixture implements OrderedFixtureInterface |
||
24 | { |
||
25 | protected $commandBus; |
||
26 | protected $queryBus; |
||
27 | |||
28 | abstract protected function type() : string; |
||
29 | |||
30 | // It does not possible enable this return type because IdentityAccess, |
||
31 | // uses the BenGorUser so, the command bus is not a shared kernel's |
||
32 | // command bus instance. |
||
33 | protected function commandBus() // : \Kreta\SharedKernel\Application\CommandBus |
||
37 | |||
38 | protected function queryBus() : QueryBus |
||
42 | |||
43 | protected function fakeIds() : array |
||
51 | |||
52 | protected function amount() : int |
||
56 | |||
57 | View Code Duplication | protected function getRandomByIndex(int $index, array $list = null) : string |
|
58 | { |
||
59 | $list = null === $list ? $this->fakeIds() : $list; |
||
60 | |||
61 | $numberOfUserIds = count($list); |
||
62 | $j = $this->mod($index, $numberOfUserIds - 1) > $numberOfUserIds |
||
63 | ? 0 |
||
64 | : $this->mod(($numberOfUserIds - ($index - 1)), $numberOfUserIds); |
||
65 | |||
66 | return $list[$j]; |
||
67 | } |
||
68 | |||
69 | protected function getRandomUserByIndex(int $index) : string |
||
79 | |||
80 | private function mod(int $first, int $second) : int |
||
86 | |||
87 | private function fakeDataDir() : string |
||
110 | } |
||
111 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.