Completed
Push — master ( f54537...394c45 )
by Mihail
02:09
created
src/Ffcms/Core/Helper/HTML/Form.php 3 patches
Unused Use Statements   -5 removed lines patch added patch discarded remove patch
@@ -4,16 +4,11 @@
 block discarded – undo
4 4
 
5 5
 use Ffcms\Core\App;
6 6
 use Ffcms\Core\Arch\Model;
7
-use Ffcms\Core\Exception\NativeException;
8 7
 use Ffcms\Core\Exception\SyntaxException;
9 8
 use Ffcms\Core\Helper\FileSystem\File;
10
-use Ffcms\Core\Helper\HTML\Form\Constructor;
11 9
 use Ffcms\Core\Helper\HTML\Form\FieldSelector;
12 10
 use Ffcms\Core\Helper\HTML\System\NativeGenerator;
13 11
 use Ffcms\Core\Helper\Type\Any;
14
-use Ffcms\Core\Helper\Type\Arr;
15
-use Ffcms\Core\Helper\Type\Obj;
16
-use Ffcms\Core\Helper\Type\Str;
17 12
 
18 13
 /**
19 14
  * Class Form. Simple HTML model generator for fast form building.
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
     {
87 87
         $form = self::buildSingleTag('form', $this->formProperty, false);
88 88
         if ($this->model->_tokenRequired)
89
-            $form .= PHP_EOL . $this->field->hidden('_csrf_token', ['value' => $this->model->_csrf_token]);
89
+            $form .= PHP_EOL.$this->field->hidden('_csrf_token', ['value' => $this->model->_csrf_token]);
90 90
 
91 91
         return $form;
92 92
     }
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
         $response = null;
107 107
         try {
108 108
             $response = $this->field->{$type}($object, $property, $helper, $layerFile);
109
-        } catch (\Exception $e){}
109
+        } catch (\Exception $e) {}
110 110
         return $response;
111 111
     }
112 112
 
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     public function submitButton($title, array $property = [])
120 120
     {
121 121
         $property['type'] = 'submit';
122
-        $property['name'] = $this->name . '[submit]';
122
+        $property['name'] = $this->name.'[submit]';
123 123
         $property['value'] = $title;
124 124
         return self::buildSingleTag('input', $property);
125 125
     }
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
     {
134 134
         // pre-validate form fields based on model rules and jquery.validation
135 135
         if ($validate) {
136
-            App::$Alias->addPlainCode('js', '$().ready(function() { $("#' . $this->name . '").validate(); });');
136
+            App::$Alias->addPlainCode('js', '$().ready(function() { $("#'.$this->name.'").validate(); });');
137 137
             App::$Alias->setCustomLibrary('js', '/vendor/bower/jquery-validation/dist/jquery.validate.min.js');
138 138
             if (App::$Request->getLanguage() !== 'en') {
139
-                $localeFile = '/vendor/bower/jquery-validation/src/localization/messages_' . App::$Request->getLanguage() . '.js';
139
+                $localeFile = '/vendor/bower/jquery-validation/src/localization/messages_'.App::$Request->getLanguage().'.js';
140 140
                 if (File::exist($localeFile)) {
141 141
                     App::$Alias->setCustomLibrary('js', $localeFile);
142 142
                 }
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
                 $formName = $this->model->getFormName();
148 148
                 if (Any::isArray($badAttr) && count($badAttr) > 0) {
149 149
                     foreach ($badAttr as $attr) {
150
-                        $itemId = $formName . '-' . $attr;
150
+                        $itemId = $formName.'-'.$attr;
151 151
                         try {
152 152
                             $render = App::$View->render(static::$structLayer['jsnotify'], ['itemId' => $itemId]);
153 153
                             App::$Alias->addPlainCode('js', $render);
Please login to merge, or discard this patch.
Braces   +15 added lines, -10 removed lines patch added patch discarded remove patch
@@ -50,8 +50,9 @@  discard block
 block discarded – undo
50 50
     public function __construct($model, array $property = null, array $layerFiles = null)
51 51
     {
52 52
         // prevent white-screen locks when model is not passed or passed wrong
53
-        if (!$model instanceof Model)
54
-            throw new SyntaxException('Bad model type passed in form builder. Check for init: new Form()');
53
+        if (!$model instanceof Model) {
54
+                    throw new SyntaxException('Bad model type passed in form builder. Check for init: new Form()');
55
+        }
55 56
 
56 57
         $this->model = $model;
57 58
         $this->name = $model->getFormName();
@@ -59,8 +60,9 @@  discard block
 block discarded – undo
59 60
         // check if passed custom layer file
60 61
         if (Any::isArray($layerFiles) && count($layerFiles) > 0) {
61 62
             foreach (array_keys(static::$structLayer) as $type) {
62
-                if (isset($layerFiles[$type]) && Any::isStr($layerFiles[$type]))
63
-                    static::$structLayer[$type] = $layerFiles[$type];
63
+                if (isset($layerFiles[$type]) && Any::isStr($layerFiles[$type])) {
64
+                                    static::$structLayer[$type] = $layerFiles[$type];
65
+                }
64 66
             }
65 67
         }
66 68
         // initialize field selector helper
@@ -71,8 +73,9 @@  discard block
 block discarded – undo
71 73
 
72 74
         $property['id'] = $this->name; // define form id
73 75
         // if action is not defined - define it
74
-        if (!$property['action'])
75
-            $property['action'] = App::$Request->getFullUrl();
76
+        if (!$property['action']) {
77
+                    $property['action'] = App::$Request->getFullUrl();
78
+        }
76 79
 
77 80
         // set property global for this form
78 81
         $this->formProperty = $property;
@@ -85,8 +88,9 @@  discard block
 block discarded – undo
85 88
     public function start()
86 89
     {
87 90
         $form = self::buildSingleTag('form', $this->formProperty, false);
88
-        if ($this->model->_tokenRequired)
89
-            $form .= PHP_EOL . $this->field->hidden('_csrf_token', ['value' => $this->model->_csrf_token]);
91
+        if ($this->model->_tokenRequired) {
92
+                    $form .= PHP_EOL . $this->field->hidden('_csrf_token', ['value' => $this->model->_csrf_token]);
93
+        }
90 94
 
91 95
         return $form;
92 96
     }
@@ -152,8 +156,9 @@  discard block
 block discarded – undo
152 156
                             $render = App::$View->render(static::$structLayer['jsnotify'], ['itemId' => $itemId]);
153 157
                             App::$Alias->addPlainCode('js', $render);
154 158
                         } catch (SyntaxException $e) {
155
-                            if (App::$Debug)
156
-                                App::$Debug->addException($e);
159
+                            if (App::$Debug) {
160
+                                                            App::$Debug->addException($e);
161
+                            }
157 162
                         }
158 163
                     }
159 164
                 }
Please login to merge, or discard this patch.
src/Ffcms/Core/Helper/Mailer.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     {
51 51
         try {
52 52
             $this->message = App::$View->render($tpl, $params, $dir);
53
-        } catch (SyntaxException $e){}
53
+        } catch (SyntaxException $e) {}
54 54
         return $this;
55 55
     }
56 56
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
         } catch (\Exception $e) {
74 74
             if (App::$Debug) {
75 75
                 App::$Debug->addException($e);
76
-                App::$Debug->addMessage('Send mail failed! Info: ' . $e->getMessage(), 'error');
76
+                App::$Debug->addMessage('Send mail failed! Info: '.$e->getMessage(), 'error');
77 77
             }
78 78
         }
79 79
     }
Please login to merge, or discard this patch.
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -57,12 +57,14 @@
 block discarded – undo
57 57
     public function send(string $to, string $subject, ?string $message = null)
58 58
     {
59 59
         // try to get message from global if not passed direct
60
-        if ($message === null)
61
-            $message = $this->message;
60
+        if ($message === null) {
61
+                    $message = $this->message;
62
+        }
62 63
 
63 64
         try {
64
-            if ($message === null)
65
-                throw new \Exception('Message body is empty!');
65
+            if ($message === null) {
66
+                            throw new \Exception('Message body is empty!');
67
+            }
66 68
 
67 69
             // try to build message and send it
68 70
             $message = (new \Swift_Message($subject))
Please login to merge, or discard this patch.
src/Ffcms/Core/Helper/HTML/Form/FieldSelector.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
         // check if model has attribute
78 78
         if (!property_exists($this->model, $rootName)) {
79 79
             if (App::$Debug)
80
-                App::$Debug->addMessage('Field "' . $name . '" (' . $field . ') is not defined in model: [' . get_class($this->model) . ']', 'error');
80
+                App::$Debug->addMessage('Field "'.$name.'" ('.$field.') is not defined in model: ['.get_class($this->model).']', 'error');
81 81
 
82 82
             return null;
83 83
         }
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
         // prepare default layer if not passed
86 86
         $layer = $this->findFieldLayer($field, $layer);
87 87
         // prepare html attributes, object value
88
-        $attr = $this->model->getFormName() . '-' . $rootName;
88
+        $attr = $this->model->getFormName().'-'.$rootName;
89 89
         $label = $this->model->getLabel($name);
90 90
         $value = $this->model->{$rootName};
91 91
         // check if dot-nested array used and update attr name
92 92
         if ($rootName !== $name) {
93 93
             $nesting = trim(strstr($name, '.'), '.');
94
-            $attr .= '-' . Str::replace('.', '-', $nesting);
94
+            $attr .= '-'.Str::replace('.', '-', $nesting);
95 95
             $value = Arr::getByPath($nesting, $value);
96 96
         }
97 97
 
Please login to merge, or discard this patch.
Braces   +27 added lines, -18 removed lines patch added patch discarded remove patch
@@ -52,32 +52,38 @@  discard block
 block discarded – undo
52 52
      */
