Total Complexity | 10 |
Total Lines | 81 |
Duplicated Lines | 6.17 % |
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 |
||
6 | class Theme |
||
7 | { |
||
8 | /** |
||
9 | * @var string |
||
10 | */ |
||
11 | private $path; |
||
12 | /** |
||
13 | * @var string[] |
||
14 | */ |
||
15 | private $zones; |
||
16 | |||
17 | /** |
||
18 | * @param string[] $zones |
||
19 | */ |
||
20 | public function __construct(string $path, array $zones) |
||
21 | { |
||
22 | $this->path = $path; |
||
23 | $this->zones = $zones; |
||
24 | } |
||
25 | |||
26 | public static function fromDirectory(string $path): self |
||
50 | ); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Returns true if $path is a theme directory. |
||
55 | * |
||
56 | * @param string $path The path, with no trailing / |
||
57 | * @return bool |
||
58 | */ |
||
59 | public static function existsInDirectory(string $path): bool |
||
60 | { |
||
61 | $configPath = $path.'/config.yml'; |
||
62 | return file_exists($configPath); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | public function getName(): string |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @return string |
||
75 | */ |
||
76 | public function getPath(): string |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @return string[] |
||
83 | */ |
||
84 | public function getZones(): array |
||
87 | } |
||
88 | } |
||
89 |
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.