GeneratorParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A generateClass() 0 9 1
A addProperty() 0 3 1
A getOutputPath() 0 3 1
1
<?php
2
/**
3
 * This file is part of graze/unicontroller-client.
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/unicontroller-client/blob/master/LICENSE.md
11
 * @link https://github.com/graze/unicontroller-client
12
 */
13
namespace Graze\UnicontrollerClient\ClassGenerator\Generator;
14
15
use Graze\UnicontrollerClient\ClassGenerator\Generator\AbstractGenerator;
16
use Graze\UnicontrollerClient\ClassGenerator\Generator\GeneratorInterface;
17
use Graze\UnicontrollerClient\ClassGenerator\Definition\DefinitionProperty;
18
19
class GeneratorParser extends AbstractGenerator implements GeneratorInterface
20
{
21
    const OUTPUT_PATH = 'src/Parser/Parser/Parser%s.php';
22
23
    /**
24
     * @var array
25
     */
26
    private $properties = [];
27
28
    /**
29
     * @param string $name
30
     * @return string
31
     */
32
    public function generateClass($name)
33
    {
34
        return sprintf(
35
            $this->getTemplate('Parser/ParserClass'),
36
            $name,
37
            $name,
38
            implode(",\n", $this->properties),
39
            $name,
40
            $name
41
        );
42
    }
43
44
    /**
45
     * @param DefinitionProperty $property
46
     */
47
    public function addProperty(DefinitionProperty $property)
48
    {
49
        $this->properties[] = sprintf("            '%s'", lcfirst($property->getName()));
50
    }
51
52
    /**
53
     * @param string $name
54
     * @return string
55
     */
56
    public function getOutputPath($name)
57
    {
58
        return sprintf(self::OUTPUT_PATH, $name);
59
    }
60
}
61