Fillet::parse()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
rs 9.4286
cc 3
eloc 5
nc 3
nop 0
1
<?php
2
3
namespace Fillet;
4
5
use Fillet\Parser\ParserInterface;
6
use Fillet\Writer\WriterFactory;
7
8
/**
9
 * Mainline driver for Fillet
10
 * This class handles all the heavy lifting for turning a data source into a series of Sculpin outputs.
11
 *
12
 * @package Fillet
13
 */
14
class Fillet
15
{
16
    /**
17
     * Configuration for Fillet
18
     * @var array
19
     */
20
    protected $config;
21
22
    /**
23
     * Full path to the file we need to work against
24
     * @var string
25
     */
26
    protected $inputFile;
27
28
    /**
29
     * Parser that we will be using
30
     * @var ParserInterface
31
     */
32
    protected $parser;
33
34
    /**
35
     * Create an instance of Fillet
36
     *
37
     * @param ParserInterface $parser Parser to use
38
     * @param string $inputFile File to parse
39
     * @param array $config Fillet configuration
40
     */
41
    public function __construct(ParserInterface $parser, $inputFile, $config)
42
    {
43
        $this->parser = $parser;
44
        $this->inputFile = $inputFile;
45
        $this->config = $config;
46
    }
47
48
    /**
49
     * Calls the parser and generates the files
50
     *
51
     * @throws \Exception
52
     */
53
    public function parse()
54
    {
55
        foreach($this->parser->parse($this->inputFile) as $item) {
56
            $writer = WriterFactory::create($item['type'], $this->config);
57
58
            if($writer) {
59
                $writer->write($item);
60
            }
61
        }
62
    }
63
}