Passed
Push — main ( cf0b02...938a8d )
by Thierry
03:58
created
jaxon-attributes/src/AttributeReader.php 1 patch
Spacing   +18 added lines, -20 removed lines patch added patch discarded remove patch
@@ -68,19 +68,19 @@  discard block
 block discarded – undo
68 68
     private function readTypes(ReflectionClass $xClass)
69 69
     {
70 70
         $sClass = $xClass->getName();
71
-        if(isset($this->aTypes[$sClass]))
71
+        if (isset($this->aTypes[$sClass]))
72 72
         {
73 73
             return;
74 74
         }
75 75
 
76 76
         $this->aTypes[$sClass] = [];
77
-        $aProperties = $xClass->getProperties(ReflectionProperty::IS_PUBLIC |
77
+        $aProperties = $xClass->getProperties(ReflectionProperty::IS_PUBLIC|
78 78
             ReflectionProperty::IS_PROTECTED);
79
-        foreach($aProperties as $xReflectionProperty)
79
+        foreach ($aProperties as $xReflectionProperty)
80 80
         {
81 81
             $xType = $xReflectionProperty->getType();
82 82
             // Check that the property has a valid type defined
83
-            if(is_a($xType, ReflectionNamedType::class) &&
83
+            if (is_a($xType, ReflectionNamedType::class) &&
84 84
                 ($sType = $xType->getName()) !== '')
85 85
             {
86 86
                 $this->aTypes[$sClass][$xReflectionProperty->getName()] = $sType;
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
     private function initAttribute(AbstractAttribute $xAttribute,
99 99
         ReflectionClass $xClass, ReflectionAttribute $xReflectionAttribute): void
100 100
     {
101
-        if(is_a($xAttribute, InjectAttribute::class))
101
+        if (is_a($xAttribute, InjectAttribute::class))
102 102
         {
103 103
             $this->readTypes($xClass);
104 104
             $xAttribute->setTarget($xReflectionAttribute->getTarget());
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         $aClassAttributes = $xClass->getAttributes();
117 117
         $aAttributes = array_filter($aClassAttributes, fn($xAttribute) =>
118 118
             is_a($xAttribute->getName(), ExcludeAttribute::class, true));
119
-        foreach($aAttributes as $xReflectionAttribute)
119
+        foreach ($aAttributes as $xReflectionAttribute)
120 120
         {
121 121
             $xReflectionAttribute->newInstance()->saveValue($this->xMetadata);
122 122
         }
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
         $aAttributes = array_filter($aClassAttributes, fn($xAttribute) =>
134 134
             is_a($xAttribute->getName(), AbstractAttribute::class, true) &&
135 135
             !is_a($xAttribute->getName(), ExcludeAttribute::class, true));
136
-        foreach($aAttributes as $xReflectionAttribute)
136
+        foreach ($aAttributes as $xReflectionAttribute)
137 137
         {
138 138
             $xAttribute = $xReflectionAttribute->newInstance();
139 139
             $this->initAttribute($xAttribute, $xClass, $xReflectionAttribute);
@@ -152,16 +152,15 @@  discard block
 block discarded – undo
152 152
     private function getPropertyAttrs(ReflectionClass $xClass, string $sProperty): void
153 153
     {
154 154
         // Only Inject attributes are allowed on properties
155
-        $aAttributes = !$xClass->hasProperty($sProperty) ? [] :
156
-            $xClass->getProperty($sProperty)->getAttributes();
155
+        $aAttributes = !$xClass->hasProperty($sProperty) ? [] : $xClass->getProperty($sProperty)->getAttributes();
157 156
         $aAttributes = array_filter($aAttributes, fn($xAttribute) =>
158 157
             is_a($xAttribute->getName(), InjectAttribute::class, true));
159
-        if(count($aAttributes) > 1)
158
+        if (count($aAttributes) > 1)
160 159
         {
161 160
             throw new SetupException('Only one Inject attribute is allowed on a property');
162 161
         }
163 162
 
164
-        foreach($aAttributes as $xReflectionAttribute)
163
+        foreach ($aAttributes as $xReflectionAttribute)
165 164
         {
166 165
             /** @var InjectAttribute */
167 166
             $xAttribute = $xReflectionAttribute->newInstance();
@@ -180,11 +179,10 @@  discard block
 block discarded – undo
180 179
      */
181 180
     private function getMethodAttrs(ReflectionClass $xClass, string $sMethod): void
182 181
     {
183
-        $aAttributes = !$xClass->hasMethod($sMethod) ? [] :
184
-            $xClass->getMethod($sMethod)->getAttributes();
182
+        $aAttributes = !$xClass->hasMethod($sMethod) ? [] : $xClass->getMethod($sMethod)->getAttributes();
185 183
         $aAttributes = array_filter($aAttributes, fn($xAttribute) =>
186 184
             is_a($xAttribute->getName(), AbstractAttribute::class, true));
187
-        foreach($aAttributes as $xReflectionAttribute)
185
+        foreach ($aAttributes as $xReflectionAttribute)
188 186
         {
189 187
             $xAttribute = $xReflectionAttribute->newInstance();
190 188
             $this->initAttribute($xAttribute, $xClass, $xReflectionAttribute);
@@ -219,31 +217,31 @@  discard block
 block discarded – undo
219 217
             $xClass = $xInput->getReflectionClass();
220 218
             // First check if the class is exluded.
221 219
             $this->getClassExcludeAttr($xClass);
222
-            if($this->xMetadata->isExcluded())
220
+            if ($this->xMetadata->isExcluded())
223 221
             {
224 222
                 return $this->xMetadata;
225 223
             }
226 224
 
227 225
             $aClasses = [$xClass];
228
-            while(($xClass = $this->getParentClass($xClass)) !== null)
226
+            while (($xClass = $this->getParentClass($xClass)) !== null)
229 227
             {
230 228
                 $aClasses[] = $xClass;
231 229
             }
232 230
             $aClasses = array_reverse($aClasses);
233 231
 
234
-            foreach($aClasses as $xClass)
232
+            foreach ($aClasses as $xClass)
235 233
             {
236 234
                 // Processing class attributes
237 235
                 $this->getClassAttrs($xClass);
238 236
 
239 237
                 // Processing properties attributes
240
-                foreach($xInput->getProperties() as $sProperty)
238
+                foreach ($xInput->getProperties() as $sProperty)
241 239
                 {
242 240
                     $this->getPropertyAttrs($xClass, $sProperty);
243 241
                 }
244 242
 
245 243
                 // Processing methods attributes
246
-                foreach($xInput->getMethods() as $sMethod)
244
+                foreach ($xInput->getMethods() as $sMethod)
247 245
                 {
248 246
                     $this->getMethodAttrs($xClass, $sMethod);
249 247
                 }
@@ -251,7 +249,7 @@  discard block
 block discarded – undo
251 249
 
252 250
             return $this->xMetadata;
253 251
         }
254
-        catch(Exception|Error $e)
252
+        catch (Exception|Error $e)
255 253
         {
256 254
             throw new SetupException($e->getMessage());
257 255
         }
Please login to merge, or discard this patch.