We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
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 |
||
5 | final class InheritanceProcessor implements ProcessorInterface |
||
6 | { |
||
7 | const HEIRS_KEY = 'heirs'; |
||
8 | const INHERITS_KEY = 'inherits'; |
||
9 | |||
10 | /** |
||
11 | * {@inheritdoc} |
||
12 | */ |
||
13 | 33 | public static function process(array $configs) |
|
21 | |||
22 | private static function removedDecorators(array $configs) |
||
28 | |||
29 | 33 | private static function processConfigsHeirs(array $configs) |
|
30 | { |
||
31 | 33 | foreach ($configs as $parentName => &$config) { |
|
32 | 33 | if (!empty($config[self::HEIRS_KEY])) { |
|
33 | // allows shorthand configuration `heirs: QueryFooDecorator` is equivalent to `heirs: [QueryFooDecorator]` |
||
34 | 5 | View Code Duplication | if (!is_array($config[self::HEIRS_KEY])) { |
|
|||
35 | 1 | $config[self::HEIRS_KEY] = [$config[self::HEIRS_KEY]]; |
|
36 | } |
||
37 | 5 | foreach ($config[self::HEIRS_KEY] as $heirs) { |
|
38 | 5 | if (!isset($configs[$heirs])) { |
|
39 | 1 | throw new \InvalidArgumentException(sprintf( |
|
40 | 1 | 'Type %s child of %s not found.', |
|
41 | 1 | json_encode($heirs), |
|
42 | 1 | json_encode($parentName) |
|
43 | )); |
||
44 | } |
||
45 | |||
46 | 4 | if (!isset($configs[$heirs][self::INHERITS_KEY])) { |
|
47 | 1 | $configs[$heirs][self::INHERITS_KEY] = []; |
|
48 | } |
||
49 | |||
50 | 4 | $configs[$heirs][self::INHERITS_KEY][] = $parentName; |
|
51 | } |
||
52 | } |
||
53 | 33 | unset($config[self::HEIRS_KEY]); |
|
54 | } |
||
55 | |||
56 | 32 | return $configs; |
|
57 | } |
||
58 | |||
59 | 32 | private static function processConfigsInherits(array $configs) |
|
79 | |||
80 | 1 | private static function inheritsTypeConfig($child, array $parents, array $configs) |
|
95 | |||
96 | 27 | private static function flattenInherits($name, array $configs, array $allowedTypes, $child = null, array $typesTreated = []) |
|
119 | |||
120 | 27 | private static function checkTypeExists($name, array $configs, $child) |
|
130 | |||
131 | 27 | private static function checkCircularReferenceInheritsTypes($name, array $typesTreated) |
|
140 | |||
141 | 27 | private static function checkAllowedInheritsTypes($name, array $config, array $allowedTypes, $child) |
|
153 | } |
||
154 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.