Passed
Push — master ( 0f9932...7bc3f9 )
by Brent
03:42
created

YamlParser::parse()   B

Complexity

Conditions 5
Paths 14

Size

Total Lines 28
Code Lines 18

Duplication

Lines 6
Ratio 21.43 %

Importance

Changes 0
Metric Value
cc 5
eloc 18
nc 14
nop 1
dl 6
loc 28
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace brendt\stitcher\parser;
4
5
use brendt\stitcher\exception\ParserException;
6
use Symfony\Component\Finder\Finder;
7
use Symfony\Component\Yaml\Exception\ParseException;
8
use Symfony\Component\Yaml\Yaml;
9
10
class YamlParser extends AbstractArrayParser {
11
12
    public function parse($path = '*.yml') {
13
        $finder = new Finder();
14
        $data = [];
15
        if (!strpos($path, '.yml')) {
16
            $path .= '.yml';
17
        }
18
19
        $files = $finder->files()->in("{$this->root}")->path($path);
20
21
        foreach ($files as $file) {
22
            try {
23
                $parsed = Yaml::parse($file->getContents());
24
25 View Code Duplication
                if (isset($parsed['entries'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
26
                    $data += $parsed['entries'];
27
                } else {
28
                    $id = str_replace(".{$file->getExtension()}", '', $file->getFilename());
29
                    $data[$id] = $parsed;
30
                }
31
            } catch (ParseException $e) {
32
                throw new ParserException("{$file->getRelativePathname()}: {$e->getMessage()}");
33
            }
34
        }
35
36
        $data = $this->parseArrayData($data);
37
38
        return $data;
39
    }
40
41
}
42