53 53
     public function __call(string $field, ?array $arguments = null): ?string
54 54
     {
55
-        if ($arguments === null || count($arguments) < 1)
56
-            return null;
55
+        if ($arguments === null || count($arguments) < 1) {
56
+                    return null;
57
+        }
57 58
 
58 59
         // get named arguments from passed array
59 60
         $name = (string)$arguments[0];
60 61
         $rootName = $name;
61 62
         // set root element name if array dot-nested notation found
62
-        if (Str::contains('.', $name))
63
-            $rootName = strstr($rootName, '.', true);
63
+        if (Str::contains('.', $name)) {
64
+                    $rootName = strstr($rootName, '.', true);
65
+        }
64 66
         // define properties, helper and layer
65 67
         $properties = null;
66 68
         $helper = null;
67 69
         $layer = null;
68
-        if (isset($arguments[1]))
69
-            $properties = (array)$arguments[1];
70
+        if (isset($arguments[1])) {
71
+                    $properties = (array)$arguments[1];
72
+        }
70 73
 
71
-        if (isset($arguments[2]))
72
-            $helper = (string)$arguments[2];
74
+        if (isset($arguments[2])) {
75
+                    $helper = (string)$arguments[2];
76
+        }
73 77
 
74
-        if (isset($arguments[3]))
75
-            $layer = (string)$arguments[3];
78
+        if (isset($arguments[3])) {
79
+                    $layer = (string)$arguments[3];
80
+        }
76 81
 
77 82
         // check if model has attribute
78 83
         if (!property_exists($this->model, $rootName)) {
79
-            if (App::$Debug)
80
-                App::$Debug->addMessage('Field "' . $name . '" (' . $field . ') is not defined in model: [' . get_class($this->model) . ']', 'error');
84
+            if (App::$Debug) {
85
+                            App::$Debug->addMessage('Field "' . $name . '" (' . $field . ') is not defined in model: [' . get_class($this->model) . ']', 'error');
86
+            }
81 87
 
82 88
             return null;
83 89
         }
@@ -100,8 +106,9 @@  discard block
 block discarded – undo
100 106
         $elementDOM = $constructor->makeTag($name, $value, $properties);
101 107
 
102 108
         // if item is hidden - return tag without assign of global template
103
-        if ($field === 'hidden')
104
-            return $elementDOM;
109
+        if ($field === 'hidden') {
110
+                    return $elementDOM;
111
+        }
105 112
 
106 113
         // prepare output html
107 114
         try {
@@ -112,8 +119,9 @@  discard block
 block discarded – undo
112 119
                 'help' => self::nohtml($helper)
113 120
             ]);
