Converter::convert()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 9
cp 0
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 12
1
<?php
2
3
/**
4
 * This file is part of the Clover to Html package.
5
 *
6
 * (c) Stéphane Demonchaux <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace CloverToHtml;
12
13
class Converter
14
{
15
    /**
16
     * @var Hydrator
17
     */
18
    private $hydrator;
19
    /**
20
     * @var Render
21
     */
22
    private $render;
23
24
    /**
25
     * @param Hydrator $hydrator
26
     * @param Render   $render
27
     */
28 3
    public function __construct(Hydrator $hydrator, Render $render)
29
    {
30 3
        $this->hydrator = $hydrator;
31 3
        $this->render   = $render;
32 3
    }
33
34
    /**
35
     * @param $clover
36
     * @param $target
37
     * @param $templatePath
38
     * @throws \Twig_Error_Loader
39
     * @throws \Twig_Error_Runtime
40
     * @throws \Twig_Error_Syntax
41
     */
42
    public function convert($clover, $target, $templatePath = null): void
43
    {
44
        if (is_file($clover) === false) {
45
            throw new \InvalidArgumentException(sprintf('"%s" is not a file', $clover));
46
        }
47
48
        if (is_dir($target) === true) {
49
            throw new \InvalidArgumentException(sprintf('Target must be empty "%s"', $target));
50
        }
51
52
        $this->render->render(
53
            $this->hydrator->xmlToDto(simplexml_load_file($clover), new Root()),
54
            $target,
55
            $templatePath
56
        );
57
    }
58
}
59