1 | <?php |
||
10 | class FunctionValidator |
||
11 | { |
||
12 | use TypeValidator; |
||
13 | |||
14 | /** |
||
15 | * A function/method to check the specification of. |
||
16 | * |
||
17 | * @var \ReflectionFunctionAbstract |
||
18 | */ |
||
19 | protected $target; |
||
20 | /** |
||
21 | * Violations collector. |
||
22 | * |
||
23 | * @var BadFunctionDefinitionException |
||
24 | */ |
||
25 | protected $exception; |
||
26 | /** |
||
27 | * A list of arguments that function/method must have. |
||
28 | * |
||
29 | * @var ArgumentSpecification[] |
||
30 | */ |
||
31 | protected $arguments = []; |
||
32 | /** |
||
33 | * A type of returning value by the function. |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $returnType = ''; |
||
38 | /** |
||
39 | * A state whether function must return value by reference. |
||
40 | * |
||
41 | * @var null|bool |
||
42 | */ |
||
43 | protected $returnByReference = null; |
||
44 | |||
45 | /** |
||
46 | * FunctionValidator constructor. |
||
47 | * |
||
48 | * @param \ReflectionFunctionAbstract $function |
||
49 | * A function/method to check the specification of. |
||
50 | */ |
||
51 | 9 | public function __construct(\ReflectionFunctionAbstract $function) |
|
56 | |||
57 | /** |
||
58 | * Defines an argument that function must have. |
||
59 | * |
||
60 | * @param ArgumentSpecification $argument |
||
61 | * A specification of the argument. |
||
62 | * |
||
63 | * @return $this |
||
64 | */ |
||
65 | 6 | public function addArgument(ArgumentSpecification $argument): self |
|
71 | |||
72 | /** |
||
73 | * Require the function to return a value by reference. |
||
74 | * |
||
75 | * @param bool $state |
||
76 | * An indicator of a state. |
||
77 | * |
||
78 | * @return $this |
||
79 | */ |
||
80 | 7 | public function setReturnByReference(bool $state): self |
|
86 | |||
87 | /** |
||
88 | * Require the function to specify a type of returning value. |
||
89 | * |
||
90 | * @param string $type |
||
91 | * A type of returning value. |
||
92 | * |
||
93 | * @return $this |
||
94 | */ |
||
95 | 7 | public function setReturnType(string $type): self |
|
101 | |||
102 | /** |
||
103 | * Runs a validation during destruction. |
||
104 | */ |
||
105 | 9 | public function __destruct() |
|
113 | |||
114 | /** |
||
115 | * Validates arguments of a function. |
||
116 | */ |
||
117 | 9 | protected function checkArguments() |
|
138 | |||
139 | /** |
||
140 | * Validates returning type. |
||
141 | */ |
||
142 | 9 | protected function checkReturnType() |
|
160 | |||
161 | /** |
||
162 | * Validates returning by reference. |
||
163 | */ |
||
164 | 9 | protected function checkReturnByReference() |
|
180 | } |
||
181 |