Passed
Push — main ( 0dcad8...87fed9 )
by Thierry
04:24
created
jaxon-core/src/Plugin/Manager/PackageManager.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -62,25 +62,25 @@  discard block
 block discarded – undo
62 62
     private function updateContainer(Config $xConfig): void
63 63
     {
64 64
         $aOptions = $xConfig->getOption('container.set', []);
65
-        foreach($aOptions as $xKey => $xValue)
65
+        foreach ($aOptions as $xKey => $xValue)
66 66
         {
67 67
             // The key is the class name. It must be a string.
68 68
             $this->di->set((string)$xKey, $xValue);
69 69
         }
70 70
         $aOptions = $xConfig->getOption('container.val', []);
71
-        foreach($aOptions as $xKey => $xValue)
71
+        foreach ($aOptions as $xKey => $xValue)
72 72
         {
73 73
             // The key is the class name. It must be a string.
74 74
             $this->di->val((string)$xKey, $xValue);
75 75
         }
76 76
         $aOptions = $xConfig->getOption('container.auto', []);
77
-        foreach($aOptions as $xValue)
77
+        foreach ($aOptions as $xValue)
78 78
         {
79 79
             // The key is the class name. It must be a string.
80 80
             $this->di->auto((string)$xValue);
81 81
         }
82 82
         $aOptions = $xConfig->getOption('container.alias', []);
83
-        foreach($aOptions as $xKey => $xValue)
83
+        foreach ($aOptions as $xKey => $xValue)
84 84
         {
85 85
             // The key is the class name. It must be a string.
86 86
             $this->di->alias((string)$xKey, (string)$xValue);
@@ -98,16 +98,16 @@  discard block
 block discarded – undo
98 98
      */
99 99
     private function registerCallables(array $aOptions, string $sCallableType): void
100 100
     {
101
-        foreach($aOptions as $xKey => $xValue)
101
+        foreach ($aOptions as $xKey => $xValue)
102 102
         {
103
-            if(is_integer($xKey) && is_string($xValue))
103
+            if (is_integer($xKey) && is_string($xValue))
104 104
             {
105 105
                 // Register a function without options
106 106
                 $this->xPluginManager->registerCallable($sCallableType, $xValue);
107 107
                 continue;
108 108
             }
109 109
 
110
-            if(is_string($xKey) && (is_array($xValue) || is_string($xValue)))
110
+            if (is_string($xKey) && (is_array($xValue) || is_string($xValue)))
111 111
             {
112 112
                 // Register a function with options
113 113
                 $this->xPluginManager->registerCallable($sCallableType, $xKey, $xValue);
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
      */
125 125
     private function registerExceptionHandlers(Config $xConfig): void
126 126
     {
127
-        foreach($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler)
127
+        foreach ($xConfig->getOption('exceptions', []) as $sExClass => $xExHandler)
128 128
         {
129 129
             $this->xCallbackManager->error($xExHandler, is_string($sExClass) ? $sExClass : '');
130 130
         }
@@ -147,20 +147,20 @@  discard block
 block discarded – undo
147 147
         // key of the array item, a string as the value of an entry without a key,
148 148
         // or set with the key $sOptionKey in an array entry without a key.
149 149
         $aCallables = [];
150
-        foreach($xConfig->getOption($sOptionName, []) as $xKey => $xValue)
150
+        foreach ($xConfig->getOption($sOptionName, []) as $xKey => $xValue)
151 151
         {
152
-            if(is_string($xKey))
152
+            if (is_string($xKey))
153 153
             {
154 154
                 $aCallables[$xKey] = $xValue;
155 155
                 continue;
156 156
             }
157
-            if(is_string($xValue))
157
+            if (is_string($xValue))
158 158
             {
159 159
                 $aCallables[] = $xValue;
160 160
                 continue;
161 161
             }
162 162
 
163
-            if(is_array($xValue) && isset($xValue[$sOptionKey]))
163
+            if (is_array($xValue) && isset($xValue[$sOptionKey]))
164 164
             {
165 165
                 $aCallables[$xValue[$sOptionKey]] = $xValue;
166 166
             }
@@ -215,12 +215,12 @@  discard block
 block discarded – undo
215 215
     {
216 216
         // $this->aPackages contains packages config file paths.
217 217
         $aLibOptions = $sClassName::config();
218
-        if(is_string($aLibOptions))
218
+        if (is_string($aLibOptions))
219 219
         {
220 220
             // A string is supposed to be the path to a config file.
221 221
             $aLibOptions = $this->xConfigManager->read($aLibOptions);
222 222
         }
223
-        elseif(!is_array($aLibOptions))
223
+        elseif (!is_array($aLibOptions))
224 224
         {
225 225
             // Otherwise, anything else than an array is not accepted.
226 226
             $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]);
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
     public function registerPackage(string $sClassName, array $aUserOptions = []): void
244 244
     {
245 245
         $sClassName = trim($sClassName, '\\ ');
246
-        if(!is_subclass_of($sClassName, AbstractPackage::class))
246
+        if (!is_subclass_of($sClassName, AbstractPackage::class))
247 247
         {
248 248
             $sMessage = $this->xTranslator->trans('errors.register.invalid', ['name' => $sClassName]);
249 249
             throw new SetupException($sMessage);
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
 
288 288
         // Register packages
289 289
         $aPackageConfig = $xAppConfig->getOption('packages', []);
290
-        foreach($aPackageConfig as $xKey => $xValue)
290
+        foreach ($aPackageConfig as $xKey => $xValue)
291 291
         {
292
-            if(is_integer($xKey) && is_string($xValue))
292
+            if (is_integer($xKey) && is_string($xValue))
293 293
             {
294 294
                 // Register a package without options
295 295
                 $sClassName = $xValue;
@@ -297,7 +297,7 @@  discard block
 block discarded – undo
297 297
                 continue;
298 298
             }
299 299
 
300
-            if(is_string($xKey) && is_array($xValue))
300
+            if (is_string($xKey) && is_array($xValue))
301 301
             {
302 302
                 // Register a package with options
303 303
                 $sClassName = $xKey;
Please login to merge, or discard this patch.
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.
jaxon-upload/src/Manager/UploadManager.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -133,13 +133,13 @@  discard block
 block discarded – undo
133 133
         try
134 134
         {
135 135
             $xFilesystem->createDirectory($sUploadDir);
136
-            if(!$xFilesystem->directoryExists($sUploadDir))
136
+            if (!$xFilesystem->directoryExists($sUploadDir))
137 137
             {
138 138
                 throw new RequestException($this->xTranslator->trans('errors.upload.access'));
139 139
             }
140 140
             return $sUploadDir;
141 141
         }
142
-        catch(FilesystemException $e)
142
+        catch (FilesystemException $e)
143 143
         {
144 144
             $this->xLogger->error('Filesystem error.', ['message' => $e->getMessage()]);
145 145
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
     {
174 174
         // Check the uploaded file validity
175 175
         $nErrorCode = $xHttpFile->getError();
176
-        if($nErrorCode !== UPLOAD_ERR_OK)
176
+        if ($nErrorCode !== UPLOAD_ERR_OK)
177 177
         {
178 178
             $this->xLogger->error('File upload error.', [
179 179
                 'code' => $nErrorCode,
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 
185 185
         // Filename without the extension. Needs to be sanitized.
186 186
         $sName = pathinfo($xHttpFile->getClientFilename(), PATHINFO_FILENAME);
187
-        if($this->cNameSanitizer !== null)
187
+        if ($this->cNameSanitizer !== null)
188 188
         {
189 189
             $sName = (string)call_user_func($this->cNameSanitizer, $sName, $sField, $this->sUploadFieldId);
190 190
         }
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
         // Set the user file data
193 193
         $xFile = File::fromHttpFile($this->xFileStorage->filesystem($sField), $xHttpFile, $sUploadDir, $sName);
194 194
         // Verify file validity (format, size)
195
-        if(!$this->xValidator->validateUploadedFile($sField, $xFile))
195
+        if (!$this->xValidator->validateUploadedFile($sField, $xFile))
196 196
         {
197 197
             throw new RequestException($this->xValidator->getErrorMessage());
198 198
         }
@@ -217,16 +217,16 @@  discard block
 block discarded – undo
217 217
 
218 218
         $aUserFiles = [];
219 219
         $this->aAllFiles = []; // A flat list of all uploaded files
220
-        foreach($aTempFiles as $sField => $aFiles)
220
+        foreach ($aTempFiles as $sField => $aFiles)
221 221
         {
222 222
             $aUserFiles[$sField] = [];
223 223
             // Get the path to the upload dir
224 224
             $sUploadDir = $this->getUploadDir($sField);
225
-            if(!is_array($aFiles))
225
+            if (!is_array($aFiles))
226 226
             {
227 227
                 $aFiles = [$aFiles];
228 228
             }
229
-            foreach($aFiles as $xHttpFile)
229
+            foreach ($aFiles as $xHttpFile)
230 230
             {
231 231
                 $aUserFiles[$sField][] = $this->makeUploadedFile($xHttpFile, $sUploadDir, $sField);
232 232
             }
@@ -234,12 +234,12 @@  discard block
 block discarded – undo
234 234
         // Copy the uploaded files from the temp dir to the user dir
235 235
         try
236 236
         {
237
-            foreach($this->aAllFiles as $aFiles)
237
+            foreach ($this->aAllFiles as $aFiles)
238 238
             {
239 239
                 $aFiles['user']->filesystem()->write($aFiles['user']->path(), $aFiles['temp']->getStream());
240 240
             }
241 241
         }
242
-        catch(FilesystemException $e)
242
+        catch (FilesystemException $e)
243 243
         {
244 244
             $this->xLogger->error('Filesystem error.', ['message' => $e->getMessage()]);
245 245
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
Please login to merge, or discard this patch.
jaxon-upload/src/Manager/FileStorage.php 1 patch
Spacing   +5 added lines, -6 removed lines patch added patch discarded remove patch
@@ -81,8 +81,7 @@  discard block
 block discarded – undo
81 81
     {
82 82
         // Local file system adapter
83 83
         $this->registerAdapter('local', function(string $sRootDir, $xOptions) {
84
-            return empty($xOptions) ? new LocalFilesystemAdapter($sRootDir) :
85
-                new LocalFilesystemAdapter($sRootDir, $xOptions);
84
+            return empty($xOptions) ? new LocalFilesystemAdapter($sRootDir) : new LocalFilesystemAdapter($sRootDir, $xOptions);
86 85
         });
87 86
 
88 87
         // AWS S3 file system adapter
@@ -140,7 +139,7 @@  discard block
 block discarded – undo
140 139
     public function filesystem(string $sField = ''): Filesystem
141 140
     {
142 141
         $sField = trim($sField);
143
-        if(isset($this->aFilesystems[$sField]))
142
+        if (isset($this->aFilesystems[$sField]))
144 143
         {
145 144
             return $this->aFilesystems[$sField];
146 145
         }
@@ -150,18 +149,18 @@  discard block
 block discarded – undo
150 149
         $sRootDir = $this->xConfigManager->getOption('upload.default.dir', '');
151 150
         $aOptions = $this->xConfigManager->getOption('upload.default.options');
152 151
         $sConfigKey = "upload.files.$sField";
153
-        if($sField !== '' && $this->xConfigManager->hasOption($sConfigKey))
152
+        if ($sField !== '' && $this->xConfigManager->hasOption($sConfigKey))
154 153
         {
155 154
             $sStorage = $this->xConfigManager->getOption("$sConfigKey.storage", $sStorage);
156 155
             $sRootDir = $this->xConfigManager->getOption("$sConfigKey.dir", $sRootDir);
157 156
             $aOptions = $this->xConfigManager->getOption("$sConfigKey.options", $aOptions);
158 157
         }
159 158
 
160
-        if(!is_string($sRootDir))
159
+        if (!is_string($sRootDir))
161 160
         {
162 161
             throw new RequestException($this->xTranslator->trans('errors.upload.dir'));
163 162
         }
164
-        if(!isset($this->aAdapters[$sStorage]))
163
+        if (!isset($this->aAdapters[$sStorage]))
165 164
         {
166 165
             throw new RequestException($this->xTranslator->trans('errors.upload.adapter'));
167 166
         }
Please login to merge, or discard this patch.
jaxon-core/src/Di/Traits/ComponentTrait.php 1 patch
Spacing   +14 added lines, -15 removed lines patch added patch discarded remove patch
@@ -144,15 +144,15 @@  discard block
 block discarded – undo
144 144
         $xRegistry->updateHash(false); // Disable hash calculation.
145 145
 
146 146
         $sComponentId = str_replace('\\', '.', $sClassName);
147
-        if(!isset($this->aComponents[$sComponentId]))
147
+        if (!isset($this->aComponents[$sComponentId]))
148 148
         {
149 149
             $aOptions = $xRegistry->getNamespaceComponentOptions($sClassName);
150
-            if($aOptions !== null)
150
+            if ($aOptions !== null)
151 151
             {
152 152
                 $this->saveComponent($sClassName, $aOptions);
153 153
             }
154 154
         }
155
-        if(isset($this->aComponents[$sComponentId]))
155
+        if (isset($this->aComponents[$sComponentId]))
156 156
         {
157 157
             return; // The component is found.
158 158
         }
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
         // The component was not found in a registered namespace. We need to parse all
161 161
         // the directories to be able to find a component registered without a namespace.
162 162
         $sComponentId = str_replace('\\', '_', $sClassName);
163
-        if(!isset($this->aComponents[$sComponentId]))
163
+        if (!isset($this->aComponents[$sComponentId]))
164 164
         {
165 165
             $xRegistry->registerComponentsInDirectories();
166 166
         }
167
-        if(isset($this->aComponents[$sComponentId]))
167
+        if (isset($this->aComponents[$sComponentId]))
168 168
         {
169 169
             return; // The component is found.
170 170
         }
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
     public function getCallableObjects(): array
183 183
     {
184 184
         $aCallableObjects = [];
185
-        foreach($this->aComponents as $sComponentId => $_)
185
+        foreach ($this->aComponents as $sComponentId => $_)
186 186
         {
187 187
             $aCallableObjects[$sComponentId] = $this->makeCallableObject($sComponentId);
188 188
         }
@@ -233,12 +233,12 @@  discard block
 block discarded – undo
233 233
     {
234 234
         /** @var Config|null */
235 235
         $xPackageConfig = $aOptions['config'] ?? null;
236
-        if($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false))
236
+        if ($xPackageConfig === null || (bool)($aOptions['excluded'] ?? false))
237 237
         {
238 238
             return null;
239 239
         }
240 240
         $sMetadataFormat = $xPackageConfig->getOption('metadata.format');
241
-        if(!in_array($sMetadataFormat, ['attributes', 'annotations']))
241
+        if (!in_array($sMetadataFormat, ['attributes', 'annotations']))
242 242
         {
243 243
             return null;
244 244
         }
@@ -248,23 +248,23 @@  discard block
 block discarded – undo
248 248
         $xMetadata = null;
249 249
         $xMetadataCache = null;
250 250
         $xConfig = $di->config();
251
-        if($xConfig->getAppOption('metadata.cache.enabled', false))
251
+        if ($xConfig->getAppOption('metadata.cache.enabled', false))
252 252
         {
253
-            if(!$di->h('jaxon_metadata_cache_dir'))
253
+            if (!$di->h('jaxon_metadata_cache_dir'))
254 254
             {
255 255
                 $sCacheDir = $xConfig->getAppOption('metadata.cache.dir');
256 256
                 $di->val('jaxon_metadata_cache_dir', $sCacheDir);
257 257
             }
258 258
             $xMetadataCache = $di->getMetadataCache();
259 259
             $xMetadata = $xMetadataCache->read($xReflectionClass->getName());
260
-            if($xMetadata !== null)
260
+            if ($xMetadata !== null)
261 261
             {
262 262
                 return $xMetadata;
263 263
             }
264 264
         }
265 265
 
266 266
         $aProperties = array_map(fn($xProperty) => $xProperty->getName(),
267
-            $xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC |
267
+            $xReflectionClass->getProperties(ReflectionProperty::IS_PUBLIC|
268 268
                 ReflectionProperty::IS_PROTECTED));
269 269
         $aMethods = $this->getPublicMethods($xReflectionClass);
270 270
 
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
         $xMetadata = $xMetadataReader->getAttributes($xInput);
274 274
 
275 275
         // Try to save the metadata in the cache
276
-        if($xMetadataCache !== null && $xMetadata !== null)
276
+        if ($xMetadataCache !== null && $xMetadata !== null)
277 277
         {
278 278
             $xMetadataCache->save($xReflectionClass->getName(), $xMetadata);
279 279
         }
@@ -291,8 +291,7 @@  discard block
 block discarded – undo
291 291
         array $aOptions): ComponentOptions
292 292
     {
293 293
         $xMetadata = $this->getComponentMetadata($xReflectionClass, $aOptions);
294
-        return !$xMetadata ? new ComponentOptions($aOptions) :
295
-            new ComponentOptions($aOptions, $xMetadata->isExcluded(),
294
+        return !$xMetadata ? new ComponentOptions($aOptions) : new ComponentOptions($aOptions, $xMetadata->isExcluded(),
296 295
             $xMetadata->getProtectedMethods(), $xMetadata->getProperties());
297 296
     }
298 297
 }
Please login to merge, or discard this patch.
jaxon-core/src/Di/ComponentContainer.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -169,13 +169,13 @@  discard block
 block discarded – undo
169 169
         try
170 170
         {
171 171
             // Make sure the registered class exists
172
-            if(isset($aOptions['include']))
172
+            if (isset($aOptions['include']))
173 173
             {
174 174
                 require_once $aOptions['include'];
175 175
             }
176 176
             $xReflectionClass = new ReflectionClass($sClassName);
177 177
             // Check if the class is registrable
178
-            if(!$xReflectionClass->isInstantiable())
178
+            if (!$xReflectionClass->isInstantiable())
179 179
             {
180 180
                 return;
181 181
             }
@@ -185,12 +185,12 @@  discard block
 block discarded – undo
185 185
             $sClassKey = $this->getReflectionClassKey($sClassName);
186 186
             $this->val($sClassKey, $xReflectionClass);
187 187
             // Register the user class, but only if the user didn't already.
188
-            if(!$this->has($sClassName))
188
+            if (!$this->has($sClassName))
189 189
             {
190 190
                 $this->set($sClassName, fn() => $this->make($this->get($sClassKey)));
191 191
             }
192 192
         }
193
-        catch(ReflectionException $e)
193
+        catch (ReflectionException $e)
194 194
         {
195 195
             throw new SetupException($this->cn()->g(Translator::class)
196 196
                 ->trans('errors.class.invalid', ['name' => $sClassName]));
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 
213 213
         $sComponentObject = $this->getCallableObjectKey($sClassName);
214 214
         // Prevent duplication. It's important not to use the class name here.
215
-        if($this->has($sComponentObject))
215
+        if ($this->has($sComponentObject))
216 216
         {
217 217
             return $sClassName;
218 218
         }
@@ -238,14 +238,14 @@  discard block
 block discarded – undo
238 238
 
239 239
         // Initialize the user class instance
240 240
         $this->xContainer->extend($sClassName, function($xClassInstance) use($sClassName) {
241
-            if($xClassInstance instanceof AbstractComponent)
241
+            if ($xClassInstance instanceof AbstractComponent)
242 242
             {
243 243
                 $xHelper = $this->get($this->getCallableHelperKey($sClassName));
244 244
                 $xHelper->xTarget = $this->xTarget;
245 245
 
246 246
                 // Call the protected "initComponent()" method of the Component class.
247 247
                 $cSetter = function($di, $xHelper) {
248
-                    $this->initComponent($di, $xHelper);  // "$this" here refers to the Component class.
248
+                    $this->initComponent($di, $xHelper); // "$this" here refers to the Component class.
249 249
                 };
250 250
                 $cSetter = $cSetter->bindTo($xClassInstance, $xClassInstance);
251 251
                 call_user_func($cSetter, $this->di, $xHelper);
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
             /** @var CallableObject */
261 261
             $xCallableObject = $this->get($this->getCallableObjectKey($sClassName));
262 262
             $xCallableObject->setDiClassAttributes($xClassInstance);
263
-            if($this->xTarget !== null)
263
+            if ($this->xTarget !== null)
264 264
             {
265 265
                 $sMethodName = $this->xTarget->getMethodName();
266 266
                 $xCallableObject->setDiMethodAttributes($xClassInstance, $sMethodName);
@@ -323,17 +323,17 @@  discard block
 block discarded – undo
323 323
     public function getComponentRequestFactory(string $sClassName): ?JxnCall
324 324
     {
325 325
         $sClassName = trim($sClassName, " \t");
326
-        if($sClassName === '')
326
+        if ($sClassName === '')
327 327
         {
328 328
             return null;
329 329
         }
330 330
 
331 331
         $sFactoryKey = $this->getRequestFactoryKey($sClassName);
332
-        if(!$this->has($sFactoryKey))
332
+        if (!$this->has($sFactoryKey))
333 333
         {
334 334
             $this->xContainer->offsetSet($sFactoryKey, function() use($sClassName) {
335 335
                 $sComponentId = str_replace('\\', '.', $sClassName);
336
-                if(!($xCallable = $this->makeCallableObject($sComponentId)))
336
+                if (!($xCallable = $this->makeCallableObject($sComponentId)))
337 337
                 {
338 338
                     return null;
339 339
                 }
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Request/CallableClass/ComponentRegistry.php 1 patch
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
     public function __construct(protected ComponentContainer $cdi)
111 111
     {
112 112
         // Set the composer autoloader
113
-        if(file_exists(($sAutoloadFile = __DIR__ . '/../../../../../../autoload.php')) ||
113
+        if (file_exists(($sAutoloadFile = __DIR__ . '/../../../../../../autoload.php')) ||
114 114
             file_exists(($sAutoloadFile = __DIR__ . '/../../../../../vendor/autoload.php')) ||
115 115
             file_exists(($sAutoloadFile = __DIR__ . '/../../../../vendor/autoload.php')))
116 116
         {
@@ -179,15 +179,15 @@  discard block
 block discarded – undo
179 179
      */
180 180
     private function makeClassOptions(string $sClassName, array $aClassOptions, array $aDirectoryOptions): array
181 181
     {
182
-        foreach($this->aDefaultClassOptions as $sOption => $xValue)
182
+        foreach ($this->aDefaultClassOptions as $sOption => $xValue)
183 183
         {
184
-            if(!isset($aClassOptions[$sOption]))
184
+            if (!isset($aClassOptions[$sOption]))
185 185
             {
186 186
                 $aClassOptions[$sOption] = $xValue;
187 187
             }
188 188
         }
189 189
         $aClassOptions['excluded'] = (bool)($aClassOptions['excluded'] ?? false); // Convert to bool.
190
-        if(is_string($aClassOptions['protected']))
190
+        if (is_string($aClassOptions['protected']))
191 191
         {
192 192
             $aClassOptions['protected'] = [$aClassOptions['protected']]; // Convert to array.
193 193
         }
@@ -198,30 +198,30 @@  discard block
 block discarded – undo
198 198
             $aDirectoryOptions['classes']['*'] ?? [], // Options for all classes
199 199
             $aDirectoryOptions['classes'][$sClassName] ?? [], // Options for this specific class
200 200
         ];
201
-        foreach($aOptionGroups as $aOptionGroup)
201
+        foreach ($aOptionGroups as $aOptionGroup)
202 202
         {
203
-            if(isset($aOptionGroup['separator']))
203
+            if (isset($aOptionGroup['separator']))
204 204
             {
205 205
                 $aClassOptions['separator'] = (string)$aOptionGroup['separator'];
206 206
             }
207
-            if(isset($aOptionGroup['excluded']))
207
+            if (isset($aOptionGroup['excluded']))
208 208
             {
209 209
                 $aClassOptions['excluded'] = (bool)$aOptionGroup['excluded'];
210 210
             }
211
-            if(isset($aOptionGroup['protected']))
211
+            if (isset($aOptionGroup['protected']))
212 212
             {
213
-                if(is_string($aOptionGroup['protected']))
213
+                if (is_string($aOptionGroup['protected']))
214 214
                 {
215 215
                     $aOptionGroup['protected'] = [$aOptionGroup['protected']]; // Convert to array.
216 216
                 }
217 217
                 $aClassOptions['protected'] = array_merge($aClassOptions['protected'], $aOptionGroup['protected']);
218 218
             }
219
-            if(isset($aOptionGroup['functions']))
219
+            if (isset($aOptionGroup['functions']))
220 220
             {
221 221
                 $aClassOptions['functions'] = array_merge($aClassOptions['functions'], $aOptionGroup['functions']);
222 222
             }
223 223
         }
224
-        if(isset($aDirectoryOptions['config']) && !isset($aClassOptions['config']))
224
+        if (isset($aDirectoryOptions['config']) && !isset($aClassOptions['config']))
225 225
         {
226 226
             $aClassOptions['config'] = $aDirectoryOptions['config'];
227 227
         }
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
     {
244 244
         $aOptions = $this->makeClassOptions($sClassName, $aClassOptions, $aDirectoryOptions);
245 245
         $this->cdi->saveComponent($sClassName, $aOptions);
246
-        if($this->bUpdateHash)
246
+        if ($this->bUpdateHash)
247 247
         {
248 248
             $this->sHash .= $sClassName . $aOptions['timestamp'];
249 249
         }
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
     {
262 262
         // For classes, the underscore is used as separator.
263 263
         $aClassOptions['separator'] = '_';
264
-        if($this->xPackageConfig !== null)
264
+        if ($this->xPackageConfig !== null)
265 265
         {
266 266
             $aClassOptions['config'] = $this->xPackageConfig;
267 267
         }
@@ -278,10 +278,10 @@  discard block
 block discarded – undo
278 278
     public function getNamespaceComponentOptions(string $sClassName): ?array
279 279
     {
280 280
         // Find the corresponding namespace
281
-        foreach($this->aNamespaceOptions as $sNamespace => $aDirectoryOptions)
281
+        foreach ($this->aNamespaceOptions as $sNamespace => $aDirectoryOptions)
282 282
         {
283 283
             // Check if the namespace matches the class.
284
-            if(strncmp($sClassName, $sNamespace . '\\', strlen($sNamespace) + 1) === 0)
284
+            if (strncmp($sClassName, $sNamespace . '\\', strlen($sNamespace) + 1) === 0)
285 285
             {
286 286
                 // Save the class options
287 287
                 $aClassOptions = ['namespace' => $sNamespace];
@@ -304,11 +304,11 @@  discard block
 block discarded – undo
304 304
         // For directories without namespace, the underscore is used as separator.
305 305
         $aOptions['separator'] = '_';
306 306
         // Set the autoload option default value
307
-        if(!isset($aOptions['autoload']))
307
+        if (!isset($aOptions['autoload']))
308 308
         {
309 309
             $aOptions['autoload'] = true;
310 310
         }
311
-        if($this->xPackageConfig !== null)
311
+        if ($this->xPackageConfig !== null)
312 312
         {
313 313
             $aOptions['config'] = $this->xPackageConfig;
314 314
         }
@@ -342,16 +342,16 @@  discard block
 block discarded – undo
342 342
         // For namespaces, the dot is used as separator.
343 343
         $aOptions['separator'] = '.';
344 344
         // Set the autoload option default value
345
-        if(!isset($aOptions['autoload']))
345
+        if (!isset($aOptions['autoload']))
346 346
         {
347 347
             $aOptions['autoload'] = true;
348 348
         }
349
-        if($this->xPackageConfig !== null)
349
+        if ($this->xPackageConfig !== null)
350 350
         {
351 351
             $aOptions['config'] = $this->xPackageConfig;
352 352
         }
353 353
         // Register the dir with PSR4 autoloading
354
-        if(($aOptions['autoload']) && $this->xAutoloader != null)
354
+        if (($aOptions['autoload']) && $this->xAutoloader != null)
355 355
         {
356 356
             $this->xAutoloader->setPsr4($sNamespace . '\\', $aOptions['directory']);
357 357
         }
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
     public function registerComponentsInNamespaces(): void
368 368
     {
369 369
         // This is to be done only once.
370
-        if($this->bNamespacesParsed)
370
+        if ($this->bNamespacesParsed)
371 371
         {
372 372
             return;
373 373
         }
@@ -375,17 +375,17 @@  discard block
 block discarded – undo
375 375
 
376 376
         // Browse directories with namespaces and read all the files.
377 377
         $sDS = DIRECTORY_SEPARATOR;
378
-        foreach($this->aNamespaceOptions as $sNamespace => $aDirectoryOptions)
378
+        foreach ($this->aNamespaceOptions as $sNamespace => $aDirectoryOptions)
379 379
         {
380 380
             $this->addNamespace($sNamespace, ['separator' => '.']);
381 381
 
382 382
             // Iterate on dir content
383 383
             $sDirectory = $aDirectoryOptions['directory'];
384 384
             $itFile = new SortedFileIterator($sDirectory);
385
-            foreach($itFile as $xFile)
385
+            foreach ($itFile as $xFile)
386 386
             {
387 387
                 // skip everything except PHP files
388
-                if(!$xFile->isFile() || $xFile->getExtension() !== 'php')
388
+                if (!$xFile->isFile() || $xFile->getExtension() !== 'php')
389 389
                 {
390 390
                     continue;
391 391
                 }
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
                 $sClassPath = $sNamespace;
395 395
                 $sRelativePath = substr($xFile->getPath(), strlen($sDirectory));
396 396
                 $sRelativePath = trim(str_replace($sDS, '\\', $sRelativePath), '\\');
397
-                if($sRelativePath !== '')
397
+                if ($sRelativePath !== '')
398 398
                 {
399 399
                     $sClassPath .= '\\' . $sRelativePath;
400 400
                 }
@@ -420,21 +420,21 @@  discard block
 block discarded – undo
420 420
     public function registerComponentsInDirectories(): void
421 421
     {
422 422
         // This is to be done only once.
423
-        if($this->bDirectoriesParsed)
423
+        if ($this->bDirectoriesParsed)
424 424
         {
425 425
             return;
426 426
         }
427 427
         $this->bDirectoriesParsed = true;
428 428
 
429 429
         // Browse directories without namespaces and read all the files.
430
-        foreach($this->aDirectoryOptions as $sDirectory => $aDirectoryOptions)
430
+        foreach ($this->aDirectoryOptions as $sDirectory => $aDirectoryOptions)
431 431
         {
432 432
             $itFile = new SortedFileIterator($sDirectory);
433 433
             // Iterate on dir content
434
-            foreach($itFile as $xFile)
434
+            foreach ($itFile as $xFile)
435 435
             {
436 436
                 // Skip everything except PHP files
437
-                if(!$xFile->isFile() || $xFile->getExtension() !== 'php')
437
+                if (!$xFile->isFile() || $xFile->getExtension() !== 'php')
438 438
                 {
439 439
                     continue;
440 440
                 }
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
                     'separator' => '.',
445 445
                     'timestamp' => $xFile->getMTime(),
446 446
                 ];
447
-                if(($aDirectoryOptions['autoload']) && $this->xAutoloader !== null)
447
+                if (($aDirectoryOptions['autoload']) && $this->xAutoloader !== null)
448 448
                 {
449 449
                     // Set classmap autoloading. Must be done before registering the class.
450 450
                     $this->xAutoloader->addClassMap([$sClassName => $xFile->getPathname()]);
Please login to merge, or discard this patch.
jaxon-core/src/Plugin/Request/CallableClass/CallableClassPlugin.php 1 patch
Spacing   +13 added lines, -14 removed lines patch added patch discarded remove patch
@@ -81,15 +81,15 @@  discard block
 block discarded – undo
81 81
      */
82 82
     public function checkOptions(string $sCallable, $xOptions): array
83 83
     {
84
-        if(!$this->xValidator->validateClass(trim($sCallable)))
84
+        if (!$this->xValidator->validateClass(trim($sCallable)))
85 85
         {
86 86
             throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
87 87
         }
88
-        if(is_string($xOptions))
88
+        if (is_string($xOptions))
89 89
         {
90 90
             $xOptions = ['include' => $xOptions];
91 91
         }
92
-        elseif(!is_array($xOptions))
92
+        elseif (!is_array($xOptions))
93 93
         {
94 94
             throw new SetupException($this->xTranslator->trans('errors.objects.invalid-declaration'));
95 95
         }
@@ -133,15 +133,15 @@  discard block
 block discarded – undo
133 133
      */
134 134
     private function addCallable(CallableObject $xCallableObject): void
135 135
     {
136
-        if($xCallableObject->excluded())
136
+        if ($xCallableObject->excluded())
137 137
         {
138 138
             return;
139 139
         }
140 140
 
141 141
         $aCallableObject = &$this->aCallableObjects;
142
-        foreach(explode('.', $xCallableObject->getJsName()) as $sName)
142
+        foreach (explode('.', $xCallableObject->getJsName()) as $sName)
143 143
         {
144
-            if(!isset($aCallableObject['children'][$sName]))
144
+            if (!isset($aCallableObject['children'][$sName]))
145 145
             {
146 146
                 $aCallableObject['children'][$sName] = [];
147 147
             }
@@ -176,11 +176,10 @@  discard block
 block discarded – undo
176 176
 
177 177
         $fMethodCallback = fn($aMethod) => $this->renderMethod($sIndent,
178 178
             ['sJsClass' => $sJsClass, 'aMethod' => $aMethod]);
179
-        $aMethods = !isset($aCallable['methods']) ? [] :
180
-            array_map($fMethodCallback, $aCallable['methods']);
179
+        $aMethods = !isset($aCallable['methods']) ? [] : array_map($fMethodCallback, $aCallable['methods']);
181 180
 
182 181
         $aChildren = [];
183
-        foreach($aCallable['children'] ?? [] as $sName => $aChild)
182
+        foreach ($aCallable['children'] ?? [] as $sName => $aChild)
184 183
         {
185 184
             $aChildren[] = $this->renderChild("$sName:", "$sJsClass.$sName",
186 185
                 $aChild, $nRepeat) . ',';
@@ -221,13 +220,13 @@  discard block
 block discarded – undo
221 220
         $this->xRegistry->registerAllComponents();
222 221
 
223 222
         $this->aCallableObjects = ['children' => []];
224
-        foreach($this->cdi->getCallableObjects() as $xCallableObject)
223
+        foreach ($this->cdi->getCallableObjects() as $xCallableObject)
225 224
         {
226 225
             $this->addCallable($xCallableObject);
227 226
         }
228 227
 
229 228
         $aScripts = [];
230
-        foreach($this->aCallableObjects['children'] as $sJsClass => $aCallable)
229
+        foreach ($this->aCallableObjects['children'] as $sJsClass => $aCallable)
231 230
         {
232 231
             $aScripts[] = $this->renderChild("{$this->sPrefix}$sJsClass =",
233 232
                 $sJsClass, $aCallable) . ';';
@@ -283,7 +282,7 @@  discard block
 block discarded – undo
283 282
         // Will be used to print a translated error message.
284 283
         $aErrorParams = ['class' => $sClassName, 'method' => $sMethodName];
285 284
 
286
-        if(!$this->xValidator->validateJsObject($sClassName) ||
285
+        if (!$this->xValidator->validateJsObject($sClassName) ||
287 286
             !$this->xValidator->validateMethod($sMethodName))
288 287
         {
289 288
             // Unable to find the requested object or method
@@ -297,7 +296,7 @@  discard block
 block discarded – undo
297 296
             /** @var CallableObject */
298 297
             $xCallableObject = $this->getCallable($sClassName);
299 298
 
300
-            if($xCallableObject->excluded($sMethodName))
299
+            if ($xCallableObject->excluded($sMethodName))
301 300
             {
302 301
                 // Unable to find the requested class or method
303 302
                 $this->throwException('', 'errors.objects.excluded', $aErrorParams);
@@ -306,7 +305,7 @@  discard block
 block discarded – undo
306 305
             $sError = 'errors.objects.call';
307 306
             $xCallableObject->call($this->xTarget);
308 307
         }
309
-        catch(ReflectionException|SetupException $e)
308
+        catch (ReflectionException|SetupException $e)
310 309
         {
311 310
             // Unable to execute the requested class or method
312 311
             $this->throwException($e->getMessage(), $sError, $aErrorParams);
Please login to merge, or discard this patch.
jaxon-core/templates/callables/method.js.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,4 +1,4 @@
 block discarded – undo
1 1
 <?php echo $this->aMethod['name'] ?>: function() { return jaxon.request({ type: 'class', name: '<?php
2 2
     echo $this->sJsClass ?>', method: '<?php echo $this->aMethod['name']
3
-    ?>' }, { parameters: arguments<?php foreach($this->aMethod['options'] as $sKey => $sValue):
3
+    ?>' }, { parameters: arguments<?php foreach ($this->aMethod['options'] as $sKey => $sValue):
4 4
         ?>, <?php echo $sKey ?>: <?php echo $sValue ?><?php endforeach ?> }); },
Please login to merge, or discard this patch.