@@ -23,7 +23,7 @@ |
||
| 23 | 23 | |
| 24 | 24 | public function withFilters(array $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; |
@@ -25,11 +25,11 @@ |
||
| 25 | 25 | { |
| 26 | 26 | $builder = static::createBuilder(); |
| 27 | 27 | |
| 28 | - if($withBaseFilters) { |
|
| 28 | + if ($withBaseFilters) { |
|
| 29 | 29 | $builder->withFilters(BaseFilters::get()); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | - if(count($extraFilters)) { |
|
| 32 | + if (count($extraFilters)) { |
|
| 33 | 33 | $builder->withFilters($extraFilters); |
| 34 | 34 | } |
| 35 | 35 | |
@@ -39,10 +39,10 @@ discard block |
||
| 39 | 39 | string $format, |
| 40 | 40 | ?int $timezone = null |
| 41 | 41 | ) { |
| 42 | - if($source === null) { |
|
| 42 | + if ($source === null) { |
|
| 43 | 43 | return null; |
| 44 | 44 | } |
| 45 | - if($timezone === null) { |
|
| 45 | + if ($timezone === null) { |
|
| 46 | 46 | return date($format, $source); |
| 47 | 47 | } |
| 48 | 48 | return gmdate($format, $source+3600*$timezone); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | array $rootSource, |
| 54 | 54 | string $delimiter = ', ' |
| 55 | 55 | ) { |
| 56 | - if($source === null) { |
|
| 56 | + if ($source === null) { |
|
| 57 | 57 | return null; |
| 58 | 58 | } |
| 59 | 59 | return implode($delimiter, $source); |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | array $rootSource, |
| 65 | 65 | string $delimiter = ', ' |
| 66 | 66 | ) { |
| 67 | - if($source === null) { |
|
| 67 | + if ($source === null) { |
|
| 68 | 68 | return null; |
| 69 | 69 | } |
| 70 | 70 | return explode($delimiter, $source); |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | Schemator $schemator, |
| 74 | 74 | ?array $source |
| 75 | 75 | ) { |
| 76 | - if($source === null) { |
|
| 76 | + if ($source === null) { |
|
| 77 | 77 | return null; |
| 78 | 78 | } |
| 79 | 79 | return array_sum($source); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | Schemator $schemator, |
| 83 | 83 | ?array $source |
| 84 | 84 | ) { |
| 85 | - if($source === null) { |
|
| 85 | + if ($source === null) { |
|
| 86 | 86 | return null; |
| 87 | 87 | } |
| 88 | 88 | return array_sum($source)/count($source); |
@@ -93,21 +93,21 @@ discard block |
||
| 93 | 93 | array $rootSource, |
| 94 | 94 | $filterConfig |
| 95 | 95 | ) { |
| 96 | - if($source === null) { |
|
| 96 | + if ($source === null) { |
|
| 97 | 97 | return null; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - if(is_callable($filterConfig)) { |
|
| 100 | + if (is_callable($filterConfig)) { |
|
| 101 | 101 | return array_values(array_filter($source, $filterConfig)); |
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $result = []; |
| 105 | 105 | |
| 106 | - foreach($source as $item) { |
|
| 107 | - foreach($filterConfig as $args) { |
|
| 106 | + foreach ($source as $item) { |
|
| 107 | + foreach ($filterConfig as $args) { |
|
| 108 | 108 | $rule = array_shift($args); |
| 109 | 109 | |
| 110 | - if(RuleHelper::check($item, $rule, $args)) { |
|
| 110 | + if (RuleHelper::check($item, $rule, $args)) { |
|
| 111 | 111 | $result[] = $item; |
| 112 | 112 | break; |
| 113 | 113 | } |
@@ -122,10 +122,10 @@ discard block |
||
| 122 | 122 | array $rootSource, |
| 123 | 123 | ?callable $sortCallback = null |
| 124 | 124 | ) { |
| 125 | - if($source === null) { |
|
| 125 | + if ($source === null) { |
|
| 126 | 126 | return null; |
| 127 | 127 | } |
| 128 | - if($sortCallback !== null) { |
|
| 128 | + if ($sortCallback !== null) { |
|
| 129 | 129 | usort($source, $sortCallback); |
| 130 | 130 | } else { |
| 131 | 131 | sort($source); |
@@ -136,7 +136,7 @@ discard block |
||
| 136 | 136 | Schemator $schemator, |
| 137 | 137 | ?array $source |
| 138 | 138 | ) { |
| 139 | - if($source === null) { |
|
| 139 | + if ($source === null) { |
|
| 140 | 140 | return null; |
| 141 | 141 | } |
| 142 | 142 | |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | ?string $source, |
| 149 | 149 | array $rootSource |
| 150 | 150 | ) { |
| 151 | - if($source === null) { |
|
| 151 | + if ($source === null) { |
|
| 152 | 152 | return null; |
| 153 | 153 | } |
| 154 | 154 | return $schemator->getValue($rootSource, $source); |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | Schemator $schemator, |
| 158 | 158 | ?array $source |
| 159 | 159 | ) { |
| 160 | - if($source === null) { |
|
| 160 | + if ($source === null) { |
|
| 161 | 161 | return null; |
| 162 | 162 | } |
| 163 | 163 | return ArrHelper::flatten($source); |
@@ -168,33 +168,33 @@ discard block |
||
| 168 | 168 | array $rootSource, |
| 169 | 169 | array $rules |
| 170 | 170 | ) { |
| 171 | - if($source === null) { |
|
| 171 | + if ($source === null) { |
|
| 172 | 172 | return null; |
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | $isArray = is_array($source); |
| 176 | 176 | |
| 177 | - if(!$isArray) { |
|
| 177 | + if (!$isArray) { |
|
| 178 | 178 | $source = [$source]; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | $result = []; |
| 182 | 182 | |
| 183 | - foreach($source as $item) { |
|
| 183 | + foreach ($source as $item) { |
|
| 184 | 184 | $isReplaced = false; |
| 185 | 185 | $elseValue = $item; |
| 186 | 186 | |
| 187 | - foreach($rules as $args) { |
|
| 187 | + foreach ($rules as $args) { |
|
| 188 | 188 | $value = array_shift($args); |
| 189 | 189 | $rule = array_shift($args); |
| 190 | 190 | |
| 191 | - if($rule === 'else') { |
|
| 191 | + if ($rule === 'else') { |
|
| 192 | 192 | $elseValue = $value; |
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | $replace = null; |
| 196 | 196 | |
| 197 | - if(RuleHelper::check($item, $rule, $args)) { |
|
| 197 | + if (RuleHelper::check($item, $rule, $args)) { |
|
| 198 | 198 | $replace = $value; |
| 199 | 199 | $isReplaced = true; |
| 200 | 200 | |
@@ -203,12 +203,12 @@ discard block |
||
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - if(!$isReplaced) { |
|
| 206 | + if (!$isReplaced) { |
|
| 207 | 207 | $result[] = $elseValue; |
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | - if(!$isArray) { |
|
| 211 | + if (!$isArray) { |
|
| 212 | 212 | $result = $result[0]; |
| 213 | 213 | } |
| 214 | 214 | |