Completed
Push — master ( cac22e...48735e )
by Mihail
02:18
created
src/App.php 3 patches
Unused Use Statements   -4 removed lines patch added patch discarded remove patch
@@ -6,16 +6,12 @@
 block discarded – undo
6 6
 use Ffcms\Core\Cache\MemoryObject;
7 7
 use Ffcms\Core\Debug\DebugMeasure;
8 8
 use Ffcms\Core\Debug\Manager as Debug;
9
-use Ffcms\Core\Exception\ForbiddenException;
10
-use Ffcms\Core\Exception\JsonException;
11 9
 use Ffcms\Core\Exception\NativeException;
12 10
 use Ffcms\Core\Exception\NotFoundException;
13
-use Ffcms\Core\Exception\SyntaxException;
14 11
 use Ffcms\Core\Exception\TemplateException;
15 12
 use Ffcms\Core\Helper\Mailer;
16 13
 use Ffcms\Core\Helper\Security;
17 14
 use Ffcms\Core\Helper\Type\Any;
18
-use Ffcms\Core\Helper\Type\Obj;
19 15
 use Ffcms\Core\Helper\Type\Str;
20 16
 use Ffcms\Core\I18n\Translate;
21 17
 use Ffcms\Core\Managers\BootManager;
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -185,22 +185,22 @@  discard block
 block discarded – undo
185 185
         $html = null;
186 186
         // lets try to get html full content to page render
187 187
         try {
188
-            $this->startMeasure(__METHOD__ . '::callback');
188
+            $this->startMeasure(__METHOD__.'::callback');
189 189
             /** @var \Ffcms\Core\Arch\Controller $callClass */
190 190
             $callClass = null;
191
-            $callMethod = 'action' . self::$Request->getAction();
191
+            $callMethod = 'action'.self::$Request->getAction();
192 192
 
193 193
             // define callback class namespace/name full path
194
-            $cName = (self::$Request->getCallbackAlias() ?? '\Apps\Controller\\' . env_name . '\\' . self::$Request->getController());
194
+            $cName = (self::$Request->getCallbackAlias() ?? '\Apps\Controller\\'.env_name.'\\'.self::$Request->getController());
195 195
             if (!class_exists($cName))
196
-                throw new NotFoundException('Callback class not found: ' . App::$Security->strip_tags($cName));
196
+                throw new NotFoundException('Callback class not found: '.App::$Security->strip_tags($cName));
197 197
 
198 198
             $callClass = new $cName;
199 199
             // check if callback method (action) is exist in class object
200 200
             if (!method_exists($callClass, $callMethod))
201
-                throw new NotFoundException('Method "' . App::$Security->strip_tags($callMethod) . '()" not founded in "' . get_class($callClass) . '"');
201
+                throw new NotFoundException('Method "'.App::$Security->strip_tags($callMethod).'()" not founded in "'.get_class($callClass).'"');
202 202
 
203
-            $this->stopMeasure(__METHOD__ . '::callback');
203
+            $this->stopMeasure(__METHOD__.'::callback');
204 204
             $params = [];
205 205
             if (!Str::likeEmpty(self::$Request->getID())) {
206 206
                 $params[] = self::$Request->getID();
@@ -224,10 +224,10 @@  discard block
 block discarded – undo
224 224
                     'current' => count($params)
225 225
                 ]));
226 226
 
227
-            $this->startMeasure($cName . '::' . $callMethod);
227
+            $this->startMeasure($cName.'::'.$callMethod);
228 228
             // make callback call to action in controller and get response
229 229
             $actionResponse = call_user_func_array([$callClass, $callMethod], $params);
230
-            $this->stopMeasure($cName . '::' . $callMethod);
230
+            $this->stopMeasure($cName.'::'.$callMethod);
231 231
 
232 232
             // set response to controller attribute
233 233
             if (!Str::likeEmpty($actionResponse))
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
                 $html = $e->display();
