Conditions | 5 |
Paths | 2 |
Total Lines | 24 |
Code Lines | 14 |
Lines | 5 |
Ratio | 20.83 % |
Changes | 0 |
1 | <?php |
||
26 | public static function fromDirectory(string $path): self |
||
27 | { |
||
28 | if (!is_dir($path)) { |
||
29 | throw new UnableToLoadFileException('Cannot find directory '.$path); |
||
30 | } |
||
31 | $path = rtrim($path, '/\\'); |
||
32 | $configPath = $path.'/config.yml'; |
||
33 | if (!is_file($configPath)) { |
||
34 | throw new UnableToLoadFileException('Cannot find config.yml in theme '.$path); |
||
35 | } |
||
36 | |||
37 | $yaml = Yaml::parse(file_get_contents($configPath)); |
||
38 | |||
39 | $compulsoryFields = ['zones']; |
||
40 | |||
41 | View Code Duplication | foreach ($compulsoryFields as $field) { |
|
|
|||
42 | if (!isset($yaml[$field])) { |
||
43 | throw new UnableToLoadFileException('Missing field '.$field.' in YAML file '.$configPath); |
||
44 | } |
||
45 | } |
||
46 | |||
47 | return new self( |
||
48 | $path, |
||
49 | $yaml['zones'] |
||
50 | ); |
||
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.