Passed
Push — master ( 59db0f...9fb939 )
by Brent
04:37
created

FileParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A parse() 0 11 2
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