@@ -70,18 +70,18 @@ discard block |
||
| 70 | 70 | protected function buildMap(ReflectionEntity $filter): array |
| 71 | 71 | { |
| 72 | 72 | $schema = $filter->getProperty('schema', true); |
| 73 | - if (empty($schema)) { |
|
| 73 | + if (empty($schema)){ |
|
| 74 | 74 | throw new SchemaException("Filter `{$filter->getName()}` does not define any schema"); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | $result = []; |
| 78 | - foreach ($schema as $field => $definition) { |
|
| 78 | + foreach ($schema as $field => $definition){ |
|
| 79 | 79 | $optional = false; |
| 80 | 80 | |
| 81 | 81 | // short definition |
| 82 | - if (is_string($definition)) { |
|
| 82 | + if (is_string($definition)){ |
|
| 83 | 83 | // simple scalar field definition |
| 84 | - if (!class_exists($definition)) { |
|
| 84 | + if (!class_exists($definition)){ |
|
| 85 | 85 | [$source, $origin] = $this->parseDefinition($field, $definition); |
| 86 | 86 | $result[$field] = [ |
| 87 | 87 | FilterProvider::SOURCE => $source, |
@@ -102,25 +102,25 @@ discard block |
||
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if (!is_array($definition) || count($definition) === 0) { |
|
| 105 | + if (!is_array($definition) || count($definition) === 0){ |
|
| 106 | 106 | throw new SchemaException( |
| 107 | 107 | "Invalid schema definition at `{$filter->getName()}`->`{$field}`" |
| 108 | 108 | ); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // complex definition |
| 112 | - if (!empty($definition[self::ORIGIN])) { |
|
| 112 | + if (!empty($definition[self::ORIGIN])){ |
|
| 113 | 113 | $origin = $definition[self::ORIGIN]; |
| 114 | 114 | |
| 115 | 115 | // [class, 'data:something.*'] vs [class, 'data:something'] |
| 116 | 116 | $iterate = strpos($origin, '.*') !== false || !empty($definition[self::ITERATE]); |
| 117 | 117 | $origin = rtrim($origin, '.*'); |
| 118 | - } else { |
|
| 118 | + }else{ |
|
| 119 | 119 | $origin = $field; |
| 120 | 120 | $iterate = true; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - if (!empty($definition[self::OPTIONAL]) && $definition[self::OPTIONAL]) { |
|
| 123 | + if (!empty($definition[self::OPTIONAL]) && $definition[self::OPTIONAL]){ |
|
| 124 | 124 | $optional = true; |
| 125 | 125 | } |
| 126 | 126 | |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | FilterProvider::OPTIONAL => $optional, |
| 134 | 134 | ]; |
| 135 | 135 | |
| 136 | - if ($iterate) { |
|
| 136 | + if ($iterate){ |
|
| 137 | 137 | [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin); |
| 138 | 138 | |
| 139 | 139 | $map[FilterProvider::ITERATE_SOURCE] = $source; |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | private function parseDefinition(string $field, string $definition): array |
| 161 | 161 | { |
| 162 | - if (strpos($definition, ':') === false) { |
|
| 162 | + if (strpos($definition, ':') === false){ |
|
| 163 | 163 | return ['data', $definition ?? $field]; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -70,18 +70,22 @@ discard block |
||
| 70 | 70 | protected function buildMap(ReflectionEntity $filter): array |
| 71 | 71 | { |
| 72 | 72 | $schema = $filter->getProperty('schema', true); |
| 73 | - if (empty($schema)) { |
|
| 73 | + if (empty($schema)) |
|
| 74 | + { |
|
| 74 | 75 | throw new SchemaException("Filter `{$filter->getName()}` does not define any schema"); |
| 75 | 76 | } |
| 76 | 77 | |
| 77 | 78 | $result = []; |
| 78 | - foreach ($schema as $field => $definition) { |
|
| 79 | + foreach ($schema as $field => $definition) |
|
| 80 | + { |
|
| 79 | 81 | $optional = false; |
| 80 | 82 | |
| 81 | 83 | // short definition |
| 82 | - if (is_string($definition)) { |
|
| 84 | + if (is_string($definition)) |
|
| 85 | + { |
|
| 83 | 86 | // simple scalar field definition |
| 84 | - if (!class_exists($definition)) { |
|
| 87 | + if (!class_exists($definition)) |
|
| 88 | + { |
|
| 85 | 89 | [$source, $origin] = $this->parseDefinition($field, $definition); |
| 86 | 90 | $result[$field] = [ |
| 87 | 91 | FilterProvider::SOURCE => $source, |
@@ -102,25 +106,30 @@ discard block |
||
| 102 | 106 | continue; |
| 103 | 107 | } |
| 104 | 108 | |
| 105 | - if (!is_array($definition) || count($definition) === 0) { |
|
| 109 | + if (!is_array($definition) || count($definition) === 0) |
|
| 110 | + { |
|
| 106 | 111 | throw new SchemaException( |
| 107 | 112 | "Invalid schema definition at `{$filter->getName()}`->`{$field}`" |
| 108 | 113 | ); |
| 109 | 114 | } |
| 110 | 115 | |
| 111 | 116 | // complex definition |
| 112 | - if (!empty($definition[self::ORIGIN])) { |
|
| 117 | + if (!empty($definition[self::ORIGIN])) |
|
| 118 | + { |
|
| 113 | 119 | $origin = $definition[self::ORIGIN]; |
| 114 | 120 | |
| 115 | 121 | // [class, 'data:something.*'] vs [class, 'data:something'] |
| 116 | 122 | $iterate = strpos($origin, '.*') !== false || !empty($definition[self::ITERATE]); |
| 117 | 123 | $origin = rtrim($origin, '.*'); |
| 118 | - } else { |
|
| 124 | + } |
|
| 125 | + else |
|
| 126 | + { |
|
| 119 | 127 | $origin = $field; |
| 120 | 128 | $iterate = true; |
| 121 | 129 | } |
| 122 | 130 | |
| 123 | - if (!empty($definition[self::OPTIONAL]) && $definition[self::OPTIONAL]) { |
|
| 131 | + if (!empty($definition[self::OPTIONAL]) && $definition[self::OPTIONAL]) |
|
| 132 | + { |
|
| 124 | 133 | $optional = true; |
| 125 | 134 | } |
| 126 | 135 | |
@@ -133,7 +142,8 @@ discard block |
||
| 133 | 142 | FilterProvider::OPTIONAL => $optional, |
| 134 | 143 | ]; |
| 135 | 144 | |
| 136 | - if ($iterate) { |
|
| 145 | + if ($iterate) |
|
| 146 | + { |
|
| 137 | 147 | [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin); |
| 138 | 148 | |
| 139 | 149 | $map[FilterProvider::ITERATE_SOURCE] = $source; |
@@ -159,7 +169,8 @@ discard block |
||
| 159 | 169 | */ |
| 160 | 170 | private function parseDefinition(string $field, string $definition): array |
| 161 | 171 | { |
| 162 | - if (strpos($definition, ':') === false) { |
|
| 172 | + if (strpos($definition, ':') === false) |
|
| 173 | + { |
|
| 163 | 174 | return ['data', $definition ?? $field]; |
| 164 | 175 | } |
| 165 | 176 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | FilterProvider::SOURCE => null, |
| 96 | 96 | FilterProvider::ORIGIN => $field, |
| 97 | 97 | FilterProvider::FILTER => $definition, |
| 98 | - FilterProvider::ARRAY => false, |
|
| 98 | + FilterProvider::array => false, |
|
| 99 | 99 | FilterProvider::OPTIONAL => $optional, |
| 100 | 100 | ]; |
| 101 | 101 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | FilterProvider::FILTER => $definition[self::NESTED], |
| 130 | 130 | FilterProvider::SOURCE => null, |
| 131 | 131 | FilterProvider::ORIGIN => $origin, |
| 132 | - FilterProvider::ARRAY => $iterate, |
|
| 132 | + FilterProvider::array => $iterate, |
|
| 133 | 133 | FilterProvider::OPTIONAL => $optional, |
| 134 | 134 | ]; |
| 135 | 135 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | public const SOURCE = 'source'; |
| 34 | 34 | public const ORIGIN = 'origin'; |
| 35 | 35 | public const FILTER = 'filter'; |
| 36 | - public const ARRAY = 'array'; |
|
| 36 | + public const array = 'array'; |
|
| 37 | 37 | public const OPTIONAL = 'optional'; |
| 38 | 38 | public const ITERATE_SOURCE = 'iterate_source'; |
| 39 | 39 | public const ITERATE_ORIGIN = 'iterate_origin'; |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | $nested = $map[self::FILTER]; |
| 106 | - if (empty($map[self::ARRAY])) { |
|
| 106 | + if (empty($map[self::array])) { |
|
| 107 | 107 | // slicing down |
| 108 | 108 | $result[$field] = $this->createFilter($nested, $input->withPrefix($map[self::ORIGIN])); |
| 109 | 109 | continue; |
@@ -86,18 +86,18 @@ discard block |
||
| 86 | 86 | public function initValues(array $mappingSchema, InputInterface $input): array |
| 87 | 87 | { |
| 88 | 88 | $result = []; |
| 89 | - foreach ($mappingSchema as $field => $map) { |
|
| 90 | - if (empty($map[self::FILTER])) { |
|
| 89 | + foreach ($mappingSchema as $field => $map){ |
|
| 90 | + if (empty($map[self::FILTER])){ |
|
| 91 | 91 | $value = $input->getValue($map[self::SOURCE], $map[self::ORIGIN]); |
| 92 | 92 | |
| 93 | - if ($value !== null) { |
|
| 93 | + if ($value !== null){ |
|
| 94 | 94 | $result[$field] = $value; |
| 95 | 95 | } |
| 96 | 96 | continue; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | $nested = $map[self::FILTER]; |
| 100 | - if (empty($map[self::ARRAY])) { |
|
| 100 | + if (empty($map[self::ARRAY])){ |
|
| 101 | 101 | // slicing down |
| 102 | 102 | $result[$field] = $this->createFilter($nested, $input->withPrefix($map[self::ORIGIN])); |
| 103 | 103 | continue; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $values = []; |
| 107 | 107 | |
| 108 | 108 | // List of "key" => "location in request" |
| 109 | - foreach ($this->iterate($map, $input) as $index => $origin) { |
|
| 109 | + foreach ($this->iterate($map, $input) as $index => $origin){ |
|
| 110 | 110 | $values[$index] = $this->createFilter($nested, $input->withPrefix($origin)); |
| 111 | 111 | } |
| 112 | 112 | |
@@ -122,18 +122,18 @@ discard block |
||
| 122 | 122 | private function iterate(array $schema, InputInterface $input): Generator |
| 123 | 123 | { |
| 124 | 124 | $values = $input->getValue($schema[self::ITERATE_SOURCE], $schema[self::ITERATE_ORIGIN]); |
| 125 | - if (empty($values) || !is_array($values)) { |
|
| 125 | + if (empty($values) || !is_array($values)){ |
|
| 126 | 126 | return []; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - foreach (array_keys($values) as $key) { |
|
| 130 | - yield $key => $schema[self::ORIGIN] . '.' . $key; |
|
| 129 | + foreach (array_keys($values) as $key){ |
|
| 130 | + yield $key => $schema[self::ORIGIN].'.'.$key; |
|
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | private function getErrorMapper(string $filter): ErrorMapper |
| 135 | 135 | { |
| 136 | - if (isset($this->errorMappers[$filter])) { |
|
| 136 | + if (isset($this->errorMappers[$filter])){ |
|
| 137 | 137 | return $this->errorMappers[$filter]; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | |
| 146 | 146 | private function getValidator(string $filter): ValidatorInterface |
| 147 | 147 | { |
| 148 | - if (isset($this->validators[$filter])) { |
|
| 148 | + if (isset($this->validators[$filter])){ |
|
| 149 | 149 | return $this->validators[$filter]; |
| 150 | 150 | } |
| 151 | 151 | |
@@ -161,18 +161,18 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | private function getSchema(string $filter): array |
| 163 | 163 | { |
| 164 | - if (isset($this->cache[$filter])) { |
|
| 164 | + if (isset($this->cache[$filter])){ |
|
| 165 | 165 | return $this->cache[$filter]; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - try { |
|
| 168 | + try{ |
|
| 169 | 169 | $reflection = new ReflectionEntity($filter); |
| 170 | - if (!$reflection->getReflection()->isSubclassOf(Filter::class)) { |
|
| 170 | + if (!$reflection->getReflection()->isSubclassOf(Filter::class)){ |
|
| 171 | 171 | throw new SchemaException('Invalid filter class, must be subclass of Filter'); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | $builder = new SchemaBuilder(new ReflectionEntity($filter)); |
| 175 | - } catch (ReflectionException $e) { |
|
| 175 | + }catch (ReflectionException $e){ |
|
| 176 | 176 | throw new SchemaException('Invalid filter schema', $e->getCode(), $e); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -86,18 +86,22 @@ discard block |
||
| 86 | 86 | public function initValues(array $mappingSchema, InputInterface $input): array |
| 87 | 87 | { |
| 88 | 88 | $result = []; |
| 89 | - foreach ($mappingSchema as $field => $map) { |
|
| 90 | - if (empty($map[self::FILTER])) { |
|
| 89 | + foreach ($mappingSchema as $field => $map) |
|
| 90 | + { |
|
| 91 | + if (empty($map[self::FILTER])) |
|
| 92 | + { |
|
| 91 | 93 | $value = $input->getValue($map[self::SOURCE], $map[self::ORIGIN]); |
| 92 | 94 | |
| 93 | - if ($value !== null) { |
|
| 95 | + if ($value !== null) |
|
| 96 | + { |
|
| 94 | 97 | $result[$field] = $value; |
| 95 | 98 | } |
| 96 | 99 | continue; |
| 97 | 100 | } |
| 98 | 101 | |
| 99 | 102 | $nested = $map[self::FILTER]; |
| 100 | - if (empty($map[self::ARRAY])) { |
|
| 103 | + if (empty($map[self::ARRAY])) |
|
| 104 | + { |
|
| 101 | 105 | // slicing down |
| 102 | 106 | $result[$field] = $this->createFilter($nested, $input->withPrefix($map[self::ORIGIN])); |
| 103 | 107 | continue; |
@@ -106,7 +110,8 @@ discard block |
||
| 106 | 110 | $values = []; |
| 107 | 111 | |
| 108 | 112 | // List of "key" => "location in request" |
| 109 | - foreach ($this->iterate($map, $input) as $index => $origin) { |
|
| 113 | + foreach ($this->iterate($map, $input) as $index => $origin) |
|
| 114 | + { |
|
| 110 | 115 | $values[$index] = $this->createFilter($nested, $input->withPrefix($origin)); |
| 111 | 116 | } |
| 112 | 117 | |
@@ -122,18 +127,21 @@ discard block |
||
| 122 | 127 | private function iterate(array $schema, InputInterface $input): Generator |
| 123 | 128 | { |
| 124 | 129 | $values = $input->getValue($schema[self::ITERATE_SOURCE], $schema[self::ITERATE_ORIGIN]); |
| 125 | - if (empty($values) || !is_array($values)) { |
|
| 130 | + if (empty($values) || !is_array($values)) |
|
| 131 | + { |
|
| 126 | 132 | return []; |
| 127 | 133 | } |
| 128 | 134 | |
| 129 | - foreach (array_keys($values) as $key) { |
|
| 135 | + foreach (array_keys($values) as $key) |
|
| 136 | + { |
|
| 130 | 137 | yield $key => $schema[self::ORIGIN] . '.' . $key; |
| 131 | 138 | } |
| 132 | 139 | } |
| 133 | 140 | |
| 134 | 141 | private function getErrorMapper(string $filter): ErrorMapper |
| 135 | 142 | { |
| 136 | - if (isset($this->errorMappers[$filter])) { |
|
| 143 | + if (isset($this->errorMappers[$filter])) |
|
| 144 | + { |
|
| 137 | 145 | return $this->errorMappers[$filter]; |
| 138 | 146 | } |
| 139 | 147 | |
@@ -145,7 +153,8 @@ discard block |
||
| 145 | 153 | |
| 146 | 154 | private function getValidator(string $filter): ValidatorInterface |
| 147 | 155 | { |
| 148 | - if (isset($this->validators[$filter])) { |
|
| 156 | + if (isset($this->validators[$filter])) |
|
| 157 | + { |
|
| 149 | 158 | return $this->validators[$filter]; |
| 150 | 159 | } |
| 151 | 160 | |
@@ -161,18 +170,23 @@ discard block |
||
| 161 | 170 | */ |
| 162 | 171 | private function getSchema(string $filter): array |
| 163 | 172 | { |
| 164 | - if (isset($this->cache[$filter])) { |
|
| 173 | + if (isset($this->cache[$filter])) |
|
| 174 | + { |
|
| 165 | 175 | return $this->cache[$filter]; |
| 166 | 176 | } |
| 167 | 177 | |
| 168 | - try { |
|
| 178 | + try |
|
| 179 | + { |
|
| 169 | 180 | $reflection = new ReflectionEntity($filter); |
| 170 | - if (!$reflection->getReflection()->isSubclassOf(Filter::class)) { |
|
| 181 | + if (!$reflection->getReflection()->isSubclassOf(Filter::class)) |
|
| 182 | + { |
|
| 171 | 183 | throw new SchemaException('Invalid filter class, must be subclass of Filter'); |
| 172 | 184 | } |
| 173 | 185 | |
| 174 | 186 | $builder = new SchemaBuilder(new ReflectionEntity($filter)); |
| 175 | - } catch (ReflectionException $e) { |
|
| 187 | + } |
|
| 188 | + catch (ReflectionException $e) |
|
| 189 | + { |
|
| 176 | 190 | throw new SchemaException('Invalid filter schema', $e->getCode(), $e); |
| 177 | 191 | } |
| 178 | 192 | |
@@ -63,8 +63,8 @@ |
||
| 63 | 63 | #[\ReturnTypeWillChange] |
| 64 | 64 | public function gc($maxlifetime) |
| 65 | 65 | { |
| 66 | - foreach ($this->files->getFiles($this->directory) as $filename) { |
|
| 67 | - if ($this->files->time($filename) < time() - $maxlifetime) { |
|
| 66 | + foreach ($this->files->getFiles($this->directory) as $filename){ |
|
| 67 | + if ($this->files->time($filename) < time() - $maxlifetime){ |
|
| 68 | 68 | $this->files->delete($filename); |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -63,8 +63,10 @@ |
||
| 63 | 63 | #[\ReturnTypeWillChange] |
| 64 | 64 | public function gc($maxlifetime) |
| 65 | 65 | { |
| 66 | - foreach ($this->files->getFiles($this->directory) as $filename) { |
|
| 67 | - if ($this->files->time($filename) < time() - $maxlifetime) { |
|
| 66 | + foreach ($this->files->getFiles($this->directory) as $filename) |
|
| 67 | + { |
|
| 68 | + if ($this->files->time($filename) < time() - $maxlifetime) |
|
| 69 | + { |
|
| 68 | 70 | $this->files->delete($filename); |
| 69 | 71 | } |
| 70 | 72 | } |
@@ -72,7 +72,7 @@ |
||
| 72 | 72 | #[\ReturnTypeWillChange] |
| 73 | 73 | public function offsetGet($offset) |
| 74 | 74 | { |
| 75 | - if (!$this->offsetExists($offset)) { |
|
| 75 | + if (!$this->offsetExists($offset)){ |
|
| 76 | 76 | throw new ConfigException("Undefined configuration key '{$offset}'"); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -72,7 +72,8 @@ |
||
| 72 | 72 | #[\ReturnTypeWillChange] |
| 73 | 73 | public function offsetGet($offset) |
| 74 | 74 | { |
| 75 | - if (!$this->offsetExists($offset)) { |
|
| 75 | + if (!$this->offsetExists($offset)) |
|
| 76 | + { |
|
| 76 | 77 | throw new ConfigException("Undefined configuration key '{$offset}'"); |
| 77 | 78 | } |
| 78 | 79 | |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function getIterator(): \Traversable |
| 48 | 48 | { |
| 49 | - while ($n = $this->next()) { |
|
| 49 | + while ($n = $this->next()){ |
|
| 50 | 50 | yield $n; |
| 51 | 51 | } |
| 52 | 52 | } |
@@ -64,18 +64,18 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function next() |
| 66 | 66 | { |
| 67 | - if ($this->replay !== []) { |
|
| 67 | + if ($this->replay !== []){ |
|
| 68 | 68 | $n = array_shift($this->replay); |
| 69 | - } else { |
|
| 69 | + }else{ |
|
| 70 | 70 | $n = $this->generator->current(); |
| 71 | - if ($n === null) { |
|
| 71 | + if ($n === null){ |
|
| 72 | 72 | return null; |
| 73 | 73 | } |
| 74 | 74 | $this->generator->next(); |
| 75 | 75 | $this->buffer[] = $n; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - if ($n !== null) { |
|
| 78 | + if ($n !== null){ |
|
| 79 | 79 | $this->offset = $n->offset; |
| 80 | 80 | } |
| 81 | 81 | |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | public function nextBytes(): string |
| 91 | 91 | { |
| 92 | 92 | $result = ''; |
| 93 | - while ($n = $this->next()) { |
|
| 94 | - if ($n instanceof Byte) { |
|
| 93 | + while ($n = $this->next()){ |
|
| 94 | + if ($n instanceof Byte){ |
|
| 95 | 95 | $result .= $n->char; |
| 96 | - } else { |
|
| 96 | + }else{ |
|
| 97 | 97 | break; |
| 98 | 98 | } |
| 99 | 99 | } |
@@ -106,12 +106,12 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | public function lookahead() |
| 108 | 108 | { |
| 109 | - if ($this->replay !== []) { |
|
| 109 | + if ($this->replay !== []){ |
|
| 110 | 110 | return $this->replay[0]; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | $n = $this->next(); |
| 114 | - if ($n !== null) { |
|
| 114 | + if ($n !== null){ |
|
| 115 | 115 | array_unshift($this->replay, $n); |
| 116 | 116 | } |
| 117 | 117 | |
@@ -128,20 +128,20 @@ discard block |
||
| 128 | 128 | { |
| 129 | 129 | $result = ''; |
| 130 | 130 | $replay = []; |
| 131 | - for ($i = 0; $i < $size; $i++) { |
|
| 131 | + for ($i = 0; $i < $size; $i++){ |
|
| 132 | 132 | $n = $this->next(); |
| 133 | - if ($n !== null) { |
|
| 133 | + if ($n !== null){ |
|
| 134 | 134 | $replay[] = $n; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if (!$n instanceof Byte) { |
|
| 137 | + if (!$n instanceof Byte){ |
|
| 138 | 138 | break; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | $result .= $n->char; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - foreach (array_reverse($replay) as $n) { |
|
| 144 | + foreach (array_reverse($replay) as $n){ |
|
| 145 | 145 | array_unshift($this->replay, $n); |
| 146 | 146 | } |
| 147 | 147 | |
@@ -155,8 +155,8 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | public function replay(int $offset): void |
| 157 | 157 | { |
| 158 | - foreach ($this->buffer as $n) { |
|
| 159 | - if ($n->offset > $offset) { |
|
| 158 | + foreach ($this->buffer as $n){ |
|
| 159 | + if ($n->offset > $offset){ |
|
| 160 | 160 | $this->replay[] = $n; |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -46,7 +46,8 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | public function getIterator(): \Traversable |
| 48 | 48 | { |
| 49 | - while ($n = $this->next()) { |
|
| 49 | + while ($n = $this->next()) |
|
| 50 | + { |
|
| 50 | 51 | yield $n; |
| 51 | 52 | } |
| 52 | 53 | } |
@@ -64,18 +65,23 @@ discard block |
||
| 64 | 65 | */ |
| 65 | 66 | public function next() |
| 66 | 67 | { |
| 67 | - if ($this->replay !== []) { |
|
| 68 | + if ($this->replay !== []) |
|
| 69 | + { |
|
| 68 | 70 | $n = array_shift($this->replay); |
| 69 | - } else { |
|
| 71 | + } |
|
| 72 | + else |
|
| 73 | + { |
|
| 70 | 74 | $n = $this->generator->current(); |
| 71 | - if ($n === null) { |
|
| 75 | + if ($n === null) |
|
| 76 | + { |
|
| 72 | 77 | return null; |
| 73 | 78 | } |
| 74 | 79 | $this->generator->next(); |
| 75 | 80 | $this->buffer[] = $n; |
| 76 | 81 | } |
| 77 | 82 | |
| 78 | - if ($n !== null) { |
|
| 83 | + if ($n !== null) |
|
| 84 | + { |
|
| 79 | 85 | $this->offset = $n->offset; |
| 80 | 86 | } |
| 81 | 87 | |
@@ -90,10 +96,14 @@ discard block |
||
| 90 | 96 | public function nextBytes(): string |
| 91 | 97 | { |
| 92 | 98 | $result = ''; |
| 93 | - while ($n = $this->next()) { |
|
| 94 | - if ($n instanceof Byte) { |
|
| 99 | + while ($n = $this->next()) |
|
| 100 | + { |
|
| 101 | + if ($n instanceof Byte) |
|
| 102 | + { |
|
| 95 | 103 | $result .= $n->char; |
| 96 | - } else { |
|
| 104 | + } |
|
| 105 | + else |
|
| 106 | + { |
|
| 97 | 107 | break; |
| 98 | 108 | } |
| 99 | 109 | } |
@@ -106,12 +116,14 @@ discard block |
||
| 106 | 116 | */ |
| 107 | 117 | public function lookahead() |
| 108 | 118 | { |
| 109 | - if ($this->replay !== []) { |
|
| 119 | + if ($this->replay !== []) |
|
| 120 | + { |
|
| 110 | 121 | return $this->replay[0]; |
| 111 | 122 | } |
| 112 | 123 | |
| 113 | 124 | $n = $this->next(); |
| 114 | - if ($n !== null) { |
|
| 125 | + if ($n !== null) |
|
| 126 | + { |
|
| 115 | 127 | array_unshift($this->replay, $n); |
| 116 | 128 | } |
| 117 | 129 | |
@@ -128,20 +140,24 @@ discard block |
||
| 128 | 140 | { |
| 129 | 141 | $result = ''; |
| 130 | 142 | $replay = []; |
| 131 | - for ($i = 0; $i < $size; $i++) { |
|
| 143 | + for ($i = 0; $i < $size; $i++) |
|
| 144 | + { |
|
| 132 | 145 | $n = $this->next(); |
| 133 | - if ($n !== null) { |
|
| 146 | + if ($n !== null) |
|
| 147 | + { |
|
| 134 | 148 | $replay[] = $n; |
| 135 | 149 | } |
| 136 | 150 | |
| 137 | - if (!$n instanceof Byte) { |
|
| 151 | + if (!$n instanceof Byte) |
|
| 152 | + { |
|
| 138 | 153 | break; |
| 139 | 154 | } |
| 140 | 155 | |
| 141 | 156 | $result .= $n->char; |
| 142 | 157 | } |
| 143 | 158 | |
| 144 | - foreach (array_reverse($replay) as $n) { |
|
| 159 | + foreach (array_reverse($replay) as $n) |
|
| 160 | + { |
|
| 145 | 161 | array_unshift($this->replay, $n); |
| 146 | 162 | } |
| 147 | 163 | |
@@ -155,8 +171,10 @@ discard block |
||
| 155 | 171 | */ |
| 156 | 172 | public function replay(int $offset): void |
| 157 | 173 | { |
| 158 | - foreach ($this->buffer as $n) { |
|
| 159 | - if ($n->offset > $offset) { |
|
| 174 | + foreach ($this->buffer as $n) |
|
| 175 | + { |
|
| 176 | + if ($n->offset > $offset) |
|
| 177 | + { |
|
| 160 | 178 | $this->replay[] = $n; |
| 161 | 179 | } |
| 162 | 180 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | array $schema, |
| 91 | 91 | ValidatorInterface $validator, |
| 92 | 92 | ErrorMapper $errorMapper |
| 93 | - ) { |
|
| 93 | + ){ |
|
| 94 | 94 | parent::__construct($data, $schema); |
| 95 | 95 | |
| 96 | 96 | $this->mappings = $schema[FilterProvider::MAPPING] ?? []; |
@@ -151,10 +151,10 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | public function getErrors(): array |
| 153 | 153 | { |
| 154 | - if ($this->errors === null) { |
|
| 154 | + if ($this->errors === null){ |
|
| 155 | 155 | $this->errors = []; |
| 156 | - foreach ($this->validator->withData($this)->getErrors() as $field => $error) { |
|
| 157 | - if (is_string($error) && Translator::isMessage($error)) { |
|
| 156 | + foreach ($this->validator->withData($this)->getErrors() as $field => $error){ |
|
| 157 | + if (is_string($error) && Translator::isMessage($error)){ |
|
| 158 | 158 | // translate error message |
| 159 | 159 | $error = $this->say($error); |
| 160 | 160 | } |
@@ -195,32 +195,32 @@ discard block |
||
| 195 | 195 | */ |
| 196 | 196 | protected function validateNested(array $errors): array |
| 197 | 197 | { |
| 198 | - foreach ($this->getFields(false) as $index => $value) { |
|
| 199 | - if (isset($errors[$index])) { |
|
| 198 | + foreach ($this->getFields(false) as $index => $value){ |
|
| 199 | + if (isset($errors[$index])){ |
|
| 200 | 200 | //Invalid on parent level |
| 201 | 201 | continue; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - if ($value instanceof FilterInterface) { |
|
| 205 | - if ($this->isOptional($index) && !$this->hasBeenPassed($index)) { |
|
| 204 | + if ($value instanceof FilterInterface){ |
|
| 205 | + if ($this->isOptional($index) && !$this->hasBeenPassed($index)){ |
|
| 206 | 206 | continue; |
| 207 | 207 | } |
| 208 | 208 | |
| 209 | - if (!$value->isValid()) { |
|
| 209 | + if (!$value->isValid()){ |
|
| 210 | 210 | $errors[$index] = $value->getErrors(); |
| 211 | 211 | continue; |
| 212 | 212 | } |
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | //Array of nested entities for validation |
| 216 | - if (is_iterable($value)) { |
|
| 217 | - foreach ($value as $nIndex => $nValue) { |
|
| 218 | - if ($nValue instanceof FilterInterface) { |
|
| 219 | - if ($this->isOptional($nIndex) && !$this->hasBeenPassed($nIndex)) { |
|
| 216 | + if (is_iterable($value)){ |
|
| 217 | + foreach ($value as $nIndex => $nValue){ |
|
| 218 | + if ($nValue instanceof FilterInterface){ |
|
| 219 | + if ($this->isOptional($nIndex) && !$this->hasBeenPassed($nIndex)){ |
|
| 220 | 220 | continue; |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - if (!$nValue->isValid()) { |
|
| 223 | + if (!$nValue->isValid()){ |
|
| 224 | 224 | $errors[$index][$nIndex] = $nValue->getErrors(); |
| 225 | 225 | } |
| 226 | 226 | } |
@@ -254,11 +254,11 @@ discard block |
||
| 254 | 254 | { |
| 255 | 255 | $value = $this->getField((string)$field); |
| 256 | 256 | |
| 257 | - if ($value === null) { |
|
| 257 | + if ($value === null){ |
|
| 258 | 258 | return false; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - if ($value instanceof FilterInterface) { |
|
| 261 | + if ($value instanceof FilterInterface){ |
|
| 262 | 262 | return $value->getValue() !== []; |
| 263 | 263 | } |
| 264 | 264 | |
@@ -151,10 +151,13 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | public function getErrors(): array |
| 153 | 153 | { |
| 154 | - if ($this->errors === null) { |
|
| 154 | + if ($this->errors === null) |
|
| 155 | + { |
|
| 155 | 156 | $this->errors = []; |
| 156 | - foreach ($this->validator->withData($this)->getErrors() as $field => $error) { |
|
| 157 | - if (is_string($error) && Translator::isMessage($error)) { |
|
| 157 | + foreach ($this->validator->withData($this)->getErrors() as $field => $error) |
|
| 158 | + { |
|
| 159 | + if (is_string($error) && Translator::isMessage($error)) |
|
| 160 | + { |
|
| 158 | 161 | // translate error message |
| 159 | 162 | $error = $this->say($error); |
| 160 | 163 | } |
@@ -195,32 +198,42 @@ discard block |
||
| 195 | 198 | */ |
| 196 | 199 | protected function validateNested(array $errors): array |
| 197 | 200 | { |
| 198 | - foreach ($this->getFields(false) as $index => $value) { |
|
| 199 | - if (isset($errors[$index])) { |
|
| 201 | + foreach ($this->getFields(false) as $index => $value) |
|
| 202 | + { |
|
| 203 | + if (isset($errors[$index])) |
|
| 204 | + { |
|
| 200 | 205 | //Invalid on parent level |
| 201 | 206 | continue; |
| 202 | 207 | } |
| 203 | 208 | |
| 204 | - if ($value instanceof FilterInterface) { |
|
| 205 | - if ($this->isOptional($index) && !$this->hasBeenPassed($index)) { |
|
| 209 | + if ($value instanceof FilterInterface) |
|
| 210 | + { |
|
| 211 | + if ($this->isOptional($index) && !$this->hasBeenPassed($index)) |
|
| 212 | + { |
|
| 206 | 213 | continue; |
| 207 | 214 | } |
| 208 | 215 | |
| 209 | - if (!$value->isValid()) { |
|
| 216 | + if (!$value->isValid()) |
|
| 217 | + { |
|
| 210 | 218 | $errors[$index] = $value->getErrors(); |
| 211 | 219 | continue; |
| 212 | 220 | } |
| 213 | 221 | } |
| 214 | 222 | |
| 215 | 223 | //Array of nested entities for validation |
| 216 | - if (is_iterable($value)) { |
|
| 217 | - foreach ($value as $nIndex => $nValue) { |
|
| 218 | - if ($nValue instanceof FilterInterface) { |
|
| 219 | - if ($this->isOptional($nIndex) && !$this->hasBeenPassed($nIndex)) { |
|
| 224 | + if (is_iterable($value)) |
|
| 225 | + { |
|
| 226 | + foreach ($value as $nIndex => $nValue) |
|
| 227 | + { |
|
| 228 | + if ($nValue instanceof FilterInterface) |
|
| 229 | + { |
|
| 230 | + if ($this->isOptional($nIndex) && !$this->hasBeenPassed($nIndex)) |
|
| 231 | + { |
|
| 220 | 232 | continue; |
| 221 | 233 | } |
| 222 | 234 | |
| 223 | - if (!$nValue->isValid()) { |
|
| 235 | + if (!$nValue->isValid()) |
|
| 236 | + { |
|
| 224 | 237 | $errors[$index][$nIndex] = $nValue->getErrors(); |
| 225 | 238 | } |
| 226 | 239 | } |
@@ -254,11 +267,13 @@ discard block |
||
| 254 | 267 | { |
| 255 | 268 | $value = $this->getField((string)$field); |
| 256 | 269 | |
| 257 | - if ($value === null) { |
|
| 270 | + if ($value === null) |
|
| 271 | + { |
|
| 258 | 272 | return false; |
| 259 | 273 | } |
| 260 | 274 | |
| 261 | - if ($value instanceof FilterInterface) { |
|
| 275 | + if ($value instanceof FilterInterface) |
|
| 276 | + { |
|
| 262 | 277 | return $value->getValue() !== []; |
| 263 | 278 | } |
| 264 | 279 | |
@@ -71,8 +71,8 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | private function bootResolvers(array $config): void |
| 73 | 73 | { |
| 74 | - foreach ($config['resolvers'] ?? [] as $name => $child) { |
|
| 75 | - if (!\is_string($name)) { |
|
| 74 | + foreach ($config['resolvers'] ?? [] as $name => $child){ |
|
| 75 | + if (!\is_string($name)){ |
|
| 76 | 76 | throw new InvalidArgumentException( |
| 77 | 77 | \vsprintf('Distribution driver config key must be a string, but %s given', [ |
| 78 | 78 | \get_debug_type($child), |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | ); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - if (!\is_array($child)) { |
|
| 83 | + if (!\is_array($child)){ |
|
| 84 | 84 | throw new InvalidArgumentException( |
| 85 | 85 | \vsprintf('Distribution driver config `%s` must be an array, but %s given', [ |
| 86 | 86 | $name, |
@@ -100,9 +100,9 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | $default = $config['default'] ?? null; |
| 102 | 102 | |
| 103 | - if ($default !== null) { |
|
| 103 | + if ($default !== null){ |
|
| 104 | 104 | // Validate config |
| 105 | - if (!\is_string($default)) { |
|
| 105 | + if (!\is_string($default)){ |
|
| 106 | 106 | throw new InvalidArgumentException( |
| 107 | 107 | \vsprintf('Distribution config default driver must be a string, but %s given', [ |
| 108 | 108 | \get_debug_type($default), |
@@ -121,13 +121,13 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | private function createResolver(string $name, array $config): UriResolverInterface |
| 123 | 123 | { |
| 124 | - if (!isset($config['type']) || !\is_string($config['type'])) { |
|
| 124 | + if (!isset($config['type']) || !\is_string($config['type'])){ |
|
| 125 | 125 | throw $this->invalidConfigKey($name, 'type', 'string'); |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | $type = $config['type']; |
| 129 | 129 | |
| 130 | - switch ($type) { |
|
| 130 | + switch ($type){ |
|
| 131 | 131 | case 'static': |
| 132 | 132 | return $this->createStaticResolver($name, $config); |
| 133 | 133 | |
@@ -150,17 +150,17 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | private function createCustomResolver(string $type, string $name, array $config): UriResolverInterface |
| 152 | 152 | { |
| 153 | - if (!\is_subclass_of($type, UriResolverInterface::class, true)) { |
|
| 153 | + if (!\is_subclass_of($type, UriResolverInterface::class, true)){ |
|
| 154 | 154 | throw $this->invalidConfigKey($name, 'type', UriResolverInterface::class); |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - if (isset($config['options']) && !\is_array($config['options'])) { |
|
| 157 | + if (isset($config['options']) && !\is_array($config['options'])){ |
|
| 158 | 158 | throw $this->invalidConfigKey($name, 'options', 'array'); |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - try { |
|
| 161 | + try{ |
|
| 162 | 162 | return new $type(...\array_values($config['options'] ?? [])); |
| 163 | - } catch (\Throwable $e) { |
|
| 163 | + }catch (\Throwable $e){ |
|
| 164 | 164 | $message = 'An error occurred while resolver `%s` initializing: %s'; |
| 165 | 165 | throw new InvalidArgumentException(\sprintf($message, $name, $e->getMessage()), 0, $e); |
| 166 | 166 | } |
@@ -174,36 +174,36 @@ discard block |
||
| 174 | 174 | private function createS3Resolver(string $name, array $config): UriResolverInterface |
| 175 | 175 | { |
| 176 | 176 | // Required config options |
| 177 | - if (!isset($config['region']) || !\is_string($config['region'])) { |
|
| 177 | + if (!isset($config['region']) || !\is_string($config['region'])){ |
|
| 178 | 178 | throw $this->invalidConfigKey($name, 'region', 'string'); |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
| 181 | + if (!isset($config['key']) || !\is_string($config['key'])){ |
|
| 182 | 182 | throw $this->invalidConfigKey($name, 'key', 'string'); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if (!isset($config['secret']) || !\is_string($config['secret'])) { |
|
| 185 | + if (!isset($config['secret']) || !\is_string($config['secret'])){ |
|
| 186 | 186 | throw $this->invalidConfigKey($name, 'secret', 'string'); |
| 187 | 187 | } |
| 188 | 188 | |
| 189 | - if (!isset($config['bucket']) || !\is_string($config['bucket'])) { |
|
| 189 | + if (!isset($config['bucket']) || !\is_string($config['bucket'])){ |
|
| 190 | 190 | throw $this->invalidConfigKey($name, 'bucket', 'string'); |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | // Optional config options |
| 194 | - if (!\is_string($config['prefix'] ?? '')) { |
|
| 194 | + if (!\is_string($config['prefix'] ?? '')){ |
|
| 195 | 195 | throw $this->invalidConfigKey($name, 'prefix', 'string or null'); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - if (!\is_string($config['version'] ?? '')) { |
|
| 198 | + if (!\is_string($config['version'] ?? '')){ |
|
| 199 | 199 | throw $this->invalidConfigKey($name, 'version', 'string or null'); |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - if (!\is_string($config['token'] ?? '')) { |
|
| 202 | + if (!\is_string($config['token'] ?? '')){ |
|
| 203 | 203 | throw $this->invalidConfigKey($name, 'token', 'string or null'); |
| 204 | 204 | } |
| 205 | 205 | |
| 206 | - if (!\is_int($config['expires'] ?? 0)) { |
|
| 206 | + if (!\is_int($config['expires'] ?? 0)){ |
|
| 207 | 207 | throw $this->invalidConfigKey($name, 'expires', 'positive int (unix timestamp)'); |
| 208 | 208 | } |
| 209 | 209 | |
@@ -233,19 +233,19 @@ discard block |
||
| 233 | 233 | */ |
| 234 | 234 | private function createCloudFrontResolver(string $name, array $config): UriResolverInterface |
| 235 | 235 | { |
| 236 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
| 236 | + if (!isset($config['key']) || !\is_string($config['key'])){ |
|
| 237 | 237 | throw $this->invalidConfigKey($name, 'key', 'string'); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | - if (!isset($config['private']) || !\is_string($config['private'])) { |
|
| 240 | + if (!isset($config['private']) || !\is_string($config['private'])){ |
|
| 241 | 241 | throw $this->invalidConfigKey($name, 'private', 'string value or path to key file'); |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - if (!isset($config['domain']) || !\is_string($config['domain'])) { |
|
| 244 | + if (!isset($config['domain']) || !\is_string($config['domain'])){ |
|
| 245 | 245 | throw $this->invalidConfigKey($name, 'domain', 'string'); |
| 246 | 246 | } |
| 247 | 247 | |
| 248 | - if (!\is_string($config['prefix'] ?? '')) { |
|
| 248 | + if (!\is_string($config['prefix'] ?? '')){ |
|
| 249 | 249 | throw $this->invalidConfigKey($name, 'prefix', 'string or null'); |
| 250 | 250 | } |
| 251 | 251 | |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | */ |
| 265 | 265 | private function createStaticResolver(string $name, array $config): UriResolverInterface |
| 266 | 266 | { |
| 267 | - if (!isset($config['uri']) || !\is_string($config['uri'])) { |
|
| 267 | + if (!isset($config['uri']) || !\is_string($config['uri'])){ |
|
| 268 | 268 | throw $this->invalidConfigKey($name, 'uri', 'string'); |
| 269 | 269 | } |
| 270 | 270 | |
@@ -279,17 +279,17 @@ discard block |
||
| 279 | 279 | */ |
| 280 | 280 | private function createUri(string $name, string $uri, array $config): UriInterface |
| 281 | 281 | { |
| 282 | - if (!\is_string($config['factory'] ?? '')) { |
|
| 282 | + if (!\is_string($config['factory'] ?? '')){ |
|
| 283 | 283 | throw $this->invalidConfigKey($name, 'factory', 'string (PSR-7 uri factory implementation)'); |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - switch (true) { |
|
| 286 | + switch (true){ |
|
| 287 | 287 | case isset($config['factory']): |
| 288 | 288 | /** @var UriFactoryInterface $factory */ |
| 289 | 289 | $factory = new $config['factory'](); |
| 290 | 290 | |
| 291 | - if (!$factory instanceof UriFactoryInterface) { |
|
| 292 | - $message = 'Distribution config driver `%s` should contain class that must be a valid PSR-7 ' . |
|
| 291 | + if (!$factory instanceof UriFactoryInterface){ |
|
| 292 | + $message = 'Distribution config driver `%s` should contain class that must be a valid PSR-7 '. |
|
| 293 | 293 | 'uri factory implementation, but `%s` given'; |
| 294 | 294 | throw new InvalidArgumentException(\sprintf($message, $name, $config['factory'])); |
| 295 | 295 | } |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | return new GuzzleUri($uri); |
| 304 | 304 | |
| 305 | 305 | default: |
| 306 | - $message = 'Can not resolve available PSR-7 UriFactory implementation; ' . |
|
| 306 | + $message = 'Can not resolve available PSR-7 UriFactory implementation; '. |
|
| 307 | 307 | 'Please define `factory` config section in `%s` distribution driver config'; |
| 308 | 308 | throw new InvalidArgumentException(\sprintf($message, $name)); |
| 309 | 309 | } |
@@ -71,8 +71,10 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | private function bootResolvers(array $config): void |
| 73 | 73 | { |
| 74 | - foreach ($config['resolvers'] ?? [] as $name => $child) { |
|
| 75 | - if (!\is_string($name)) { |
|
| 74 | + foreach ($config['resolvers'] ?? [] as $name => $child) |
|
| 75 | + { |
|
| 76 | + if (!\is_string($name)) |
|
| 77 | + { |
|
| 76 | 78 | throw new InvalidArgumentException( |
| 77 | 79 | \vsprintf('Distribution driver config key must be a string, but %s given', [ |
| 78 | 80 | \get_debug_type($child), |
@@ -80,7 +82,8 @@ discard block |
||
| 80 | 82 | ); |
| 81 | 83 | } |
| 82 | 84 | |
| 83 | - if (!\is_array($child)) { |
|
| 85 | + if (!\is_array($child)) |
|
| 86 | + { |
|
| 84 | 87 | throw new InvalidArgumentException( |
| 85 | 88 | \vsprintf('Distribution driver config `%s` must be an array, but %s given', [ |
| 86 | 89 | $name, |
@@ -100,9 +103,11 @@ discard block |
||
| 100 | 103 | { |
| 101 | 104 | $default = $config['default'] ?? null; |
| 102 | 105 | |
| 103 | - if ($default !== null) { |
|
| 106 | + if ($default !== null) |
|
| 107 | + { |
|
| 104 | 108 | // Validate config |
| 105 | - if (!\is_string($default)) { |
|
| 109 | + if (!\is_string($default)) |
|
| 110 | + { |
|
| 106 | 111 | throw new InvalidArgumentException( |
| 107 | 112 | \vsprintf('Distribution config default driver must be a string, but %s given', [ |
| 108 | 113 | \get_debug_type($default), |
@@ -121,13 +126,15 @@ discard block |
||
| 121 | 126 | */ |
| 122 | 127 | private function createResolver(string $name, array $config): UriResolverInterface |
| 123 | 128 | { |
| 124 | - if (!isset($config['type']) || !\is_string($config['type'])) { |
|
| 129 | + if (!isset($config['type']) || !\is_string($config['type'])) |
|
| 130 | + { |
|
| 125 | 131 | throw $this->invalidConfigKey($name, 'type', 'string'); |
| 126 | 132 | } |
| 127 | 133 | |
| 128 | 134 | $type = $config['type']; |
| 129 | 135 | |
| 130 | - switch ($type) { |
|
| 136 | + switch ($type) |
|
| 137 | + { |
|
| 131 | 138 | case 'static': |
| 132 | 139 | return $this->createStaticResolver($name, $config); |
| 133 | 140 | |
@@ -150,17 +157,22 @@ discard block |
||
| 150 | 157 | */ |
| 151 | 158 | private function createCustomResolver(string $type, string $name, array $config): UriResolverInterface |
| 152 | 159 | { |
| 153 | - if (!\is_subclass_of($type, UriResolverInterface::class, true)) { |
|
| 160 | + if (!\is_subclass_of($type, UriResolverInterface::class, true)) |
|
| 161 | + { |
|
| 154 | 162 | throw $this->invalidConfigKey($name, 'type', UriResolverInterface::class); |
| 155 | 163 | } |
| 156 | 164 | |
| 157 | - if (isset($config['options']) && !\is_array($config['options'])) { |
|
| 165 | + if (isset($config['options']) && !\is_array($config['options'])) |
|
| 166 | + { |
|
| 158 | 167 | throw $this->invalidConfigKey($name, 'options', 'array'); |
| 159 | 168 | } |
| 160 | 169 | |
| 161 | - try { |
|
| 170 | + try |
|
| 171 | + { |
|
| 162 | 172 | return new $type(...\array_values($config['options'] ?? [])); |
| 163 | - } catch (\Throwable $e) { |
|
| 173 | + } |
|
| 174 | + catch (\Throwable $e) |
|
| 175 | + { |
|
| 164 | 176 | $message = 'An error occurred while resolver `%s` initializing: %s'; |
| 165 | 177 | throw new InvalidArgumentException(\sprintf($message, $name, $e->getMessage()), 0, $e); |
| 166 | 178 | } |
@@ -174,36 +186,44 @@ discard block |
||
| 174 | 186 | private function createS3Resolver(string $name, array $config): UriResolverInterface |
| 175 | 187 | { |
| 176 | 188 | // Required config options |
| 177 | - if (!isset($config['region']) || !\is_string($config['region'])) { |
|
| 189 | + if (!isset($config['region']) || !\is_string($config['region'])) |
|
| 190 | + { |
|
| 178 | 191 | throw $this->invalidConfigKey($name, 'region', 'string'); |
| 179 | 192 | } |
| 180 | 193 | |
| 181 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
| 194 | + if (!isset($config['key']) || !\is_string($config['key'])) |
|
| 195 | + { |
|
| 182 | 196 | throw $this->invalidConfigKey($name, 'key', 'string'); |
| 183 | 197 | } |
| 184 | 198 | |
| 185 | - if (!isset($config['secret']) || !\is_string($config['secret'])) { |
|
| 199 | + if (!isset($config['secret']) || !\is_string($config['secret'])) |
|
| 200 | + { |
|
| 186 | 201 | throw $this->invalidConfigKey($name, 'secret', 'string'); |
| 187 | 202 | } |
| 188 | 203 | |
| 189 | - if (!isset($config['bucket']) || !\is_string($config['bucket'])) { |
|
| 204 | + if (!isset($config['bucket']) || !\is_string($config['bucket'])) |
|
| 205 | + { |
|
| 190 | 206 | throw $this->invalidConfigKey($name, 'bucket', 'string'); |
| 191 | 207 | } |
| 192 | 208 | |
| 193 | 209 | // Optional config options |
| 194 | - if (!\is_string($config['prefix'] ?? '')) { |
|
| 210 | + if (!\is_string($config['prefix'] ?? '')) |
|
| 211 | + { |
|
| 195 | 212 | throw $this->invalidConfigKey($name, 'prefix', 'string or null'); |
| 196 | 213 | } |
| 197 | 214 | |
| 198 | - if (!\is_string($config['version'] ?? '')) { |
|
| 215 | + if (!\is_string($config['version'] ?? '')) |
|
| 216 | + { |
|
| 199 | 217 | throw $this->invalidConfigKey($name, 'version', 'string or null'); |
| 200 | 218 | } |
| 201 | 219 | |
| 202 | - if (!\is_string($config['token'] ?? '')) { |
|
| 220 | + if (!\is_string($config['token'] ?? '')) |
|
| 221 | + { |
|
| 203 | 222 | throw $this->invalidConfigKey($name, 'token', 'string or null'); |
| 204 | 223 | } |
| 205 | 224 | |
| 206 | - if (!\is_int($config['expires'] ?? 0)) { |
|
| 225 | + if (!\is_int($config['expires'] ?? 0)) |
|
| 226 | + { |
|
| 207 | 227 | throw $this->invalidConfigKey($name, 'expires', 'positive int (unix timestamp)'); |
| 208 | 228 | } |
| 209 | 229 | |
@@ -233,19 +253,23 @@ discard block |
||
| 233 | 253 | */ |
| 234 | 254 | private function createCloudFrontResolver(string $name, array $config): UriResolverInterface |
| 235 | 255 | { |
| 236 | - if (!isset($config['key']) || !\is_string($config['key'])) { |
|
| 256 | + if (!isset($config['key']) || !\is_string($config['key'])) |
|
| 257 | + { |
|
| 237 | 258 | throw $this->invalidConfigKey($name, 'key', 'string'); |
| 238 | 259 | } |
| 239 | 260 | |
| 240 | - if (!isset($config['private']) || !\is_string($config['private'])) { |
|
| 261 | + if (!isset($config['private']) || !\is_string($config['private'])) |
|
| 262 | + { |
|
| 241 | 263 | throw $this->invalidConfigKey($name, 'private', 'string value or path to key file'); |
| 242 | 264 | } |
| 243 | 265 | |
| 244 | - if (!isset($config['domain']) || !\is_string($config['domain'])) { |
|
| 266 | + if (!isset($config['domain']) || !\is_string($config['domain'])) |
|
| 267 | + { |
|
| 245 | 268 | throw $this->invalidConfigKey($name, 'domain', 'string'); |
| 246 | 269 | } |
| 247 | 270 | |
| 248 | - if (!\is_string($config['prefix'] ?? '')) { |
|
| 271 | + if (!\is_string($config['prefix'] ?? '')) |
|
| 272 | + { |
|
| 249 | 273 | throw $this->invalidConfigKey($name, 'prefix', 'string or null'); |
| 250 | 274 | } |
| 251 | 275 | |
@@ -264,7 +288,8 @@ discard block |
||
| 264 | 288 | */ |
| 265 | 289 | private function createStaticResolver(string $name, array $config): UriResolverInterface |
| 266 | 290 | { |
| 267 | - if (!isset($config['uri']) || !\is_string($config['uri'])) { |
|
| 291 | + if (!isset($config['uri']) || !\is_string($config['uri'])) |
|
| 292 | + { |
|
| 268 | 293 | throw $this->invalidConfigKey($name, 'uri', 'string'); |
| 269 | 294 | } |
| 270 | 295 | |
@@ -279,16 +304,19 @@ discard block |
||
| 279 | 304 | */ |
| 280 | 305 | private function createUri(string $name, string $uri, array $config): UriInterface |
| 281 | 306 | { |
| 282 | - if (!\is_string($config['factory'] ?? '')) { |
|
| 307 | + if (!\is_string($config['factory'] ?? '')) |
|
| 308 | + { |
|
| 283 | 309 | throw $this->invalidConfigKey($name, 'factory', 'string (PSR-7 uri factory implementation)'); |
| 284 | 310 | } |
| 285 | 311 | |
| 286 | - switch (true) { |
|
| 312 | + switch (true) |
|
| 313 | + { |
|
| 287 | 314 | case isset($config['factory']): |
| 288 | 315 | /** @var UriFactoryInterface $factory */ |
| 289 | 316 | $factory = new $config['factory'](); |
| 290 | 317 | |
| 291 | - if (!$factory instanceof UriFactoryInterface) { |
|
| 318 | + if (!$factory instanceof UriFactoryInterface) |
|
| 319 | + { |
|
| 292 | 320 | $message = 'Distribution config driver `%s` should contain class that must be a valid PSR-7 ' . |
| 293 | 321 | 'uri factory implementation, but `%s` given'; |
| 294 | 322 | throw new InvalidArgumentException(\sprintf($message, $name, $config['factory'])); |
@@ -28,11 +28,11 @@ |
||
| 28 | 28 | $container->bindSingleton(ReaderInterface::class, function () use ($container) { |
| 29 | 29 | $factory = new Factory(); |
| 30 | 30 | |
| 31 | - if ($container->has(CacheInterface::class)) { |
|
| 31 | + if ($container->has(CacheInterface::class)){ |
|
| 32 | 32 | $factory = $factory->withCache( |
| 33 | 33 | $container->get(CacheInterface::class) |
| 34 | 34 | ); |
| 35 | - } elseif ($container->has(CacheItemPoolInterface::class)) { |
|
| 35 | + } elseif ($container->has(CacheItemPoolInterface::class)){ |
|
| 36 | 36 | $factory = $factory->withCache( |
| 37 | 37 | $container->get(CacheItemPoolInterface::class) |
| 38 | 38 | ); |
@@ -25,14 +25,18 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | public function boot(Container $container): void |
| 27 | 27 | { |
| 28 | - $container->bindSingleton(ReaderInterface::class, function () use ($container) { |
|
| 28 | + $container->bindSingleton(ReaderInterface::class, function () use ($container) |
|
| 29 | + { |
|
| 29 | 30 | $factory = new Factory(); |
| 30 | 31 | |
| 31 | - if ($container->has(CacheInterface::class)) { |
|
| 32 | + if ($container->has(CacheInterface::class)) |
|
| 33 | + { |
|
| 32 | 34 | $factory = $factory->withCache( |
| 33 | 35 | $container->get(CacheInterface::class) |
| 34 | 36 | ); |
| 35 | - } elseif ($container->has(CacheItemPoolInterface::class)) { |
|
| 37 | + } |
|
| 38 | + elseif ($container->has(CacheItemPoolInterface::class)) |
|
| 39 | + { |
|
| 36 | 40 | $factory = $factory->withCache( |
| 37 | 41 | $container->get(CacheItemPoolInterface::class) |
| 38 | 42 | ); |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function perform(): void |
| 28 | 28 | { |
| 29 | - if (!$this->verifyEnvironment()) { |
|
| 29 | + if (!$this->verifyEnvironment()){ |
|
| 30 | 30 | return; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | $found = false; |
| 36 | 36 | $count = $this->option('one') ? 1 : PHP_INT_MAX; |
| 37 | 37 | |
| 38 | - while ($count > 0 && ($migration = $this->migrator->run())) { |
|
| 38 | + while ($count > 0 && ($migration = $this->migrator->run())){ |
|
| 39 | 39 | $found = true; |
| 40 | 40 | $count--; |
| 41 | 41 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | ); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - if (!$found) { |
|
| 48 | + if (!$found){ |
|
| 49 | 49 | $this->writeln('<fg=red>No outstanding migrations were found.</fg=red>'); |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -26,7 +26,8 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function perform(): void |
| 28 | 28 | { |
| 29 | - if (!$this->verifyEnvironment()) { |
|
| 29 | + if (!$this->verifyEnvironment()) |
|
| 30 | + { |
|
| 30 | 31 | return; |
| 31 | 32 | } |
| 32 | 33 | |
@@ -35,7 +36,8 @@ discard block |
||
| 35 | 36 | $found = false; |
| 36 | 37 | $count = $this->option('one') ? 1 : PHP_INT_MAX; |
| 37 | 38 | |
| 38 | - while ($count > 0 && ($migration = $this->migrator->run())) { |
|
| 39 | + while ($count > 0 && ($migration = $this->migrator->run())) |
|
| 40 | + { |
|
| 39 | 41 | $found = true; |
| 40 | 42 | $count--; |
| 41 | 43 | |
@@ -45,7 +47,8 @@ discard block |
||
| 45 | 47 | ); |
| 46 | 48 | } |
| 47 | 49 | |
| 48 | - if (!$found) { |
|
| 50 | + if (!$found) |
|
| 51 | + { |
|
| 49 | 52 | $this->writeln('<fg=red>No outstanding migrations were found.</fg=red>'); |
| 50 | 53 | } |
| 51 | 54 | } |