Passed
Push — master ( 003724...f241d1 )
by Brent
02:47
created

FileParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Brendt\Stitcher\Parser;
4
5
use Brendt\Stitcher\Config;
6
use Symfony\Component\Finder\Finder;
7
8
/**
9
 * The FileParser takes a path and reads the file contents from that path.
10
 */
11
class FileParser implements Parser
12
{
13
14
    /**
15
     * @var string
16
     */
17
    private $srcDir;
18
19
    /**
20
     * FileParser constructor.
21
     *
22
     * @param string $srcDir
23
     */
24
    public function __construct($srcDir) {
25
        $this->srcDir = $srcDir;
26
    }
27
28
    /**
29
     * @param $path
30
     *
31
     * @return string
32
     */
33
    public function parse($path) {
34
        $files = Finder::create()->files()->in($this->srcDir)->path(trim($path, '/'))->getIterator();
35
        $files->rewind();
36
        $file = $files->current();
37
38
        if (!$file) {
39
            return '';
40
        }
41
42
        return $file->getContents();
43
    }
44
45
}
46