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 namespace Limoncello\Application\Data; |
||
| 32 | abstract class BaseSeedRunner |
||
| 33 | { |
||
| 34 | /** Seed column name */ |
||
| 35 | const SEEDS_COLUMN_ID = 'id'; |
||
| 36 | |||
| 37 | /** Seed column name */ |
||
| 38 | const SEEDS_COLUMN_CLASS = 'class'; |
||
| 39 | |||
| 40 | /** Seed column name */ |
||
| 41 | const SEEDS_COLUMN_SEEDED_AT = 'seeded_at'; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var string |
||
| 45 | */ |
||
| 46 | private $seedsTable; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var null|callable |
||
| 50 | */ |
||
| 51 | private $seedInit = null; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var IoInterface |
||
| 55 | */ |
||
| 56 | private $inOut; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @return string[] |
||
| 60 | */ |
||
| 61 | abstract protected function getSeedClasses(): array; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @param IoInterface $inOut |
||
| 65 | * @param callable $seedInit |
||
|
|
|||
| 66 | * @param string $seedsTable |
||
| 67 | */ |
||
| 68 | 2 | public function __construct( |
|
| 80 | |||
| 81 | /** |
||
| 82 | * @param ContainerInterface $container |
||
| 83 | * |
||
| 84 | * @return void |
||
| 85 | */ |
||
| 86 | public function run(ContainerInterface $container): void |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param ContainerInterface $container |
||
| 100 | * |
||
| 101 | * @return Generator |
||
| 102 | * |
||
| 103 | * @SuppressWarnings(PHPMD.ElseExpression) |
||
| 104 | */ |
||
| 105 | View Code Duplication | protected function getSeeds(ContainerInterface $container): Generator |
|
| 124 | |||
| 125 | /** |
||
| 126 | * @param ContainerInterface $container |
||
| 127 | * |
||
| 128 | * @return Connection |
||
| 129 | */ |
||
| 130 | protected function getConnection(ContainerInterface $container): Connection |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @param ContainerInterface $container |
||
| 137 | * @param string $seedClass |
||
| 138 | * |
||
| 139 | * @return void |
||
| 140 | */ |
||
| 141 | protected function executeSeedInit(ContainerInterface $container, string $seedClass): void |
||
| 147 | |||
| 148 | /** |
||
| 149 | * @return IoInterface |
||
| 150 | */ |
||
| 151 | protected function getIO(): IoInterface |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @param IoInterface $inOut |
||
| 158 | * |
||
| 159 | * @return self |
||
| 160 | */ |
||
| 161 | 2 | private function setIO(IoInterface $inOut): self |
|
| 167 | |||
| 168 | /** |
||
| 169 | * @param AbstractSchemaManager $manager |
||
| 170 | * |
||
| 171 | * @return void |
||
| 172 | */ |
||
| 173 | View Code Duplication | private function createSeedsTable(AbstractSchemaManager $manager): void |
|
| 192 | |||
| 193 | /** |
||
| 194 | * @param Connection $connection |
||
| 195 | * |
||
| 196 | * @return array |
||
| 197 | */ |
||
| 198 | private function readSeeded(Connection $connection): array |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @param Connection $connection |
||
| 222 | * @param string $class |
||
| 223 | * |
||
| 224 | * @return void |
||
| 225 | */ |
||
| 226 | View Code Duplication | private function saveSeed(Connection $connection, string $class): void |
|
| 235 | |||
| 236 | /** |
||
| 237 | * @return string |
||
| 238 | */ |
||
| 239 | private function getSeedsTable(): string |
||
| 243 | } |
||
| 244 |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type
arrayand suggests a stricter type likearray<String>.Most often this is a case of a parameter that can be null in addition to its declared types.