GeneratorParser::addProperty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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