@@ -25,11 +25,11 @@  | 
                                                    ||
| 25 | 25 |      { | 
                                                        
| 26 | 26 | $builder = static::createBuilder();  | 
                                                        
| 27 | 27 | |
| 28 | -        if($withBaseFilters) { | 
                                                        |
| 28 | +        if ($withBaseFilters) { | 
                                                        |
| 29 | 29 | $builder->withFilters(new BaseFiltersStorage($builder->get()));  | 
                                                        
| 30 | 30 | }  | 
                                                        
| 31 | 31 | |
| 32 | -        if(count($extraFilters)) { | 
                                                        |
| 32 | +        if (count($extraFilters)) { | 
                                                        |
| 33 | 33 | $builder->withFilters($extraFilters);  | 
                                                        
| 34 | 34 | }  | 
                                                        
| 35 | 35 | |
@@ -23,7 +23,7 @@  | 
                                                    ||
| 23 | 23 | |
| 24 | 24 | public function withFilters($filters): SchematorBuilderInterface  | 
                                                        
| 25 | 25 |      { | 
                                                        
| 26 | -        foreach($filters as $filterName => $filter) { | 
                                                        |
| 26 | +        foreach ($filters as $filterName => $filter) { | 
                                                        |
| 27 | 27 | $this->schemator->addFilter($filterName, $filter);  | 
                                                        
| 28 | 28 | }  | 
                                                        
| 29 | 29 | return $this;  | 
                                                        
@@ -31,10 +31,10 @@ discard block  | 
                                                    ||
| 31 | 31 | ?int $timezone = null  | 
                                                        
| 32 | 32 |      ) { | 
                                                        
| 33 | 33 | $source = $context->getSource();  | 
                                                        
| 34 | -        if($source === null) { | 
                                                        |
| 34 | +        if ($source === null) { | 
                                                        |
| 35 | 35 | return null;  | 
                                                        
| 36 | 36 | }  | 
                                                        
| 37 | -        if($timezone === null) { | 
                                                        |
| 37 | +        if ($timezone === null) { | 
                                                        |
| 38 | 38 | return date($format, $source);  | 
                                                        
| 39 | 39 | }  | 
                                                        
| 40 | 40 | return gmdate($format, $source+3600*$timezone);  | 
                                                        
@@ -45,7 +45,7 @@ discard block  | 
                                                    ||
| 45 | 45 | string $delimiter = ', '  | 
                                                        
| 46 | 46 |      ): ?string { | 
                                                        
| 47 | 47 | $source = $context->getSource();  | 
                                                        
| 48 | -        if($source === null) { | 
                                                        |
| 48 | +        if ($source === null) { | 
                                                        |
| 49 | 49 | return null;  | 
                                                        
| 50 | 50 | }  | 
                                                        
| 51 | 51 | return implode($delimiter, $source);  | 
                                                        
@@ -56,7 +56,7 @@ discard block  | 
                                                    ||
| 56 | 56 | string $delimiter = ', '  | 
                                                        
| 57 | 57 |      ) { | 
                                                        
| 58 | 58 | $source = $context->getSource();  | 
                                                        
| 59 | -        if($source === null) { | 
                                                        |
| 59 | +        if ($source === null) { | 
                                                        |
| 60 | 60 | return null;  | 
                                                        
| 61 | 61 | }  | 
                                                        
| 62 | 62 | return explode($delimiter, $source);  | 
                                                        
@@ -65,7 +65,7 @@ discard block  | 
                                                    ||
| 65 | 65 | public static function sum(FilterContextInterface $context)  | 
                                                        
| 66 | 66 |      { | 
                                                        
| 67 | 67 | $source = $context->getSource();  | 
                                                        
| 68 | -        if($source === null) { | 
                                                        |
| 68 | +        if ($source === null) { | 
                                                        |
| 69 | 69 | return null;  | 
                                                        
| 70 | 70 | }  | 
                                                        
| 71 | 71 | return array_sum($source);  | 
                                                        
@@ -74,7 +74,7 @@ discard block  | 
                                                    ||
| 74 | 74 | public static function average(FilterContextInterface $context)  | 
                                                        
| 75 | 75 |      { | 
                                                        
| 76 | 76 | $source = $context->getSource();  | 
                                                        
| 77 | -        if($source === null) { | 
                                                        |
| 77 | +        if ($source === null) { | 
                                                        |
| 78 | 78 | return null;  | 
                                                        
| 79 | 79 | }  | 
                                                        
| 80 | 80 | return array_sum($source)/count($source);  | 
                                                        
@@ -86,21 +86,21 @@ discard block  | 
                                                    ||
| 86 | 86 | ): ?array  | 
                                                        
| 87 | 87 |      { | 
                                                        
| 88 | 88 | $source = $context->getSource();  | 
                                                        
| 89 | -        if($source === null) { | 
                                                        |
| 89 | +        if ($source === null) { | 
                                                        |
| 90 | 90 | return null;  | 
                                                        
| 91 | 91 | }  | 
                                                        
| 92 | 92 | |
| 93 | -        if(is_callable($filterConfig)) { | 
                                                        |
| 93 | +        if (is_callable($filterConfig)) { | 
                                                        |
| 94 | 94 | return array_values(array_filter($source, $filterConfig));  | 
                                                        
| 95 | 95 | }  | 
                                                        
| 96 | 96 | |
| 97 | 97 | $result = [];  | 
                                                        
| 98 | 98 | |
| 99 | -        foreach($source as $item) { | 
                                                        |
| 100 | -            foreach($filterConfig as $args) { | 
                                                        |
| 99 | +        foreach ($source as $item) { | 
                                                        |
| 100 | +            foreach ($filterConfig as $args) { | 
                                                        |
| 101 | 101 | $rule = array_shift($args);  | 
                                                        
| 102 | 102 | |
| 103 | -                if(RuleHelper::check($item, $rule, $args)) { | 
                                                        |
| 103 | +                if (RuleHelper::check($item, $rule, $args)) { | 
                                                        |
| 104 | 104 | $result[] = $item;  | 
                                                        
| 105 | 105 | break;  | 
                                                        
| 106 | 106 | }  | 
                                                        
@@ -115,10 +115,10 @@ discard block  | 
                                                    ||
| 115 | 115 | ?callable $sortCallback = null  | 
                                                        
| 116 | 116 |      ): ?array { | 
                                                        
| 117 | 117 | $source = $context->getSource();  | 
                                                        
| 118 | -        if($source === null) { | 
                                                        |
| 118 | +        if ($source === null) { | 
                                                        |
| 119 | 119 | return null;  | 
                                                        
| 120 | 120 | }  | 
                                                        
| 121 | -        if($sortCallback !== null) { | 
                                                        |
| 121 | +        if ($sortCallback !== null) { | 
                                                        |
| 122 | 122 | usort($source, $sortCallback);  | 
                                                        
| 123 | 123 |          } else { | 
                                                        
| 124 | 124 | sort($source);  | 
                                                        
@@ -129,7 +129,7 @@ discard block  | 
                                                    ||
| 129 | 129 | public static function rsort(FilterContextInterface $context): ?array  | 
                                                        
| 130 | 130 |      { | 
                                                        
| 131 | 131 | $source = $context->getSource();  | 
                                                        
| 132 | -        if($source === null) { | 
                                                        |
| 132 | +        if ($source === null) { | 
                                                        |
| 133 | 133 | return null;  | 
                                                        
| 134 | 134 | }  | 
                                                        
| 135 | 135 | |
@@ -140,7 +140,7 @@ discard block  | 
                                                    ||
| 140 | 140 | public static function path(FilterContextInterface $context)  | 
                                                        
| 141 | 141 |      { | 
                                                        
| 142 | 142 | $source = $context->getSource();  | 
                                                        
| 143 | -        if($source === null) { | 
                                                        |
| 143 | +        if ($source === null) { | 
                                                        |
| 144 | 144 | return null;  | 
                                                        
| 145 | 145 | }  | 
                                                        
| 146 | 146 | return $context->getSchemator()->getValue($context->getRootSource(), $source);  | 
                                                        
@@ -149,7 +149,7 @@ discard block  | 
                                                    ||
| 149 | 149 | public static function flatten(FilterContextInterface $context): ?array  | 
                                                        
| 150 | 150 |      { | 
                                                        
| 151 | 151 | $source = $context->getSource();  | 
                                                        
| 152 | -        if($source === null) { | 
                                                        |
| 152 | +        if ($source === null) { | 
                                                        |
| 153 | 153 | return null;  | 
                                                        
| 154 | 154 | }  | 
                                                        
| 155 | 155 | return ArrHelper::flatten($source);  | 
                                                        
@@ -158,33 +158,33 @@ discard block  | 
                                                    ||
| 158 | 158 | public static function replace(FilterContextInterface $context, array $rules)  | 
                                                        
| 159 | 159 |      { | 
                                                        
| 160 | 160 | $source = $context->getSource();  | 
                                                        
| 161 | -        if($source === null) { | 
                                                        |
| 161 | +        if ($source === null) { | 
                                                        |
| 162 | 162 | return null;  | 
                                                        
| 163 | 163 | }  | 
                                                        
| 164 | 164 | |
| 165 | 165 | $isArray = is_array($source);  | 
                                                        
| 166 | 166 | |
| 167 | -        if(!$isArray) { | 
                                                        |
| 167 | +        if (!$isArray) { | 
                                                        |
| 168 | 168 | $source = [$source];  | 
                                                        
| 169 | 169 | }  | 
                                                        
| 170 | 170 | |
| 171 | 171 | $result = [];  | 
                                                        
| 172 | 172 | |
| 173 | -        foreach($source as $item) { | 
                                                        |
| 173 | +        foreach ($source as $item) { | 
                                                        |
| 174 | 174 | $isReplaced = false;  | 
                                                        
| 175 | 175 | $elseValue = $item;  | 
                                                        
| 176 | 176 | |
| 177 | -            foreach($rules as $args) { | 
                                                        |
| 177 | +            foreach ($rules as $args) { | 
                                                        |
| 178 | 178 | $value = array_shift($args);  | 
                                                        
| 179 | 179 | $rule = array_shift($args);  | 
                                                        
| 180 | 180 | |
| 181 | -                if($rule === 'else') { | 
                                                        |
| 181 | +                if ($rule === 'else') { | 
                                                        |
| 182 | 182 | $elseValue = $value;  | 
                                                        
| 183 | 183 | }  | 
                                                        
| 184 | 184 | |
| 185 | 185 | $replace = null;  | 
                                                        
| 186 | 186 | |
| 187 | -                if(RuleHelper::check($item, $rule, $args)) { | 
                                                        |
| 187 | +                if (RuleHelper::check($item, $rule, $args)) { | 
                                                        |
| 188 | 188 | $replace = $value;  | 
                                                        
| 189 | 189 | $isReplaced = true;  | 
                                                        
| 190 | 190 | |
@@ -193,12 +193,12 @@ discard block  | 
                                                    ||
| 193 | 193 | }  | 
                                                        
| 194 | 194 | }  | 
                                                        
| 195 | 195 | |
| 196 | -            if(!$isReplaced) { | 
                                                        |
| 196 | +            if (!$isReplaced) { | 
                                                        |
| 197 | 197 | $result[] = $elseValue;  | 
                                                        
| 198 | 198 | }  | 
                                                        
| 199 | 199 | }  | 
                                                        
| 200 | 200 | |
| 201 | -        if(!$isArray) { | 
                                                        |
| 201 | +        if (!$isArray) { | 
                                                        |
| 202 | 202 | $result = $result[0];  | 
                                                        
| 203 | 203 | }  | 
                                                        
| 204 | 204 | |
@@ -53,9 +53,9 @@ discard block  | 
                                                    ||
| 53 | 53 |      { | 
                                                        
| 54 | 54 | $toAccessor = $this->nestedAccessorFactory->create($result, $this->pathDelimiter);  | 
                                                        
| 55 | 55 | |
| 56 | -        foreach($schema as $keyTo => $keyFrom) { | 
                                                        |
| 56 | +        foreach ($schema as $keyTo => $keyFrom) { | 
                                                        |
| 57 | 57 | $value = $this->getValue($source, $keyFrom, $strict);  | 
                                                        
| 58 | -            if($keyTo === '') { | 
                                                        |
| 58 | +            if ($keyTo === '') { | 
                                                        |
| 59 | 59 | return $value;  | 
                                                        
| 60 | 60 | }  | 
                                                        
| 61 | 61 | $toAccessor->set($keyTo, $value, $strict);  | 
                                                        
@@ -74,19 +74,19 @@ discard block  | 
                                                    ||
| 74 | 74 | */  | 
                                                        
| 75 | 75 | public function getValue($source, $key, bool $strict = false)  | 
                                                        
| 76 | 76 |      { | 
                                                        
| 77 | -        if($key === '' || $key === null) { | 
                                                        |
| 77 | +        if ($key === '' || $key === null) { | 
                                                        |
| 78 | 78 | return $source;  | 
                                                        
| 79 | 79 | }  | 
                                                        
| 80 | 80 | |
| 81 | -        if($source === null || (!is_array($source) && !is_object($source))) { | 
                                                        |
| 81 | +        if ($source === null || (!is_array($source) && !is_object($source))) { | 
                                                        |
| 82 | 82 | return $this->getValueFromUnsupportedSource($source, $key, $strict);  | 
                                                        
| 83 | 83 | }  | 
                                                        
| 84 | 84 | |
| 85 | -        if(is_string($key)) { | 
                                                        |
| 85 | +        if (is_string($key)) { | 
                                                        |
| 86 | 86 | return $this->getValueByKey($source, $key, $strict);  | 
                                                        
| 87 | 87 | }  | 
                                                        
| 88 | 88 | |
| 89 | -        if(is_array($key)) { | 
                                                        |
| 89 | +        if (is_array($key)) { | 
                                                        |
| 90 | 90 | return $this->getValueByFilters($source, $key, $strict);  | 
                                                        
| 91 | 91 | }  | 
                                                        
| 92 | 92 | |
@@ -118,7 +118,7 @@ discard block  | 
                                                    ||
| 118 | 118 |          try { | 
                                                        
| 119 | 119 | $fromAccessor = $this->nestedAccessorFactory->create($source, $this->pathDelimiter);  | 
                                                        
| 120 | 120 | return $fromAccessor->get($key, $strict);  | 
                                                        
| 121 | -        } catch(NestedAccessorException $e) { | 
                                                        |
| 121 | +        } catch (NestedAccessorException $e) { | 
                                                        |
| 122 | 122 | throw SchematorException::createAsCannotGetValue($source, $key, $e);  | 
                                                        
| 123 | 123 | }  | 
                                                        
| 124 | 124 | }  | 
                                                        
@@ -134,13 +134,13 @@ discard block  | 
                                                    ||
| 134 | 134 | protected function getValueByFilters(array $source, array $filters, bool $strict)  | 
                                                        
| 135 | 135 |      { | 
                                                        
| 136 | 136 | $result = $source;  | 
                                                        
| 137 | -        foreach($filters as $filterConfig) { | 
                                                        |
| 138 | -            if(is_string($filterConfig)) { | 
                                                        |
| 137 | +        foreach ($filters as $filterConfig) { | 
                                                        |
| 138 | +            if (is_string($filterConfig)) { | 
                                                        |
| 139 | 139 | $result = $this->getValue($result, $filterConfig, $strict);  | 
                                                        
| 140 | -            } elseif(is_array($filterConfig)) { | 
                                                        |
| 140 | +            } elseif (is_array($filterConfig)) { | 
                                                        |
| 141 | 141 | $result = $this->runFilter($filterConfig, $result, $source, $strict);  | 
                                                        
| 142 | 142 |              } else { | 
                                                        
| 143 | -                if($strict) { | 
                                                        |
| 143 | +                if ($strict) { | 
                                                        |
| 144 | 144 | throw SchematorException::createAsUnsupportedFilterConfigType($filterConfig);  | 
                                                        
| 145 | 145 | }  | 
                                                        
| 146 | 146 | $result = null;  | 
                                                        
@@ -160,7 +160,7 @@ discard block  | 
                                                    ||
| 160 | 160 | */  | 
                                                        
| 161 | 161 | protected function getValueFromUnsupportedSource($source, $key, bool $strict)  | 
                                                        
| 162 | 162 |      { | 
                                                        
| 163 | -        if(!$strict) { | 
                                                        |
| 163 | +        if (!$strict) { | 
                                                        |
| 164 | 164 | return null;  | 
                                                        
| 165 | 165 | }  | 
                                                        
| 166 | 166 | throw SchematorException::createAsUnsupportedSourceType($source, $key);  | 
                                                        
@@ -176,7 +176,7 @@ discard block  | 
                                                    ||
| 176 | 176 | */  | 
                                                        
| 177 | 177 | protected function getValueByUnsupportedKey($source, $key, bool $strict)  | 
                                                        
| 178 | 178 |      { | 
                                                        
| 179 | -        if(!$strict) { | 
                                                        |
| 179 | +        if (!$strict) { | 
                                                        |
| 180 | 180 | return null;  | 
                                                        
| 181 | 181 | }  | 
                                                        
| 182 | 182 | throw SchematorException::createAsUnsupportedKeyType($source, $key);  | 
                                                        
@@ -202,8 +202,8 @@ discard block  | 
                                                    ||
| 202 | 202 | new FilterContext($this, $source, $rootSource),  | 
                                                        
| 203 | 203 | ...$filterConfig  | 
                                                        
| 204 | 204 | );  | 
                                                        
| 205 | -        } catch(Throwable $e) { | 
                                                        |
| 206 | -            if($strict) { | 
                                                        |
| 205 | +        } catch (Throwable $e) { | 
                                                        |
| 206 | +            if ($strict) { | 
                                                        |
| 207 | 207 | throw SchematorException::createAsFilterError($filterName, $filterConfig, $source, $e);  | 
                                                        
| 208 | 208 | }  | 
                                                        
| 209 | 209 | return null;  |