Issues (283)

bin/src/ClassGenerator.php (3 issues)

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 Bug introduced by
The doc comment [] at position 0 could not be parsed: Unknown type name '[' at position 0 in [].
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 Bug introduced by
The doc comment [] at position 0 could not be parsed: Unknown type name '[' at position 0 in [].
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 Bug introduced by
The doc comment [] at position 0 could not be parsed: Unknown type name '[' at position 0 in [].
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