Passed
Push — main ( 7f530d...7aae9b )
by Thierry
05:54
created
jaxon-core/src/Plugin/Request/CallableClass/ComponentOptions.php 1 patch
Spacing   +22 added lines, -25 removed lines patch added patch discarded remove patch
@@ -106,18 +106,18 @@  discard block
 block discarded – undo
106 106
         $sSeparator = $aOptions['separator'] ?? '.';
107 107
         $this->sSeparator = $sSeparator === '_' ? '_' : '.';
108 108
         $this->addProtectedMethods($aOptions['protected'] ?? []);
109
-        foreach($aOptions['functions'] ?? [] as $sNames => $aFunctionOptions)
109
+        foreach ($aOptions['functions'] ?? [] as $sNames => $aFunctionOptions)
110 110
         {
111 111
             // Names are in a comma-separated list.
112 112
             $aFunctionNames = explode(',', $sNames);
113
-            foreach($aFunctionNames as $sFunctionName)
113
+            foreach ($aFunctionNames as $sFunctionName)
114 114
             {
115 115
                 $this->addFunctionOptions($sFunctionName, $aFunctionOptions);
116 116
             }
117 117
         }
118 118
 
119 119
         // Options from the attributes or annotations.
120
-        if($xMetadata !== null)
120
+        if ($xMetadata !== null)
121 121
         {
122 122
             $this->readMetadataOptions($xMetadata);
123 123
         }
@@ -133,8 +133,7 @@  discard block
 block discarded – undo
133 133
     private function addProtectedMethods(array|string $xMethods): void
134 134
     {
135 135
         $this->aExportMethods['except'] = array_merge($this->aExportMethods['except'],
136
-            !is_array($xMethods) ? [trim((string)$xMethods)] :
137
-            array_map(fn($sMethod) => trim((string)$sMethod), $xMethods));
136
+            !is_array($xMethods) ? [trim((string)$xMethods)] : array_map(fn($sMethod) => trim((string)$sMethod), $xMethods));
138 137
     }
139 138
 
140 139
     /**
@@ -149,7 +148,7 @@  discard block
 block discarded – undo
149 148
         $aExportMethods['except'] = array_unique(array_merge(
150 149
             $aExportMethods['except'] ?? [], $this->aExportMethods['except']));
151 150
         $this->aExportMethods = $aExportMethods;
152
-        foreach($xMetadata->getProperties() as $sFunctionName => $aFunctionOptions)
151
+        foreach ($xMetadata->getProperties() as $sFunctionName => $aFunctionOptions)
153 152
         {
154 153
             $this->addFunctionOptions($sFunctionName, $aFunctionOptions);
155 154
         }
@@ -162,7 +161,7 @@  discard block
 block discarded – undo
162 161
      */
163 162
     private function filterPublicMethods(array $aMethods): array
