Completed
Push — master ( 411d94...8fae9a )
by John
02:59
created

ClassGenerator   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 97
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A generateClasses() 0 11 2
A getParser() 0 7 1
A getEntity() 0 7 1
A getSerialiser() 0 7 1
A factory() 0 8 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;
14
15
use Graze\UnicontrollerClient\ClassGenerator\Generator\GeneratorParser;
16
use Graze\UnicontrollerClient\ClassGenerator\Generator\GeneratorEntity;
17
use Graze\UnicontrollerClient\ClassGenerator\Generator\GeneratorSerialiser;
18
use Graze\UnicontrollerClient\ClassGenerator\Definition\Definition;
19
20
class ClassGenerator
21
{
22
    /**
23
     * @var GeneratorParser
24
     */
25
    private $generatorParser;
26
27
    /**
28
     * @var GeneratorEntity
29
     */
30
    private $generatorEntity;
31
32
    /**
33
     * @var GeneratorSerialiser
34
     */
35
    private $generatorSerialiser;
36
37
    /**
38
     * @var string
39
     */
40
    private $name;
41
42
    /**
43
     * @param GeneratorParser $generatorParser
44
     * @param GeneratorEntity $generatorEntity
45
     * @param GeneratorSerialiser $generatorSerialiser
46
     */
47
    public function __construct(
48
        GeneratorParser $generatorParser,
49
        GeneratorEntity $generatorEntity,
50
        GeneratorSerialiser $generatorSerialiser
51
    ) {
52
        $this->generatorParser = $generatorParser;
53
        $this->generatorEntity = $generatorEntity;
54
        $this->generatorSerialiser = $generatorSerialiser;
55
    }
56
57
    /**
58
     * @param Definition $definition
59
     */
60
    public function generateClasses(Definition $definition)
61
    {
62
        $this->name = $definition->getName();
63
64
        foreach ($definition->getProperties() as $property) {
65
            $this->generatorParser->addProperty($property);
66
            $this->generatorEntity->addProperty($property);
67
            $this->generatorEntity->addMethod($property);
68
            $this->generatorSerialiser->addCallSerialise($property);
69
        }
70
    }
71
72
    /**
73
     * @return []
0 ignored issues
show
Documentation introduced by
The doc-type [] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
74
     */
75
    public function getParser()
76
    {
77
        return [
78
            $this->generatorParser->getOutputPath($this->name),
79
            $this->generatorParser->generateClass($this->name)
80
        ];
81
    }
82
83
    /**
84
     * @return []
0 ignored issues
show
Documentation introduced by
The doc-type [] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
85
     */
86
    public function getEntity()
87
    {
88
        return [
89
            $this->generatorEntity->getOutputPath($this->name),
90
            $this->generatorEntity->generateClass($this->name)
91
        ];
92
    }
93
94
    /**
95
     * @return []
0 ignored issues
show
Documentation introduced by
The doc-type [] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
96
     */
97
    public function getSerialiser()
98
    {
99
        return [
100
            $this->generatorSerialiser->getOutputPath($this->name),
101
            $this->generatorSerialiser->generateClass($this->name)
102
        ];
103
    }
104
105
    /**
106
     * @return ClassGenerator
107
     */
108
    public static function factory()
109
    {
110
        return new static(
111
            new GeneratorParser(),
112
            new GeneratorEntity(),
113
            new GeneratorSerialiser()
114
        );
115
    }
116
}
117