Passed
Push — master ( 1e96ad...00da65 )
by Smoren
01:46
created
src/Exceptions/SchematorException.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
      */
27 27
     public static function ensureFilterExists(array $filterMap, string $filterName): void
28 28
     {
29
-        if(!isset($filterMap[$filterName])) {
29
+        if (!isset($filterMap[$filterName])) {
30 30
             throw new SchematorException(
31 31
                 "filter '{$filterName}' not found",
32 32
                 SchematorException::FILTER_NOT_FOUND,
Please login to merge, or discard this patch.
src/Filters/BaseFiltersStorage.php 1 patch
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -23,10 +23,10 @@  discard block
 block discarded – undo
23 23
     public static function date(FilterContextInterface $context, string $format, ?int $timezone = null)
24 24
     {
25 25
         $source = $context->getSource();
26
-        if($source === null) {
26
+        if ($source === null) {
27 27
             return null;
28 28
         }
29
-        if($timezone === null) {
29
+        if ($timezone === null) {
30 30
             return date($format, $source);
31 31
         }
32 32
         return gmdate($format, $source+3600*$timezone);
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
     public static function implode(FilterContextInterface $context, string $delimiter = ', '): ?string
36 36
     {
37 37
         $source = $context->getSource();
38
-        if($source === null) {
38
+        if ($source === null) {
39 39
             return null;
40 40
         }
41 41
         return implode($delimiter, $source);
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
     public static function explode(FilterContextInterface $context, string $delimiter = ', ')
45 45
     {
46 46
         $source = $context->getSource();
47
-        if($source === null) {
47
+        if ($source === null) {
48 48
             return null;
49 49
         }
50 50
         return explode($delimiter, $source);
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     public static function sum(FilterContextInterface $context)
54 54
     {
55 55
         $source = $context->getSource();
56
-        if($source === null) {
56
+        if ($source === null) {
57 57
             return null;
58 58
         }
59 59
         return array_sum($source);
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     public static function average(FilterContextInterface $context)
63 63
     {
64 64
         $source = $context->getSource();
65
-        if($source === null) {
65
+        if ($source === null) {
66 66
             return null;
67 67
         }
68 68
         return array_sum($source)/count($source);
@@ -71,21 +71,21 @@  discard block
 block discarded – undo
71 71
     public static function filter(FilterContextInterface $context, $filterConfig): ?array
72 72
     {
73 73
         $source = $context->getSource();
74
-        if($source === null) {
74
+        if ($source === null) {
75 75
             return null;
76 76
         }
77 77
 
78
-        if(is_callable($filterConfig)) {
78
+        if (is_callable($filterConfig)) {
79 79
             return array_values(array_filter($source, $filterConfig));
80 80
         }
81 81
 
82 82
         $result = [];
83 83
 
84
-        foreach($source as $item) {
85
-            foreach($filterConfig as $args) {
84
+        foreach ($source as $item) {
85
+            foreach ($filterConfig as $args) {
86 86
                 $rule = array_shift($args);
87 87
 
88
-                if(RuleHelper::check($item, $rule, $args)) {
88
+                if (RuleHelper::check($item, $rule, $args)) {
89 89
                     $result[] = $item;
90 90
                     break;
91 91
                 }
@@ -98,10 +98,10 @@  discard block
 block discarded – undo
98 98
     public static function sort(FilterContextInterface $context, ?callable $sortCallback = null): ?array
99 99
     {
100 100
         $source = $context->getSource();
101
-        if($source === null) {
101
+        if ($source === null) {
102 102
             return null;
103 103
         }
104
-        if($sortCallback !== null) {
104
+        if ($sortCallback !== null) {
105 105
             usort($source, $sortCallback);
106 106
         } else {
107 107
             sort($source);
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
     public static function rsort(FilterContextInterface $context): ?array
113 113
     {
114 114
         $source = $context->getSource();
115
-        if($source === null) {
115
+        if ($source === null) {
116 116
             return null;
117 117
         }
118 118
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
     public static function path(FilterContextInterface $context)
124 124
     {
125 125
         $source = $context->getSource();
126
-        if($source === null) {
126
+        if ($source === null) {
127 127
             return null;
128 128
         }
129 129
         return $context->getSchemator()->getValue($context->getRootSource(), $source);
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
     public static function flatten(FilterContextInterface $context): ?array
133 133
     {
134 134
         $source = $context->getSource();
135
-        if($source === null) {
135
+        if ($source === null) {
136 136
             return null;
137 137
         }
138 138
         return ArrHelper::flatten($source);
@@ -141,33 +141,33 @@  discard block
 block discarded – undo
141 141
     public static function replace(FilterContextInterface $context, array $rules)
142 142
     {
143 143
         $source = $context->getSource();
144
-        if($source === null) {
144
+        if ($source === null) {
145 145
             return null;
146 146
         }
147 147
 
148 148
         $isArray = is_array($source);
149 149
 
150
-        if(!$isArray) {
150
+        if (!$isArray) {
151 151
             $source = [$source];
152 152
         }
153 153
 
154 154
         $result = [];
155 155
 
156
-        foreach($source as $item) {
156
+        foreach ($source as $item) {
157 157
             $isReplaced = false;
158 158
             $elseValue = $item;
159 159
 
160
-            foreach($rules as $args) {
160
+            foreach ($rules as $args) {
161 161
                 $value = array_shift($args);
162 162
                 $rule = array_shift($args);
163 163
 
164
-                if($rule === 'else') {
164
+                if ($rule === 'else') {
165 165
                     $elseValue = $value;
166 166
                 }
167 167
 
168 168
                 $replace = null;
169 169
 
170
-                if(RuleHelper::check($item, $rule, $args)) {
170
+                if (RuleHelper::check($item, $rule, $args)) {
171 171
                     $replace = $value;
172 172
                     $isReplaced = true;
173 173
 
@@ -176,12 +176,12 @@  discard block
 block discarded – undo
176 176
                 }
177 177
             }
178 178
 
179
-            if(!$isReplaced) {
179
+            if (!$isReplaced) {
180 180
                 $result[] = $elseValue;
181 181
             }
182 182
         }
183 183
 
184
-        if(!$isArray) {
184
+        if (!$isArray) {
185 185
             $result = $result[0];
186 186
         }
187 187
 
Please login to merge, or discard this patch.
src/Factories/SchematorFactory.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,11 +20,11 @@
 block discarded – undo
20 20
     {
21 21
         $builder = static::createBuilder();
22 22
 
23
-        if($withBaseFilters) {
23
+        if ($withBaseFilters) {
24 24
             $builder->withFilters(new BaseFiltersStorage());
25 25
         }
26 26
 
27
-        if(count($extraFilters)) {
27
+        if (count($extraFilters)) {
28 28
             $builder->withFilters($extraFilters);
29 29
         }
30 30
 
Please login to merge, or discard this patch.
src/Factories/SchematorBuilder.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
      */
41 41
     public function withFilters(iterable $filters): SchematorBuilderInterface
42 42
     {
43
-        foreach($filters as $filterName => $filter) {
43
+        foreach ($filters as $filterName => $filter) {
44 44
             $this->schemator->addFilter($filterName, $filter);
45 45
         }
46 46
         return $this;
Please login to merge, or discard this patch.
src/Components/MassSchemator.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public function generate(iterable $source, array $schema): Generator
34 34
     {
35
-        foreach($source as $item) {
35
+        foreach ($source as $item) {
36 36
             yield $this->schemator->exec($item, $schema);
37 37
         }
38 38
     }
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
         $gen = $this->generate($source, $schema);
46 46
         $result = [];
47 47
 
48
-        foreach($gen as $item) {
48
+        foreach ($gen as $item) {
49 49
             $result[] = $item;
50 50
         }
51 51
 
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
         $gen = $this->generate($source, $schema);
63 63
         $result = [];
64 64
 
65
-        foreach($gen as $item) {
65
+        foreach ($gen as $item) {
66 66
             $result[] = $item;
67 67
         }
68 68
 
Please login to merge, or discard this patch.
src/Components/Schemator.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
     {
49 49
         $toAccessor = $this->nestedAccessorFactory->create($result, $this->pathDelimiter);
50 50
 
51
-        foreach($schema as $keyTo => $keyFrom) {
51
+        foreach ($schema as $keyTo => $keyFrom) {
52 52
             $value = $this->getValue($source, $keyFrom, $strict);
53
-            if($keyTo === '') {
53
+            if ($keyTo === '') {
54 54
                 return $value;
55 55
             }
56 56
             $toAccessor->set($keyTo, $value, $strict);
@@ -73,19 +73,19 @@  discard block
 block discarded – undo
73 73
      */
74 74
     public function getValue($source, $key, bool $strict = false)
75 75
     {
76
-        if($key === '' || $key === null) {
76
+        if ($key === '' || $key === null) {
77 77
             return $source;
78 78
         }
79 79
 
80
-        if($source === null || (!is_array($source) && !is_object($source))) {
80
+        if ($source === null || (!is_array($source) && !is_object($source))) {
81 81
             return $this->getValueFromUnsupportedSource($source, $key, $strict);
82 82
         }
83 83
 
84
-        if(is_string($key)) {
84
+        if (is_string($key)) {
85 85
             return $this->getValueByKey($source, $key, $strict);
86 86
         }
87 87
 
88
-        if(is_array($key)) {
88
+        if (is_array($key)) {
89 89
             return $this->getValueByFilters($source, $key, $strict);
90 90
         }
91 91
 
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         try {
115 115
             $fromAccessor = $this->nestedAccessorFactory->create($source, $this->pathDelimiter);
116 116
             return $fromAccessor->get($key, $strict);
117
-        } catch(NestedAccessorException $e) {
117
+        } catch (NestedAccessorException $e) {
118 118
             throw SchematorException::createAsCannotGetValue($source, $key, $e);
119 119
         }
120 120
     }
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
     protected function getValueByFilters($source, array $filters, bool $strict)
131 131
     {
132 132
         $result = $source;
133
-        foreach($filters as $filterConfig) {
134
-            if(is_string($filterConfig)) {
133
+        foreach ($filters as $filterConfig) {
134
+            if (is_string($filterConfig)) {
135 135
                 $result = $this->getValue($result, $filterConfig, $strict);
136
-            } elseif(is_array($filterConfig)) {
136
+            } elseif (is_array($filterConfig)) {
137 137
                 $result = $this->runFilter($filterConfig, $result, $source, $strict);
138 138
             } else {
139
-                if($strict) {
139
+                if ($strict) {
140 140
                     throw SchematorException::createAsUnsupportedFilterConfigType($filterConfig);
141 141
                 }
142 142
                 $result = null;
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      */
157 157
     protected function getValueFromUnsupportedSource($source, $key, bool $strict)
158 158
     {
159
-        if(!$strict) {
159
+        if (!$strict) {
160 160
             return null;
161 161
         }
162 162
         throw SchematorException::createAsUnsupportedSourceType($source, $key);
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      */
173 173
     protected function getValueByUnsupportedKey($source, $key, bool $strict)
174 174
     {
175
-        if(!$strict) {
175
+        if (!$strict) {
176 176
             return null;
177 177
         }
178 178
         throw SchematorException::createAsUnsupportedKeyType($source, $key);
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
                 new FilterContext($this, $source, $rootSource),
199 199
                 ...$filterConfig
200 200
             );
201
-        } catch(Throwable $e) {
202
-            if($strict) {
201
+        } catch (Throwable $e) {
202
+            if ($strict) {
203 203
                 throw SchematorException::createAsFilterError($filterName, $filterConfig, $source, $e);
204 204
             }
205 205
             return null;
Please login to merge, or discard this patch.
src/Components/NestedAccessor.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
      */
30 30
     public function __construct(&$source, string $pathDelimiter = '.')
31 31
     {
32
-        if($source === null) {
32
+        if ($source === null) {
33 33
             $source = [];
34 34
         }
35 35
 
36
-        if(is_scalar($source)) {
36
+        if (is_scalar($source)) {
37 37
             throw NestedAccessorException::createAsSourceIsScalar($source);
38 38
         }
39 39
 
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     public function get(?string $path = null, bool $strict = true)
53 53
     {
54 54
         // when path is not specified
55
-        if($path === null || $path === '') {
55
+        if ($path === null || $path === '') {
56 56
             // let's return the full source
57 57
             return $this->source;
58 58
         }
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
         );
71 71
 
72 72
         // when strict mode is on and we got errors
73
-        if($strict && $errorsCount) {
73
+        if ($strict && $errorsCount) {
74 74
             throw NestedAccessorException::createAsCannotGetValue($path, $errorsCount);
75 75
         }
76 76
 
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
     protected function _get($source, array $path, &$result, int &$errorsCount): void
102 102
     {
103 103
         // if path stack is empty — we reached target value of given path in source argument
104
-        if(!count($path)) {
104
+        if (!count($path)) {
105 105
             // so if result is multiple
106
-            if(is_array($result)) {
106
+            if (is_array($result)) {
107 107
                 // we append source to result
108 108
                 $result[] = $source;
109 109
             } else {
@@ -115,11 +115,11 @@  discard block
 block discarded – undo
115 115
         }
116 116
 
117 117
         // let's iterate every path part from stack
118
-        while(count($path)) {
118
+        while (count($path)) {
119 119
             $key = array_pop($path);
120 120
 
121
-            if(is_array($source)) {
122
-                if(!array_key_exists($key, $source)) {
121
+            if (is_array($source)) {
122
+                if (!array_key_exists($key, $source)) {
123 123
                     // path part key is missing in source array
124 124
                     $errorsCount++;
125 125
                     // we cannot go deeper
@@ -127,8 +127,8 @@  discard block
 block discarded – undo
127 127
                 }
128 128
                 // go to the next nested level
129 129
                 $source = $source[$key];
130
-            } elseif(is_object($source)) {
131
-                if(!property_exists($source, $key)) {
130
+            } elseif (is_object($source)) {
131
+                if (!property_exists($source, $key)) {
132 132
                     // path part key is missing in source object
133 133
                     $errorsCount++;
134 134
                     // we cannot go deeper
@@ -145,13 +145,13 @@  discard block
 block discarded – undo
145 145
 
146 146
             // when it's not the last iteration of the stack
147 147
             // and the source is non-associative array (list)
148
-            if(count($path) && is_array($source) && !ArrHelper::isAssoc($source)) {
148
+            if (count($path) && is_array($source) && !ArrHelper::isAssoc($source)) {
149 149
                 // the result will be multiple
150
-                if(!is_array($result)) {
150
+                if (!is_array($result)) {
151 151
                     $result = [];
152 152
                 }
153 153
                 // and we need to use recursive call for each item of this array
154
-                foreach($source as $item) {
154
+                foreach ($source as $item) {
155 155
                     $this->_get($item, $path, $result, $errorsCount);
156 156
                 }
157 157
                 // we don't need to do something in this recursive branch
@@ -177,15 +177,15 @@  discard block
 block discarded – undo
177 177
     {
178 178
         $temp = &$source;
179 179
         // let's iterate every path part to go deeper into nesting
180
-        foreach($path as $key) {
181
-            if(isset($temp) && is_scalar($temp)) {
180
+        foreach ($path as $key) {
181
+            if (isset($temp) && is_scalar($temp)) {
182 182
                 // value in the middle of the path must me an array
183 183
                 $temp = [];
184 184
             }
185 185
 
186 186
             // go to the next nested level
187
-            if(is_object($temp)) {
188
-                if($strict && !property_exists($temp, $key)) {
187
+            if (is_object($temp)) {
188
+                if ($strict && !property_exists($temp, $key)) {
189 189
                     throw NestedAccessorException::createAsCannotSetValue($key);
190 190
                 }
191 191
                 $temp = &$temp->{$key};
Please login to merge, or discard this patch.