164 163
     {
165
-        if($this->bExcluded || in_array('*', $this->aExportMethods['except']))
164
+        if ($this->bExcluded || in_array('*', $this->aExportMethods['except']))
166 165
         {
167 166
             return [];
168 167
         }
@@ -170,12 +169,12 @@  discard block
 block discarded – undo
170 169
         $aBaseMethods = $aMethods[1];
171 170
         $aNoMethods = $aMethods[2];
172 171
         $aMethods = $aMethods[0];
173
-        if(isset($this->aExportMethods['only']))
172
+        if (isset($this->aExportMethods['only']))
174 173
         {
175 174
             $aMethods = array_intersect($aMethods, $this->aExportMethods['only']);
176 175
         }
177 176
         $aMethods = array_diff($aMethods, $this->aExportMethods['except']);
178
-        if(count($aBaseMethods) > 0 && isset($this->aExportMethods['base']))
177
+        if (count($aBaseMethods) > 0 && isset($this->aExportMethods['base']))
179 178
         {
180 179
             $aBaseMethods = array_diff($aBaseMethods, $this->aExportMethods['base']);
181 180
         }
@@ -261,19 +260,19 @@  discard block
 block discarded – undo
261 260
      */
262 261
     private function setHookMethods(array &$aHookMethods, $xValue): void
263 262
     {
264
-        foreach($xValue as $sCalledMethod => $xMethodToCall)
263
+        foreach ($xValue as $sCalledMethod => $xMethodToCall)
265 264
         {
266
-            if(!isset($aHookMethods[$sCalledMethod]))
265
+            if (!isset($aHookMethods[$sCalledMethod]))
267 266
             {
268 267
                 $aHookMethods[$sCalledMethod] = [];
269 268
             }
270
-            if(is_array($xMethodToCall))
269
+            if (is_array($xMethodToCall))
271 270
             {
272 271
                 $aHookMethods[$sCalledMethod] =
273 272
                     array_merge($aHookMethods[$sCalledMethod], $xMethodToCall);
274 273
                 continue;
275 274
             }
276
-            if(is_string($xMethodToCall))
275
+            if (is_string($xMethodToCall))
277 276
             {
278 277
                 $aHookMethods[$sCalledMethod][] = $xMethodToCall;
279 278
             }
@@ -298,7 +297,7 @@  discard block
 block discarded – undo
298 297
      */
299 298
     private function addOption(string $sName, $xValue): void
300 299
     {
301
-        switch($sName)
300
+        switch ($sName)
302 301
         {
303 302
         // Set the methods to call before processing the request
304 303
         case '__before':
@@ -326,11 +325,11 @@  discard block
 block discarded – undo
326 325
      */
327 326
     private function _addJsArrayOption(string $sFunctionName, string $sOptionName, $xOptionValue): void
328 327
     {
329
-        if(is_string($xOptionValue))
328
+        if (is_string($xOptionValue))
330 329
         {
331 330
             $xOptionValue = [$xOptionValue];
332 331
         }
333
-        if(!is_array($xOptionValue))
332
+        if (!is_array($xOptionValue))
334 333
         {
335 334
             return; // Do not save.
336 335
         }
@@ -360,10 +359,10 @@  discard block
 block discarded – undo
360 359
      */
361 360
     private function addJsOption(string $sFunctionName, string $sOptionName, $xOptionValue): void
362 361
     {
363
-        switch($sOptionName)
362
+        switch ($sOptionName)
364 363
         {
365 364
         case 'excluded':
366
-            if((bool)$xOptionValue)
365
+            if ((bool)$xOptionValue)
367 366
             {
368 367
                 $this->addProtectedMethods($sFunctionName);
369 368
             }
@@ -387,12 +386,11 @@  discard block
 block discarded – undo
387 386
      */
388 387
     private function addFunctionOptions(string $sFunctionName, array $aFunctionOptions): void
389 388
     {
390
-        foreach($aFunctionOptions as $sOptionName => $xOptionValue)
389
+        foreach ($aFunctionOptions as $sOptionName => $xOptionValue)
391 390
         {
392 391
             substr($sOptionName, 0, 2) === '__' ?
393 392
                 // Options for PHP classes. They start with "__".
394
-                $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) :
395
-                // Options for javascript code.
393
+                $this->addOption($sOptionName, [$sFunctionName => $xOptionValue]) : // Options for javascript code.
396 394
                 $this->addJsOption($sFunctionName, $sOptionName, $xOptionValue);
397 395
         }
398 396
     }
@@ -408,16 +406,15 @@  discard block
 block discarded – undo
408 406
         $aOptions = array_merge($this->aJsOptions['*'] ?? []); // Clone the array
409 407
         // Then add the method options.
410 408
         $aMethodOptions = $this->aJsOptions[$sMethodName] ?? [];
411
-        foreach($aMethodOptions as $sOptionName => $xOptionValue)
409
+        foreach ($aMethodOptions as $sOptionName => $xOptionValue)
412 410
         {
413 411
             // For databags and callbacks, merge the values in a single array.
414 412
             // For all the other options, keep the last value.
415 413
             $aOptions[$sOptionName] = !in_array($sOptionName, ['bags', 'callback']) ?
416
-                $xOptionValue :
417
-                array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue));
414
+                $xOptionValue : array_unique(array_merge($aOptions[$sOptionName] ?? [], $xOptionValue));
418 415
         }
419 416
         // Since callbacks are js object names, they need a special formatting.
420
-        if(isset($aOptions['callback']))
417
+        if (isset($aOptions['callback']))
421 418
         {
422 419
             $aOptions['callback'] = str_replace('"', '', json_encode($aOptions['callback']));
423 420
         }
Please login to merge, or discard this patch.
jaxon-attributes/src/Attribute/Inject.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
 
22 22
 use function ltrim;
23 23
 
24
-#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_PROPERTY |
25
-    Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
24
+#[Attribute(Attribute::TARGET_CLASS|Attribute::TARGET_PROPERTY|
25
+    Attribute::TARGET_METHOD|Attribute::IS_REPEATABLE)]
26 26
 class Inject extends AbstractAttribute
27 27
 {
28 28
     /**
@@ -78,17 +78,17 @@  discard block
 block discarded – undo
78 78
      */
79 79
     public function validate(): void
80 80
     {
81
-        if($this->nTarget === Attribute::TARGET_CLASS)
81
+        if ($this->nTarget === Attribute::TARGET_CLASS)
82 82
         {
83
-            if(!$this->attr || !$this->type)
83
+            if (!$this->attr || !$this->type)
84 84
             {
85 85
                 throw new SetupException('When applied to a class, the Inject attribute requires two arguments.');
86 86
             }
87 87
             return;
88 88
         }
89
-        if($this->nTarget === Attribute::TARGET_METHOD)
89
+        if ($this->nTarget === Attribute::TARGET_METHOD)
90 90
         {
91
-            if(!$this->attr)
91
+            if (!$this->attr)
92 92
             {
93 93
                 throw new SetupException('When applied to a method, the Inject attribute requires the "attr" argument.');
94 94
             }
@@ -100,13 +100,13 @@  discard block
 block discarded – undo
100 100
      */
101 101
     private function getFullClassName(): void
102 102
     {
103
-        if(!$this->type)
103
+        if (!$this->type)
104 104
         {
105 105
             // If no type is provided, take the attribute type.
106 106
             $this->type = $this->aTypes[$this->attr] ?? '';
107 107
             return;
108 108
         }
109
-        if($this->type[0] === '\\')
109
+        if ($this->type[0] === '\\')
110 110
         {
111 111
             $this->type = ltrim($this->type, '\\');
112 112
         }
Please login to merge, or discard this patch.
jaxon-attributes/src/AttributeReader.php 1 patch
Spacing   +19 added lines, -21 removed lines patch added patch discarded remove patch
@@ -82,19 +82,19 @@  discard block
 block discarded – undo
82 82
     private function readTypes(ReflectionClass $xClass)
83 83
     {
84 84
         $sClass = $xClass->getName();
85
-        if(isset($this->aTypes[$sClass]))
85
+        if (isset($this->aTypes[$sClass]))
86 86
         {
87 87
             return;
88 88
         }
89 89
 
90 90
         $this->aTypes[$sClass] = [];
91
-        $aProperties = $xClass->getProperties(ReflectionProperty::IS_PUBLIC |
91
+        $aProperties = $xClass->getProperties(ReflectionProperty::IS_PUBLIC|
92 92
             ReflectionProperty::IS_PROTECTED);
93
-        foreach($aProperties as $xReflectionProperty)
93
+        foreach ($aProperties as $xReflectionProperty)
94 94
         {
95 95
             $xType = $xReflectionProperty->getType();
96 96
             // Check that the property has a valid type defined
97
-            if(is_a($xType, ReflectionNamedType::class) &&
97
+            if (is_a($xType, ReflectionNamedType::class) &&
98 98
                 ($sType = $xType->getName()) !== '')
99 99
             {
100 100
                 $this->aTypes[$sClass][$xReflectionProperty->getName()] = $sType;
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
     private function initAttribute(AbstractAttribute $xAttribute,
113 113
         ReflectionClass $xClass, ReflectionAttribute $xReflectionAttribute): void
114 114
     {
115
-        if(is_a($xAttribute, InjectAttribute::class))
115
+        if (is_a($xAttribute, InjectAttribute::class))
116 116
         {
117 117
             $this->readTypes($xClass);
118 118
             $xAttribute->setTarget($xReflectionAttribute->getTarget());
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
         $aAttributes = $xClass->getAttributes();
161 161
         $aAttributes = array_filter($aAttributes, fn($xReflectionAttribute) =>
162 162
             $this->isBaseClassAttribute($xReflectionAttribute));
163
-        foreach($aAttributes as $xReflectionAttribute)
163
+        foreach ($aAttributes as $xReflectionAttribute)
164 164
         {
165 165
             $xReflectionAttribute->newInstance()->saveValue($this->xMetadata);
166 166
         }
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
         $aAttributes = array_filter($aAttributes, fn($xReflectionAttribute) =>
178 178
             $this->isJaxonAttribute($xReflectionAttribute) &&
179 179
             !$this->isBaseClassAttribute($xReflectionAttribute));
180
-        foreach($aAttributes as $xReflectionAttribute)
180
+        foreach ($aAttributes as $xReflectionAttribute)
181 181
         {
182 182
             $xAttribute = $xReflectionAttribute->newInstance();
183 183
             $this->initAttribute($xAttribute, $xClass, $xReflectionAttribute);
@@ -195,17 +195,16 @@  discard block
 block discarded – undo
195 195
      */
196 196
     private function readPropertyAttributes(ReflectionClass $xClass, string $sProperty): void
197 197
     {
198
-        $aAttributes = !$xClass->hasProperty($sProperty) ? [] :
199
-            $xClass->getProperty($sProperty)->getAttributes();
198
+        $aAttributes = !$xClass->hasProperty($sProperty) ? [] : $xClass->getProperty($sProperty)->getAttributes();
200 199
         $aAttributes = array_filter($aAttributes, fn($xReflectionAttribute) =>
201 200
             $this->isPropertyAttribute($xReflectionAttribute));
202 201
         // Only Inject attributes are allowed on properties
203
-        if(count($aAttributes) > 1)
202
+        if (count($aAttributes) > 1)
204 203
         {
205 204
             throw new SetupException('Only one Inject attribute is allowed on a property');
206 205
         }
207 206
 
208
-        foreach($aAttributes as $xReflectionAttribute)
207
+        foreach ($aAttributes as $xReflectionAttribute)
209 208
         {
210 209
             /** @var InjectAttribute */
211 210
             $xAttribute = $xReflectionAttribute->newInstance();
@@ -224,11 +223,10 @@  discard block
 block discarded – undo
224 223
      */
225 224
     private function readMethodAttributes(ReflectionClass $xClass, string $sMethod): void
226 225
     {
227
-        $aAttributes = !$xClass->hasMethod($sMethod) ? [] :
228
-            $xClass->getMethod($sMethod)->getAttributes();
226
+        $aAttributes = !$xClass->hasMethod($sMethod) ? [] : $xClass->getMethod($sMethod)->getAttributes();
229 227
         $aAttributes = array_filter($aAttributes, fn($xReflectionAttribute) =>
230 228
             $this->isJaxonAttribute($xReflectionAttribute));
231
-        foreach($aAttributes as $xReflectionAttribute)
229
+        foreach ($aAttributes as $xReflectionAttribute)
232 230
         {
233 231
             $xAttribute = $xReflectionAttribute->newInstance();
234 232
             $this->initAttribute($xAttribute, $xClass, $xReflectionAttribute);
@@ -263,33 +261,33 @@  discard block
 block discarded – undo
263 261
             $this->readBaseClassAttributes($xClass);
264 262
 
265 263
             $aClasses = [$xClass];
266
-            while(($xClass = $this->getParentClass($xClass)) !== null)
264
+            while (($xClass = $this->getParentClass($xClass)) !== null)
267 265
             {
268 266
                 $aClasses[] = $xClass;
269 267
             }
270 268
             $aClasses = array_reverse($aClasses);
271 269
 
272
-            foreach($aClasses as $xClass)
270
+            foreach ($aClasses as $xClass)
273 271
             {
274 272
                 // Processing class attributes
275 273
                 $this->readClassAttributes($xClass);
276 274
                 // Processing properties attributes
277
-                foreach($xInput->getProperties() as $sProperty)
275
+                foreach ($xInput->getProperties() as $sProperty)
278 276
                 {
279 277
                     $this->readPropertyAttributes($xClass, $sProperty);
280 278
                 }
281 279
             }
282 280
 
283 281
             // The methods attributes are not taken for excluded classes.
284
-            if($this->xMetadata->isExcluded())
282
+            if ($this->xMetadata->isExcluded())
285 283
             {
286 284
                 return $this->xMetadata;
287 285
             }
288 286
 
289
-            foreach($aClasses as $xClass)
287
+            foreach ($aClasses as $xClass)
290 288
             {
291 289
                 // Processing methods attributes
292
-                foreach($xInput->getMethods() as $sMethod)
290
+                foreach ($xInput->getMethods() as $sMethod)
293 291
                 {
294 292
                     $this->readMethodAttributes($xClass, $sMethod);
295 293
                 }
@@ -297,7 +295,7 @@  discard block
 block discarded – undo
297 295
 
298 296
             return $this->xMetadata;
299 297
         }
300
-        catch(Exception|Error $e)
298
+        catch (Exception|Error $e)
301 299
         {
302 300
             throw new SetupException($e->getMessage());
303 301
         }
Please login to merge, or discard this patch.
jaxon-annotations/src/AnnotationReader.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -116,21 +116,21 @@  discard block
 block discarded – undo
116 116
             fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class)
117 117
         );
118 118
         // First check if the class is excluded.
119
-        foreach($aAnnotations as $xAnnotation)
119
+        foreach ($aAnnotations as $xAnnotation)
120 120
         {
121
-            if(is_a($xAnnotation, ExcludeAnnotation::class))
121
+            if (is_a($xAnnotation, ExcludeAnnotation::class))
122 122
             {
123 123
                 $xAnnotation->saveValue($this->xMetadata);
124 124
             }
125 125
         }
126
-        if($this->xMetadata->isExcluded())
126
+        if ($this->xMetadata->isExcluded())
127 127
         {
128 128
             return;
129 129
         }
130 130
 
131
-        foreach($aAnnotations as $xAnnotation)
131
+        foreach ($aAnnotations as $xAnnotation)
132 132
         {
133
-            if(!is_a($xAnnotation, ExcludeAnnotation::class))
133
+            if (!is_a($xAnnotation, ExcludeAnnotation::class))
134 134
             {
135 135
                 $xAnnotation->saveValue($this->xMetadata);
136 136
             }
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
             $this->xManager->getPropertyAnnotations($sClass, $sProperty),
153 153
             function($xAnnotation) use($sProperty) {
154 154
                 // Save the property type
155
-                if(is_a($xAnnotation, VarAnnotation::class))
155
+                if (is_a($xAnnotation, VarAnnotation::class))
156 156
                 {
157 157
                     $this->aPropTypes[$sProperty] = $xAnnotation->type;
158 158
                 }
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
                 return is_a($xAnnotation, ContainerAnnotation::class);
161 161
             }
162 162
         );
163
-        if(count($aAnnotations) > 1)
163
+        if (count($aAnnotations) > 1)
164 164
         {
165 165
             throw new AnnotationException('Only one @di annotation is allowed on a property');
166 166
         }
167 167
 
168
-        foreach($aAnnotations as $xAnnotation)
168
+        foreach ($aAnnotations as $xAnnotation)
169 169
         {
170 170
             $xAnnotation->setAttr($sProperty);
171 171
             $xAnnotation->saveValue($this->xMetadata);
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
             $this->xManager->getMethodAnnotations($sClass, $sMethod),
188 188
             fn($xAnnotation) => is_a($xAnnotation, AbstractAnnotation::class)
189 189
         );
190
-        foreach($aAnnotations as $xAnnotation)
190
+        foreach ($aAnnotations as $xAnnotation)
191 191
         {
192 192
             $xAnnotation->saveValue($this->xMetadata, $sMethod);
193 193
         }
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
             $this->sCurrMemberType = AnnotationManager::MEMBER_PROPERTY;
215 215
 
216 216
             // Properties annotations
217
-            foreach($xInput->getProperties() as $sProperty)
217
+            foreach ($xInput->getProperties() as $sProperty)
218 218
             {
219 219
                 $this->readPropertyAnnotations($sClass, $sProperty);
220 220
             }
221 221
 
222 222
             // The methods annotations are not taken for excluded classes.
223
-            if($this->xMetadata->isExcluded())
223
+            if ($this->xMetadata->isExcluded())
224 224
             {
225 225
                 return $this->xMetadata;
226 226
             }
@@ -228,14 +228,14 @@  discard block
 block discarded – undo
228 228
             // Processing methods annotations
229 229
             $this->sCurrMemberType = AnnotationManager::MEMBER_METHOD;
230 230
 
231
-            foreach($xInput->getMethods() as $sMethod)
231
+            foreach ($xInput->getMethods() as $sMethod)
232 232
             {
233 233
                 $this->readMethodAnnotations($sClass, $sMethod);
234 234
             }
235 235
 
236 236
             return $this->xMetadata;
237 237
         }
238
-        catch(AnnotationException $e)
238
+        catch (AnnotationException $e)
239 239
         {
240 240
             throw new SetupException($e->getMessage());
241 241
         }
Please login to merge, or discard this patch.