242 242
             } else { // or hook exception to system based :)))
243 243
                 if (App::$Debug) {
244
-                    $msg = $e->getMessage() . $e->getTraceAsString();
244
+                    $msg = $e->getMessage().$e->getTraceAsString();
245 245
                     $html = (new NativeException($msg))->display();
246 246
                 } else {
247 247
                     $html = (new NativeException($e->getMessage()))->display();
Please login to merge, or discard this patch.
Braces   +21 added lines, -14 removed lines patch added patch discarded remove patch
@@ -156,8 +156,9 @@  discard block
 block discarded – undo
156 156
 
157 157
         /** @var array $objects */
158 158
         $objects = App::$Properties->getAll('object');
159
-        if (!Any::isArray($objects))
160
-            throw new NativeException('Object configurations is not loaded: /Private/Config/Object.php');
159
+        if (!Any::isArray($objects)) {
160
+                    throw new NativeException('Object configurations is not loaded: /Private/Config/Object.php');
161
+        }
161 162
 
162 163
         // each all objects as service_name => service_instance()
163 164
         foreach ($objects as $name => $instance) {
@@ -192,20 +193,23 @@  discard block
 block discarded – undo
192 193
 
193 194
             // define callback class namespace/name full path
194 195
             $cName = (self::$Request->getCallbackAlias() ?? '\Apps\Controller\\' . env_name . '\\' . self::$Request->getController());
195
-            if (!class_exists($cName))
196
-                throw new NotFoundException('Callback class not found: ' . App::$Security->strip_tags($cName));
196
+            if (!class_exists($cName)) {
197
+                            throw new NotFoundException('Callback class not found: ' . App::$Security->strip_tags($cName));
198
+            }
197 199
 
198 200
             $callClass = new $cName;
199 201
             // check if callback method (action) is exist in class object
200
-            if (!method_exists($callClass, $callMethod))
201
-                throw new NotFoundException('Method "' . App::$Security->strip_tags($callMethod) . '()" not founded in "' . get_class($callClass) . '"');
202
+            if (!method_exists($callClass, $callMethod)) {
203
+                            throw new NotFoundException('Method "' . App::$Security->strip_tags($callMethod) . '()" not founded in "' . get_class($callClass) . '"');
204
+            }
202 205
 
203 206
             $this->stopMeasure(__METHOD__ . '::callback');
204 207
             $params = [];
205 208
             if (!Str::likeEmpty(self::$Request->getID())) {
206 209
                 $params[] = self::$Request->getID();
207
-                if (!Str::likeEmpty(self::$Request->getAdd()))
208
-                    $params[] = self::$Request->getAdd();
210
+                if (!Str::likeEmpty(self::$Request->getAdd())) {
211
+                                    $params[] = self::$Request->getAdd();
212
+                }
209 213
             }
210 214
 
211 215
             // get instance of callback object (class::method) as reflection
@@ -213,16 +217,18 @@  discard block
 block discarded – undo
213 217
             $argCount = 0;
214 218
             // calculate method defined arguments count
215 219
             foreach ($instance->getParameters() as $arg) {
216
-                if (!$arg->isOptional())
217
-                    $argCount++;
220
+                if (!$arg->isOptional()) {
221
+                                    $argCount++;
222
+                }
218 223
             }
219 224
             // compare method arg count with passed
220
-            if (count($params) < $argCount)
221
-                throw new NotFoundException(__('Arguments for method %method% is not enough. Expected: %required%, got: %current%.', [
225
+            if (count($params) < $argCount) {
226
+                            throw new NotFoundException(__('Arguments for method %method% is not enough. Expected: %required%, got: %current%.', [
222 227
                     'method' => $callMethod,
223 228
                     'required' => $argCount,
224 229
                     'current' => count($params)
225 230
                 ]));
231
+            }
226 232
 
227 233
             $this->startMeasure($cName . '::' . $callMethod);
228 234
             // make callback call to action in controller and get response
@@ -230,8 +236,9 @@  discard block
 block discarded – undo
230 236
             $this->stopMeasure($cName . '::' . $callMethod);
231 237
 
232 238
             // set response to controller attribute
233
-            if (!Str::likeEmpty($actionResponse))
234
-                $callClass->setOutput($actionResponse);
239
+            if (!Str::likeEmpty($actionResponse)) {
240
+                            $callClass->setOutput($actionResponse);
241
+            }
235 242
 
236 243
             // build full compiled output html data with default layout and widgets
237 244
             $html = $callClass->buildOutput();
Please login to merge, or discard this patch.
src/Traits/ModelValidator.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -8,7 +8,6 @@
 block discarded – undo
8 8
 use Ffcms\Core\Exception\SyntaxException;
9 9
 use Ffcms\Core\Helper\ModelFilters;
10 10
 use Ffcms\Core\Helper\Type\Any;
11
-use Ffcms\Core\Helper\Type\Obj;
12 11
 use Ffcms\Core\Helper\Type\Str;
13 12
 
14 13
 /**
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
                     } elseif (method_exists($class, $obj)) { // maybe its a function?
138 138
                         $class = $class::$obj; // call function
139 139
                     } else {
140
-                        throw new SyntaxException('Filter callback execution failed: ' . $filterName);
140
+                        throw new SyntaxException('Filter callback execution failed: '.$filterName);
141 141
                     }
142 142
                 }
143 143
             }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
             if (method_exists($class, $method)) {
147 147
                 $check = @$class::$method($fieldValue, $filterArgs);
148 148
             } else {
149
-                throw new SyntaxException('Filter callback execution failed: ' . $filterName);
149
+                throw new SyntaxException('Filter callback execution failed: '.$filterName);
150 150
             }
151 151
         } elseif (method_exists('Ffcms\Core\Helper\ModelFilters', $filterName)) { // only full namespace\class path based :(
152 152
             if ($filterArgs != null) {
@@ -155,14 +155,14 @@  discard block
 block discarded – undo
155 155
                 $check = ModelFilters::$filterName($fieldValue);
156 156
             }
157 157
         } else {
158
-            throw new SyntaxException('Filter "' . $filterName . '" is not exist');
158
+            throw new SyntaxException('Filter "'.$filterName.'" is not exist');
159 159
         }
160 160
 
161 161
         // if one from all validation tests is fail - mark as incorrect attribute
162 162
         if ($check !== true) {
163 163
             $this->_badAttr[] = $propertyName;
164 164
             if (App::$Debug)
165
-                App::$Debug->addMessage('Validation failed. Property: ' . $propertyName . ', filter: ' . $filterName, 'warning');
165
+                App::$Debug->addMessage('Validation failed. Property: '.$propertyName.', filter: '.$filterName, 'warning');
166 166
         } else {
167 167
             $field_set_name = $propertyName;
168 168
             // prevent array-type setting
Please login to merge, or discard this patch.
Braces   +30 added lines, -20 removed lines patch added patch discarded remove patch
@@ -41,8 +41,9 @@  discard block
 block discarded – undo
41 41
             // if request is submited for this model - try to validate input data
42 42
             if ($this->send()) {
43 43
                 // token is wrong - update bool state
44
-                if ($currentToken !== $this->getRequest('_csrf_token'))
45
-                    $this->_tokenOk = false;
44
+                if ($currentToken !== $this->getRequest('_csrf_token')) {
45
+                                    $this->_tokenOk = false;
46
+                }
46 47
             }
47 48
             // set token data to display
48 49
             $this->_csrf_token = $newToken;
@@ -58,21 +59,24 @@  discard block
 block discarded – undo
58 59
     public function runValidate(array $rules = null)
59 60
     {
60 61
         // skip validation on empty rules
61
-        if ($rules === null)
62
-            return true;
62
+        if ($rules === null) {
63
+                    return true;
64
+        }
63 65
 
64 66
         $success = true;
65 67
         // list each rule as single one
66 68
         foreach ($rules as $rule) {
67 69
             // 0 = field (property) name, 1 = filter name, 2 = filter value
68
-            if ($rule[0] === null || $rule[1] === null)
69
-                continue;
70
+            if ($rule[0] === null || $rule[1] === null) {
71
+                            continue;
72
+            }
70 73
 
71 74
             $propertyName = $rule[0];
72 75
             $validationRule = $rule[1];
73 76
             $validationValue = null;
74
-            if (isset($rule[2]))
75
-                $validationValue = $rule[2];
77
+            if (isset($rule[2])) {
78
+                            $validationValue = $rule[2];
79
+            }
76 80
 
77 81
             // check if target field defined as array and make recursive validation
78 82
             if (Any::isArray($propertyName)) {
@@ -160,8 +164,9 @@  discard block
 block discarded – undo
160 164
         // if one from all validation tests is fail - mark as incorrect attribute
161 165
         if ($check !== true) {
162 166
             $this->_badAttr[] = $propertyName;
163
-            if (App::$Debug)
164
-                App::$Debug->addMessage('Validation failed. Property: ' . $propertyName . ', filter: ' . $filterName, 'warning');
167
+            if (App::$Debug) {
168
+                            App::$Debug->addMessage('Validation failed. Property: ' . $propertyName . ', filter: ' . $filterName, 'warning');
169
+            }
165 170
         } else {
166 171
             $field_set_name = $propertyName;
167 172
             // prevent array-type setting
@@ -172,8 +177,9 @@  discard block
 block discarded – undo
172 177
                 if ($propertyName !== $field_set_name) { // array-based property
173 178
                     $dot_path = trim(strstr($propertyName, '.'), '.');
174 179
                     // prevent throws any exceptions for null and false objects
175
-                    if (!Any::isArray($this->{$field_set_name}))
176
-                        $this->{$field_set_name} = [];
180
+                    if (!Any::isArray($this->{$field_set_name})) {
181
+                                            $this->{$field_set_name} = [];
182
+                    }
177 183
 
178 184
                     // use dot-data provider to compile output array
179 185
                     $dotData = new DotData($this->{$field_set_name});
@@ -203,14 +209,16 @@  discard block
 block discarded – undo
203 209
         $sources = $this->sources();
204 210
         $types = $this->types();
205 211
         // validate sources for current field
206
-        if (array_key_exists($propertyName, $sources))
207
-            $inputType = Str::lowerCase($sources[$propertyName]);
212
+        if (array_key_exists($propertyName, $sources)) {
213
+                    $inputType = Str::lowerCase($sources[$propertyName]);
214
+        }
208 215
 
209 216
 
210 217
         // check if field is array-nested element by dots and use first element as general
211 218
         $filterField = $propertyName;
212
-        if (array_key_exists($filterField, $types))
213
-            $filterType = Str::lowerCase($types[$filterField]);
219
+        if (array_key_exists($filterField, $types)) {
220
+                    $filterType = Str::lowerCase($types[$filterField]);
221
+        }
214 222
 
215 223
         // get clear field value
216 224
         $propertyValue = $this->getRequest($propertyName, $inputType);
@@ -312,8 +320,9 @@  discard block
 block discarded – undo
312 320
      */
313 321
     public function getRequest($param, $method = null)
314 322
     {
315
-        if ($method === null)
316
-            $method = $this->_sendMethod;
323
+        if ($method === null) {
324
+                    $method = $this->_sendMethod;
325
+        }
317 326
 
318 327
         $method = Str::lowerCase($method);
319 328
         // get root request as array or string
@@ -337,8 +346,9 @@  discard block
 block discarded – undo
337 346
         if (Str::contains('.', $param)) {
338 347
             $response = $request;
339 348
             foreach (explode('.', $param) as $path) {
340
-                if ($response !== null && !array_key_exists($path, $response))
341
-                    return null;
349
+                if ($response !== null && !array_key_exists($path, $response)) {
350
+                                    return null;
351
+                }
342 352
                 // find deep array nesting offset
343 353
                 $response = $response[$path];
344 354
             }
Please login to merge, or discard this patch.
src/Helper/Mailer.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
     {
50 50
         try {
51 51
             $this->message = App::$View->render($tpl, $params, $dir);
52
-        } catch (SyntaxException $e){}
52
+        } catch (SyntaxException $e) {}
53 53
         return $this;
54 54
     }
55 55
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         } catch (\Exception $e) {
81 81
             if (App::$Debug) {
82 82
                 App::$Debug->addException($e);
83
-                App::$Debug->addMessage('Send mail failed! Info: ' . $e->getMessage(), 'error');
83
+                App::$Debug->addMessage('Send mail failed! Info: '.$e->getMessage(), 'error');
84 84
             }
85 85
             return false;
86 86
         }
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -63,12 +63,14 @@
 block discarded – undo
63 63
     public function send(string $address, string $subject, ?string $message = null): bool
64 64
     {
65 65
         // try to get message from global if not passed direct
66
-        if ($message === null)
67
-            $message = $this->message;
66
+        if ($message === null) {
67
+                    $message = $this->message;
68
+        }
68 69
 
69 70
         try {
70
-            if ($message === null)
71
-                throw new \Exception('Message body is empty!');
71
+            if ($message === null) {
72
+                            throw new \Exception('Message body is empty!');
73
+            }
72 74
 
73 75
             // try to build message and send it
74 76
             $message = (new \Swift_Message($subject))
Please login to merge, or discard this patch.