Passed
Push — main ( 813e95...426dc3 )
by Thierry
07:49
created
src/Annotation/ContainerAnnotation.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -105,43 +105,43 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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;
Please login to merge, or discard this patch.
src/AnnotationReader.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.