@@ -136,15 +136,13 @@ |
||
136 | 136 | if(isset($aMethodAttrs['protected'])) |
137 | 137 | { |
138 | 138 | $aProtected[] = $sMethod; // The method is not to be exported. |
139 | - } |
|
140 | - elseif(count($aMethodAttrs) > 0) |
|
139 | + } elseif(count($aMethodAttrs) > 0) |
|
141 | 140 | { |
142 | 141 | $aAttributes[$sMethod] = $aMethodAttrs; |
143 | 142 | } |
144 | 143 | } |
145 | 144 | return [false, $aAttributes, $aProtected]; |
146 | - } |
|
147 | - catch(AnnotationException $e) |
|
145 | + } catch(AnnotationException $e) |
|
148 | 146 | { |
149 | 147 | throw new SetupException($e->getMessage()); |
150 | 148 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | public static function register(Container $di, bool $bForce = false) |
80 | 80 | { |
81 | - if(!$bForce && $di->h(AnnotationReader::class)) |
|
81 | + if (!$bForce && $di->h(AnnotationReader::class)) |
|
82 | 82 | { |
83 | 83 | return; |
84 | 84 | } |
@@ -114,13 +114,13 @@ discard block |
||
114 | 114 | }); |
115 | 115 | |
116 | 116 | $aAttributes = []; |
117 | - foreach($aAnnotations as $xAnnotation) |
|
117 | + foreach ($aAnnotations as $xAnnotation) |
|
118 | 118 | { |
119 | 119 | $xAnnotation->setReader($this); |
120 | 120 | $sName = $xAnnotation->getName(); |
121 | 121 | $xAnnotation->setPrevValue($aAttributes[$sName] ?? null); |
122 | 122 | $xValue = $xAnnotation->getValue(); |
123 | - if($sName === 'protected' && !$xValue) |
|
123 | + if ($sName === 'protected' && !$xValue) |
|
124 | 124 | { |
125 | 125 | continue; // Ignore annotation @exclude with value false |
126 | 126 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | // Only keep the annotations declared in this package. |
142 | 142 | $aAnnotations = array_filter($aAnnotations, function($xAnnotation) use($sProperty) { |
143 | 143 | // Save the property type |
144 | - if(is_a($xAnnotation, VarAnnotation::class)) |
|
144 | + if (is_a($xAnnotation, VarAnnotation::class)) |
|
145 | 145 | { |
146 | 146 | $this->aPropTypes[$sProperty] = $xAnnotation->type; |
147 | 147 | } |
@@ -150,11 +150,11 @@ discard block |
||
150 | 150 | }); |
151 | 151 | |
152 | 152 | $nCount = count($aAnnotations); |
153 | - if($nCount === 0) |
|
153 | + if ($nCount === 0) |
|
154 | 154 | { |
155 | 155 | return ['', null]; |
156 | 156 | } |
157 | - if($nCount > 1) |
|
157 | + if ($nCount > 1) |
|
158 | 158 | { |
159 | 159 | throw new AnnotationException('Only one @di annotation is allowed on a property'); |
160 | 160 | } |
@@ -185,10 +185,10 @@ discard block |
||
185 | 185 | $this->aPropTypes = []; |
186 | 186 | $aPropAttrs = []; |
187 | 187 | // Properties annotations |
188 | - foreach($aProperties as $sProperty) |
|
188 | + foreach ($aProperties as $sProperty) |
|
189 | 189 | { |
190 | 190 | [$sName, $xValue] = $this->propAnnotations($sProperty, $this->xManager->getPropertyAnnotations($sClass, $sProperty)); |
191 | - if(!$xValue) |
|
191 | + if (!$xValue) |
|
192 | 192 | { |
193 | 193 | continue; |
194 | 194 | } |
@@ -199,19 +199,19 @@ discard block |
||
199 | 199 | ContainerAnnotation::$sMemberType = AnnotationManager::MEMBER_CLASS; |
200 | 200 | |
201 | 201 | $aClassAttrs = $this->filterAnnotations($this->xManager->getClassAnnotations($sClass)); |
202 | - if(isset($aClassAttrs['protected'])) |
|
202 | + if (isset($aClassAttrs['protected'])) |
|
203 | 203 | { |
204 | 204 | return [true, [], []]; // The entire class is not to be exported. |
205 | 205 | } |
206 | 206 | |
207 | 207 | // Merge attributes and class annotations |
208 | - foreach($aPropAttrs as $sName => $xValue) |
|
208 | + foreach ($aPropAttrs as $sName => $xValue) |
|
209 | 209 | { |
210 | 210 | $aClassAttrs[$sName] = array_merge($aClassAttrs[$sName] ?? [], $xValue); |
211 | 211 | } |
212 | 212 | |
213 | 213 | $aAttributes = []; |
214 | - if(count($aClassAttrs) > 0) |
|
214 | + if (count($aClassAttrs) > 0) |
|
215 | 215 | { |
216 | 216 | $aAttributes['*'] = $aClassAttrs; |
217 | 217 | } |
@@ -220,21 +220,21 @@ discard block |
||
220 | 220 | ContainerAnnotation::$sMemberType = AnnotationManager::MEMBER_METHOD; |
221 | 221 | |
222 | 222 | $aProtected = []; |
223 | - foreach($aMethods as $sMethod) |
|
223 | + foreach ($aMethods as $sMethod) |
|
224 | 224 | { |
225 | 225 | $aMethodAttrs = $this->filterAnnotations($this->xManager->getMethodAnnotations($sClass, $sMethod)); |
226 | - if(isset($aMethodAttrs['protected'])) |
|
226 | + if (isset($aMethodAttrs['protected'])) |
|
227 | 227 | { |
228 | 228 | $aProtected[] = $sMethod; // The method is not to be exported. |
229 | 229 | } |
230 | - elseif(count($aMethodAttrs) > 0) |
|
230 | + elseif (count($aMethodAttrs) > 0) |
|
231 | 231 | { |
232 | 232 | $aAttributes[$sMethod] = $aMethodAttrs; |
233 | 233 | } |
234 | 234 | } |
235 | 235 | return [false, $aAttributes, $aProtected]; |
236 | 236 | } |
237 | - catch(AnnotationException $e) |
|
237 | + catch (AnnotationException $e) |
|
238 | 238 | { |
239 | 239 | throw new SetupException($e->getMessage()); |
240 | 240 | } |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function initAnnotation(array $properties) |
63 | 63 | { |
64 | - if(count($properties) !== 1 || !isset($properties['name']) || !is_string($properties['name'])) |
|
64 | + if (count($properties) !== 1 || !isset($properties['name']) || !is_string($properties['name'])) |
|
65 | 65 | { |
66 | 66 | throw new AnnotationException('The @databag annotation requires a property "name" of type string'); |
67 | 67 | } |
68 | - if(!$this->validateDataBagName($properties['name'])) |
|
68 | + if (!$this->validateDataBagName($properties['name'])) |
|
69 | 69 | { |
70 | 70 | throw new AnnotationException($properties['name'] . ' is not a valid "name" value for the @databag annotation'); |
71 | 71 | } |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | */ |
86 | 86 | public function getValue() |
87 | 87 | { |
88 | - if(is_array($this->xPrevValue)) |
|
88 | + if (is_array($this->xPrevValue)) |
|
89 | 89 | { |
90 | 90 | $this->xPrevValue[] = $this->sName; // Append the current value to the array |
91 | 91 | return $this->xPrevValue; |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | public static function parseAnnotation($value) |
58 | 58 | { |
59 | 59 | $aParams = preg_split("/[\s]+/", $value, 2); |
60 | - if(count($aParams) === 1) |
|
60 | + if (count($aParams) === 1) |
|
61 | 61 | { |
62 | 62 | return ['call' => rtrim($aParams[0])]; |
63 | 63 | } |
@@ -81,28 +81,28 @@ discard block |
||
81 | 81 | */ |
82 | 82 | public function initAnnotation(array $properties) |
83 | 83 | { |
84 | - if(!isset($properties['call']) || !is_string($properties['call'])) |
|
84 | + if (!isset($properties['call']) || !is_string($properties['call'])) |
|
85 | 85 | { |
86 | 86 | throw new AnnotationException('The @' . $this->getType() . |
87 | 87 | ' annotation requires a property "call" of type string'); |
88 | 88 | } |
89 | - if(!$this->validateMethodName($properties['call'])) |
|
89 | + if (!$this->validateMethodName($properties['call'])) |
|
90 | 90 | { |
91 | 91 | throw new AnnotationException($properties['call'] . |
92 | 92 | ' is not a valid "call" value for the @' . $this->getType() . ' annotation'); |
93 | 93 | } |
94 | - foreach(array_keys($properties) as $propName) |
|
94 | + foreach (array_keys($properties) as $propName) |
|
95 | 95 | { |
96 | - if($propName !== 'call' && $propName !== 'with') |
|
96 | + if ($propName !== 'call' && $propName !== 'with') |
|
97 | 97 | { |
98 | 98 | throw new AnnotationException('Unknown property "' . $propName . |
99 | 99 | '" in the @' . $this->getType() . ' annotation'); |
100 | 100 | } |
101 | 101 | } |
102 | 102 | // Cannot use isset here, because it will return false in case $properties['with'] === null |
103 | - if(array_key_exists('with', $properties)) |
|
103 | + if (array_key_exists('with', $properties)) |
|
104 | 104 | { |
105 | - if(!is_array($properties['with'])) |
|
105 | + if (!is_array($properties['with'])) |
|
106 | 106 | { |
107 | 107 | throw new AnnotationException('The "with" property of the @' . |
108 | 108 | $this->getType() . ' annotation must be of type array'); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function getValue() |
119 | 119 | { |
120 | - if(is_array($this->xPrevValue)) |
|
120 | + if (is_array($this->xPrevValue)) |
|
121 | 121 | { |
122 | 122 | // Add the current value to the array |
123 | 123 | $this->xPrevValue[$this->sMethodName] = $this->sMethodParams; |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public static function parseAnnotation($value) |
40 | 40 | { |
41 | - if($value === 'true') |
|
41 | + if ($value === 'true') |
|
42 | 42 | { |
43 | 43 | return [true]; |
44 | 44 | } |
45 | - if($value === 'false') |
|
45 | + if ($value === 'false') |
|
46 | 46 | { |
47 | 47 | return [false]; |
48 | 48 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | */ |
56 | 56 | public function initAnnotation(array $properties) |
57 | 57 | { |
58 | - if(count($properties) !== 0 && |
|
58 | + if (count($properties) !== 0 && |
|
59 | 59 | (count($properties) !== 1 || !isset($properties[0]) || !is_bool($properties[0]))) |
60 | 60 | { |
61 | 61 | throw new AnnotationException('the @exclude annotation requires a single boolean or no property'); |
@@ -60,11 +60,11 @@ discard block |
||
60 | 60 | */ |
61 | 61 | public function initAnnotation(array $properties) |
62 | 62 | { |
63 | - if(count($properties) != 1 || !isset($properties['field']) || !is_string($properties['field'])) |
|
63 | + if (count($properties) != 1 || !isset($properties['field']) || !is_string($properties['field'])) |
|
64 | 64 | { |
65 | 65 | throw new AnnotationException('The @upload annotation requires a property "field" of type string'); |
66 | 66 | } |
67 | - if(!$this->validateUploadField($properties['field'])) |
|
67 | + if (!$this->validateUploadField($properties['field'])) |
|
68 | 68 | { |
69 | 69 | throw new AnnotationException($properties['field'] . ' is not a valid "field" value for the @upload annotation'); |
70 | 70 | } |
@@ -84,6 +84,6 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public function getValue() |
86 | 86 | { |
87 | - return "'" . $this->sField . "'" ; // The field id is surrounded with simple quotes. |
|
87 | + return "'" . $this->sField . "'"; // The field id is surrounded with simple quotes. |
|
88 | 88 | } |
89 | 89 | } |
@@ -105,43 +105,43 @@ discard block |
||
105 | 105 | { |
106 | 106 | $aParams = preg_split("/[\s]+/", $value, 3); |
107 | 107 | $nParamCount = count($aParams); |
108 | - if($nParamCount === 1) |
|
108 | + if ($nParamCount === 1) |
|
109 | 109 | { |
110 | 110 | // For a property, the only parameter is the class. Otherwise, it is the attribute. |
111 | - if(self::$sMemberType === AnnotationManager::MEMBER_PROPERTY) |
|
111 | + if (self::$sMemberType === AnnotationManager::MEMBER_PROPERTY) |
|
112 | 112 | { |
113 | 113 | $sClass = rtrim($aParams[0]); |
114 | - if(substr($sClass, 0, 1) === '$') |
|
114 | + if (substr($sClass, 0, 1) === '$') |
|
115 | 115 | { |
116 | 116 | throw new AnnotationException('The only property of the @di annotation must be a class name'); |
117 | 117 | } |
118 | 118 | return ['class' => $sClass]; |
119 | 119 | } |
120 | 120 | $sAttr = rtrim($aParams[0]); |
121 | - if(substr($sAttr, 0, 1) !== '$') |
|
121 | + if (substr($sAttr, 0, 1) !== '$') |
|
122 | 122 | { |
123 | 123 | throw new AnnotationException('The only property of the @di annotation must be a var name'); |
124 | 124 | } |
125 | - return ['attr' => substr($sAttr,1)]; |
|
125 | + return ['attr' => substr($sAttr, 1)]; |
|
126 | 126 | } |
127 | - if($nParamCount === 2) |
|
127 | + if ($nParamCount === 2) |
|
128 | 128 | { |
129 | - if(self::$sMemberType === AnnotationManager::MEMBER_PROPERTY) |
|
129 | + if (self::$sMemberType === AnnotationManager::MEMBER_PROPERTY) |
|
130 | 130 | { |
131 | 131 | throw new AnnotationException('The @di annotation accepts only one property on a class attribute'); |
132 | 132 | } |
133 | 133 | $sAttr = rtrim($aParams[0]); |
134 | - if(substr($sAttr, 0, 1) !== '$') |
|
134 | + if (substr($sAttr, 0, 1) !== '$') |
|
135 | 135 | { |
136 | 136 | throw new AnnotationException('The only property of the @di annotation must be a var name'); |
137 | 137 | } |
138 | 138 | $sClass = rtrim($aParams[1]); |
139 | - if(substr($sClass, 0, 1) === '$') |
|
139 | + if (substr($sClass, 0, 1) === '$') |
|
140 | 140 | { |
141 | 141 | throw new AnnotationException('The first property of the @di annotation must be a class name'); |
142 | 142 | } |
143 | 143 | // For a property, having 2 parameters is not allowed. |
144 | - return ['attr' => substr($sAttr,1), 'class' => $sClass]; |
|
144 | + return ['attr' => substr($sAttr, 1), 'class' => $sClass]; |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | throw new AnnotationException('The @di annotation only accepts one or two properties'); |
@@ -153,33 +153,33 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function initAnnotation(array $properties) |
155 | 155 | { |
156 | - if(isset($properties['__raw'])) |
|
156 | + if (isset($properties['__raw'])) |
|
157 | 157 | { |
158 | 158 | $properties = $this->parseValue($properties['__raw']); |
159 | 159 | } |
160 | 160 | $nCount = count($properties); |
161 | - if($nCount > 2 || |
|
161 | + if ($nCount > 2 || |
|
162 | 162 | ($nCount === 2 && !(isset($properties['attr']) && isset($properties['class']))) || |
163 | 163 | ($nCount === 1 && !(isset($properties['attr']) || isset($properties['class'])))) |
164 | 164 | { |
165 | 165 | throw new AnnotationException('The @di annotation accepts only "attr" or "class" as properties'); |
166 | 166 | } |
167 | 167 | |
168 | - if(isset($properties['attr'])) |
|
168 | + if (isset($properties['attr'])) |
|
169 | 169 | { |
170 | - if(self::$sMemberType === AnnotationManager::MEMBER_PROPERTY) |
|
170 | + if (self::$sMemberType === AnnotationManager::MEMBER_PROPERTY) |
|
171 | 171 | { |
172 | 172 | throw new AnnotationException('The @di annotation does not allow the "attr" property on class attributes'); |
173 | 173 | } |
174 | - if(!is_string($properties['attr'])) |
|
174 | + if (!is_string($properties['attr'])) |
|
175 | 175 | { |
176 | 176 | throw new AnnotationException('The @di annotation requires a property "attr" of type string'); |
177 | 177 | } |
178 | 178 | $this->sAttr = $properties['attr']; |
179 | 179 | } |
180 | - if(isset($properties['class'])) |
|
180 | + if (isset($properties['class'])) |
|
181 | 181 | { |
182 | - if(!is_string($properties['class'])) |
|
182 | + if (!is_string($properties['class'])) |
|
183 | 183 | { |
184 | 184 | throw new AnnotationException('The @di annotation requires a property "class" of type string'); |
185 | 185 | } |
@@ -215,20 +215,20 @@ discard block |
||
215 | 215 | { |
216 | 216 | // The type in the @di annotations can be set from the values in the @var annotations |
217 | 217 | $aPropTypes = $this->xReader->getPropTypes(); |
218 | - if($this->sClass === '' && isset($aPropTypes[$this->sAttr])) |
|
218 | + if ($this->sClass === '' && isset($aPropTypes[$this->sAttr])) |
|
219 | 219 | { |
220 | 220 | $this->sClass = ltrim($aPropTypes[$this->sAttr], '\\'); |
221 | 221 | } |
222 | 222 | |
223 | - if(!$this->validateAttrName($this->sAttr)) |
|
223 | + if (!$this->validateAttrName($this->sAttr)) |
|
224 | 224 | { |
225 | 225 | throw new AnnotationException($this->sAttr . ' is not a valid "attr" value for the @di annotation'); |
226 | 226 | } |
227 | - if(!$this->validateClassName($this->sClass)) |
|
227 | + if (!$this->validateClassName($this->sClass)) |
|
228 | 228 | { |
229 | 229 | throw new AnnotationException($this->sClass . ' is not a valid "class" value for the @di annotation'); |
230 | 230 | } |
231 | - if(is_array($this->xPrevValue)) |
|
231 | + if (is_array($this->xPrevValue)) |
|
232 | 232 | { |
233 | 233 | $this->xPrevValue[$this->sAttr] = $this->sClass; // Append the current value to the array |
234 | 234 | return $this->xPrevValue; |