Passed
Push — master ( 9a9566...e7d3cc )
by Maxim
04:23
created

PropertyData::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 18
nc 1
nop 2
dl 0
loc 20
ccs 0
cts 19
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is a part of "Axessors" library.
4
 *
5
 * @author <[email protected]>
6
 * @license GPL
7
 */
8
9
namespace NoOne4rever\Axessors;
10
11
/**
12
 * Class PropertyData.
13
 *
14
 * Stores information about Axessors property.
15
 *
16
 * @package NoOne4rever\Axessors
17
 */
18
class PropertyData
19
{
20
    /** @var \ReflectionProperty property's reflection */
21
    public $reflection;
22
23
    /** @var string[] access modifiers for getter and setter */
24
    private $accessibility;
25
    /** @var string an alias of property name */
26
    private $alias;
27
    /** @var array type tree */
28
    private $type;
29
    /** @var string[] conditions for setter */
30
    private $conditionsIn = [];
31
    /** @var string[] conditions for getter */
32
    private $conditionsOut = [];
33
    /** @var string[] handlers for setter */
34
    private $handlersIn = [];
35
    /** @var string[] handlers for getter */
36
    private $handlersOut = [];
37
    /** @var string[] methods' names */
38
    private $methods = [];
39
40
    /**
41
     * PropertyData constructor.
42
     *
43
     * @param \ReflectionProperty $reflection property's information
44
     * @param array $tokens tokens form Axessors comment
45
     */
46
    public function __construct(\ReflectionProperty $reflection, array $tokens)
47
    {
48
        $parser = new Parser($reflection, $tokens);
49
        $this->reflection = $reflection;
50
        $this->accessibility = $parser->processAccessModifier();
51
        $this->alias = $parser->getAlias();
52
        $typeProcessor = new TypeProcessor($parser->getReflection(), $parser->getNamespace(), $parser->getTypeDef());
53
        $typeProcessor->processType();
54
        $this->type = $typeProcessor->getTypeTree();
55
        $conditionsProcessor = new ConditionsProcessor($parser->getInConditions(), $parser->getOutConditions(),
56
            $parser->getNamespace());
57
        $this->conditionsIn = $conditionsProcessor->processInputData();
58
        $this->conditionsOut = $conditionsProcessor->processOutputData();
59
        $handlersProcessor = new HandlersProcessor($parser->getInHandlers(), $parser->getOutHandlers(),
60
            $parser->getNamespace());
61
        $this->handlersIn = $handlersProcessor->processInputData();
62
        $this->handlersOut = $handlersProcessor->processOutputData();
63
        $methodsProcessor = new MethodsProcessor($this->accessibility['write'] ?? '',
64
            $this->accessibility['read'] ?? '', $this->getAlias());
65
        $this->methods = $methodsProcessor->processMethods($typeProcessor->getTypeTree());
66
    }
67
68
    /**
69
     * Getter for {@see PropertyData::$accessibility}.
70
     *
71
     * @return string[] {@see PropertyData::$accessibility}
72
     */
73
    public function getAccessibility(): array
74
    {
75
        return $this->accessibility;
76
    }
77
78
    /**
79
     * Getter for {@see PropertyData::$alias}.
80
     *
81
     * @return string {@see PropertyData::$alias}
82
     */
83
    public function getAlias(): string
84
    {
85
        return $this->alias;
86
    }
87
88
    /**
89
     * Getter for {@see PropertyData::$methods}.
90
     *
91
     * @return string[] {@see PropertyData::$methods}
92
     */
93
    public function getMethods(): array
94
    {
95
        return $this->methods;
96
    }
97
98
    /**
99
     * Getter for {@see PropertyData::$conditionsIn}.
100
     *
101
     * @return string[] {@see PropertyData::$conditionsIn}
102
     */
103
    public function getInputConditions(): array
104
    {
105
        return $this->conditionsIn;
106
    }
107
108
    /**
109
     * Getter for {@see PropertyData::$conditionsOut}.
110
     *
111
     * @return string[] {@see PropertyData::$conditionsOut}
112
     */
113
    public function getOutputConditions(): array
114
    {
115
        return $this->conditionsOut;
116
    }
117
118
    /**
119
     * Getter for {@see PropertyData::$handlersOut}.
120
     *
121
     * @return string[] {@see PropertyData::$handlersOut}
122
     */
123
    public function getOutputHandlers(): array
124
    {
125
        return $this->handlersOut;
126
    }
127
128
    /**
129
     * Getter for {@see PropertyData::$handlersIn}.
130
     *
131
     * @return string[] {@see PropertyData::$handlersIn}
132
     */
133
    public function getInputHandlers(): array
134
    {
135
        return $this->handlersIn;
136
    }
137
138
    /**
139
     * Getter for {@see PropertyData::$type}.
140
     *
141
     * @return array {@see PropertyData::$type}
142
     */
143
    public function getTypeTree(): array
144
    {
145
        return $this->type;
146
    }
147
148
    /**
149
     * Getter for {@see PropertyData::$alias}.
150
     *
151
     * @return string {@see PropertyData::$alias}
152
     */
153
    public function getName(): string
154
    {
155
        return $this->alias;
156
    }
157
}
158