114 121
         } catch (SyntaxException $e) {
115
-            if (App::$Debug)
116
-                App::$Debug->addException($e);
122
+            if (App::$Debug) {
123
+                            App::$Debug->addException($e);
124
+            }
117 125
             return null;
118 126
         }
119 127
     }
@@ -126,8 +134,9 @@  discard block
 block discarded – undo
126 134
      */
127 135
     private function findFieldLayer(?string $type = null, ?string $layer = null): ?string
128 136
     {
129
-        if ($layer !== null)
130
-            return $layer;
137
+        if ($layer !== null) {
138
+                    return $layer;
139
+        }
131 140
 
132 141
         switch ($type) {
133 142
             case 'checkbox':
Please login to merge, or discard this patch.
src/Ffcms/Core/Helper/HTML/Form/PasswordField.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,8 +30,9 @@
 block discarded – undo
30 30
      */
31 31
     public function make()
32 32
     {
33
-        if (isset($this->properties['value']))
34
-            unset($this->properties['value']);
33
+        if (isset($this->properties['value'])) {
34
+                    unset($this->properties['value']);
35
+        }
35 36
 
36 37
         $this->properties['type'] = 'password';
37 38
         
Please login to merge, or discard this patch.
src/Ffcms/Core/Traits/ModelValidator.php 1 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 (!array_key_exists($path, $response))
341
-                    return null;
349
+                if (!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.