Total Complexity | 8 |
Total Lines | 72 |
Duplicated Lines | 6.94 % |
Changes | 0 |
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 |
||
9 | class SubTheme |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | private $name; |
||
15 | /** |
||
16 | * @var string |
||
17 | */ |
||
18 | private $parent; |
||
19 | /** |
||
20 | * @var array|string[][] |
||
21 | */ |
||
22 | private $assignations; |
||
23 | |||
24 | /** |
||
25 | * @param string $name |
||
26 | * @param string $parent |
||
27 | * @param string[][] $assignations |
||
28 | */ |
||
29 | public function __construct(string $name, string $parent, array $assignations) |
||
30 | { |
||
31 | $this->name = $name; |
||
32 | $this->parent = $parent; |
||
33 | $this->assignations = $assignations; |
||
34 | } |
||
35 | |||
36 | public static function fromFile(string $file): self |
||
37 | { |
||
38 | if (!is_readable($file)) { |
||
39 | throw new UnableToLoadFileException('Cannot read file '.$file); |
||
40 | } |
||
41 | |||
42 | $yaml = Yaml::parse(file_get_contents($file)); |
||
43 | |||
44 | $compulsoryFields = ['name', 'parent', 'assignations']; |
||
45 | |||
46 | View Code Duplication | foreach ($compulsoryFields as $field) { |
|
47 | if (!isset($yaml[$field])) { |
||
48 | throw new UnableToLoadFileException('Missing field "'.$field.'" in YAML file '.$file); |
||
49 | } |
||
50 | } |
||
51 | |||
52 | return new self( |
||
53 | $yaml['name'], |
||
54 | $yaml['parent'], |
||
55 | $yaml['assignations'] |
||
56 | ); |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * @return string |
||
61 | */ |
||
62 | public function getName(): string |
||
63 | { |
||
64 | return $this->name; |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @return string |
||
69 | */ |
||
70 | public function getParent(): string |
||
71 | { |
||
72 | return $this->parent; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * @return array|string[][] |
||
77 | */ |
||
78 | public function getAssignations() |
||
81 | } |
||
82 | } |
||
83 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths