@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | public function __construct( |
| 20 | 20 | public readonly ?string $key = null, |
| 21 | - ) { |
|
| 21 | + ){ |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -31,6 +31,6 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function getSchema(\ReflectionProperty $property): string |
| 33 | 33 | { |
| 34 | - return 'cookie:' . $this->getKey($property); |
|
| 34 | + return 'cookie:'.$this->getKey($property); |
|
| 35 | 35 | } |
| 36 | 36 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | public function __construct( |
| 20 | 20 | public readonly ?string $key = null, |
| 21 | - ) { |
|
| 21 | + ){ |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -31,6 +31,6 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function getSchema(\ReflectionProperty $property): string |
| 33 | 33 | { |
| 34 | - return 'input:' . $this->getKey($property); |
|
| 34 | + return 'input:'.$this->getKey($property); |
|
| 35 | 35 | } |
| 36 | 36 | } |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | public function __construct( |
| 10 | 10 | public readonly array $errors, |
| 11 | 11 | public readonly mixed $context = null |
| 12 | - ) { |
|
| 12 | + ){ |
|
| 13 | 13 | parent::__construct('The given data was invalid.', 422); |
| 14 | 14 | } |
| 15 | 15 | } |
@@ -17,8 +17,10 @@ discard block |
||
| 17 | 17 | { |
| 18 | 18 | // De-mapping |
| 19 | 19 | $mapped = []; |
| 20 | - foreach ($errors as $field => $message) { |
|
| 21 | - if (!isset($this->schema[$field])) { |
|
| 20 | + foreach ($errors as $field => $message) |
|
| 21 | + { |
|
| 22 | + if (!isset($this->schema[$field])) |
|
| 23 | + { |
|
| 22 | 24 | $mapped[$field] = $message; |
| 23 | 25 | continue; |
| 24 | 26 | } |
@@ -36,14 +38,16 @@ discard block |
||
| 36 | 38 | */ |
| 37 | 39 | private function mount(array &$array, string $path, mixed $message): void |
| 38 | 40 | { |
| 39 | - if ($path === '.') { |
|
| 41 | + if ($path === '.') |
|
| 42 | + { |
|
| 40 | 43 | throw new SchemaException( |
| 41 | 44 | \sprintf('Unable to mount error `%s` to `%s` (root path is forbidden)', $message, $path) |
| 42 | 45 | ); |
| 43 | 46 | } |
| 44 | 47 | |
| 45 | 48 | $step = \explode('.', $path); |
| 46 | - while ($name = \array_shift($step)) { |
|
| 49 | + while ($name = \array_shift($step)) |
|
| 50 | + { |
|
| 47 | 51 | $array = &$array[$name]; |
| 48 | 52 | } |
| 49 | 53 | |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | { |
| 11 | 11 | public function __construct( |
| 12 | 12 | private readonly array $schema |
| 13 | - ) { |
|
| 13 | + ){ |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | { |
| 22 | 22 | // De-mapping |
| 23 | 23 | $mapped = []; |
| 24 | - foreach ($errors as $field => $message) { |
|
| 25 | - if (!isset($this->schema[$field])) { |
|
| 24 | + foreach ($errors as $field => $message){ |
|
| 25 | + if (!isset($this->schema[$field])){ |
|
| 26 | 26 | $mapped[$field] = $message; |
| 27 | 27 | continue; |
| 28 | 28 | } |
@@ -40,14 +40,14 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | private function mount(array &$array, string $path, mixed $message): void |
| 42 | 42 | { |
| 43 | - if ($path === '.') { |
|
| 43 | + if ($path === '.'){ |
|
| 44 | 44 | throw new SchemaException( |
| 45 | 45 | \sprintf('Unable to mount error `%s` to `%s` (root path is forbidden)', $message, $path) |
| 46 | 46 | ); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $step = \explode('.', $path); |
| 50 | - while ($name = \array_shift($step)) { |
|
| 50 | + while ($name = \array_shift($step)){ |
|
| 51 | 51 | $array = &$array[$name]; |
| 52 | 52 | } |
| 53 | 53 | |
@@ -13,6 +13,6 @@ |
||
| 13 | 13 | public readonly AbstractEntity $entity, |
| 14 | 14 | public readonly array $schema = [], |
| 15 | 15 | public readonly array $errors = [], |
| 16 | - ) { |
|
| 16 | + ){ |
|
| 17 | 17 | } |
| 18 | 18 | } |
@@ -42,18 +42,18 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function makeSchema(string $name, array $schema): array |
| 44 | 44 | { |
| 45 | - if (empty($schema)) { |
|
| 45 | + if (empty($schema)){ |
|
| 46 | 46 | throw new SchemaException(\sprintf('Filter `%s` does not define any schema', $name)); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | $result = []; |
| 50 | - foreach ($schema as $field => $definition) { |
|
| 50 | + foreach ($schema as $field => $definition){ |
|
| 51 | 51 | $optional = false; |
| 52 | 52 | |
| 53 | 53 | // short definition |
| 54 | - if (\is_string($definition)) { |
|
| 54 | + if (\is_string($definition)){ |
|
| 55 | 55 | // simple scalar field definition |
| 56 | - if (!\class_exists($definition)) { |
|
| 56 | + if (!\class_exists($definition)){ |
|
| 57 | 57 | [$source, $origin] = $this->parseDefinition($field, $definition); |
| 58 | 58 | $result[$field] = [ |
| 59 | 59 | self::SCHEMA_SOURCE => $source, |
@@ -74,25 +74,25 @@ discard block |
||
| 74 | 74 | continue; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if (!\is_array($definition) || $definition === []) { |
|
| 77 | + if (!\is_array($definition) || $definition === []){ |
|
| 78 | 78 | throw new SchemaException( |
| 79 | 79 | \sprintf('Invalid schema definition at `%s`->`%s`', $name, $field) |
| 80 | 80 | ); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | // complex definition |
| 84 | - if (!empty($definition[self::ORIGIN])) { |
|
| 84 | + if (!empty($definition[self::ORIGIN])){ |
|
| 85 | 85 | $origin = $definition[self::ORIGIN]; |
| 86 | 86 | |
| 87 | 87 | // [class, 'data:something.*'] vs [class, 'data:something'] |
| 88 | 88 | $iterate = \str_contains((string)$origin, '.*') || !empty($definition[self::ITERATE]); |
| 89 | 89 | $origin = \rtrim($origin, '.*'); |
| 90 | - } else { |
|
| 90 | + }else{ |
|
| 91 | 91 | $origin = $field; |
| 92 | 92 | $iterate = true; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - if (!empty($definition[self::OPTIONAL])) { |
|
| 95 | + if (!empty($definition[self::OPTIONAL])){ |
|
| 96 | 96 | $optional = true; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | self::SCHEMA_OPTIONAL => $optional, |
| 106 | 106 | ]; |
| 107 | 107 | |
| 108 | - if ($iterate) { |
|
| 108 | + if ($iterate){ |
|
| 109 | 109 | [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin); |
| 110 | 110 | |
| 111 | 111 | $map[self::SCHEMA_ITERATE_SOURCE] = $source; |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | private function parseDefinition(string $field, string $definition): array |
| 130 | 130 | { |
| 131 | - if (!\str_contains($definition, ':')) { |
|
| 131 | + if (!\str_contains($definition, ':')){ |
|
| 132 | 132 | return ['data', empty($definition) ? $field : $definition]; |
| 133 | 133 | } |
| 134 | 134 | |
@@ -42,18 +42,22 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function makeSchema(string $name, array $schema): array |
| 44 | 44 | { |
| 45 | - if (empty($schema)) { |
|
| 45 | + if (empty($schema)) |
|
| 46 | + { |
|
| 46 | 47 | throw new SchemaException(\sprintf('Filter `%s` does not define any schema', $name)); |
| 47 | 48 | } |
| 48 | 49 | |
| 49 | 50 | $result = []; |
| 50 | - foreach ($schema as $field => $definition) { |
|
| 51 | + foreach ($schema as $field => $definition) |
|
| 52 | + { |
|
| 51 | 53 | $optional = false; |
| 52 | 54 | |
| 53 | 55 | // short definition |
| 54 | - if (\is_string($definition)) { |
|
| 56 | + if (\is_string($definition)) |
|
| 57 | + { |
|
| 55 | 58 | // simple scalar field definition |
| 56 | - if (!\class_exists($definition)) { |
|
| 59 | + if (!\class_exists($definition)) |
|
| 60 | + { |
|
| 57 | 61 | [$source, $origin] = $this->parseDefinition($field, $definition); |
| 58 | 62 | $result[$field] = [ |
| 59 | 63 | self::SCHEMA_SOURCE => $source, |
@@ -74,25 +78,30 @@ discard block |
||
| 74 | 78 | continue; |
| 75 | 79 | } |
| 76 | 80 | |
| 77 | - if (!\is_array($definition) || $definition === []) { |
|
| 81 | + if (!\is_array($definition) || $definition === []) |
|
| 82 | + { |
|
| 78 | 83 | throw new SchemaException( |
| 79 | 84 | \sprintf('Invalid schema definition at `%s`->`%s`', $name, $field) |
| 80 | 85 | ); |
| 81 | 86 | } |
| 82 | 87 | |
| 83 | 88 | // complex definition |
| 84 | - if (!empty($definition[self::ORIGIN])) { |
|
| 89 | + if (!empty($definition[self::ORIGIN])) |
|
| 90 | + { |
|
| 85 | 91 | $origin = $definition[self::ORIGIN]; |
| 86 | 92 | |
| 87 | 93 | // [class, 'data:something.*'] vs [class, 'data:something'] |
| 88 | 94 | $iterate = \str_contains((string)$origin, '.*') || !empty($definition[self::ITERATE]); |
| 89 | 95 | $origin = \rtrim($origin, '.*'); |
| 90 | - } else { |
|
| 96 | + } |
|
| 97 | + else |
|
| 98 | + { |
|
| 91 | 99 | $origin = $field; |
| 92 | 100 | $iterate = true; |
| 93 | 101 | } |
| 94 | 102 | |
| 95 | - if (!empty($definition[self::OPTIONAL])) { |
|
| 103 | + if (!empty($definition[self::OPTIONAL])) |
|
| 104 | + { |
|
| 96 | 105 | $optional = true; |
| 97 | 106 | } |
| 98 | 107 | |
@@ -105,7 +114,8 @@ discard block |
||
| 105 | 114 | self::SCHEMA_OPTIONAL => $optional, |
| 106 | 115 | ]; |
| 107 | 116 | |
| 108 | - if ($iterate) { |
|
| 117 | + if ($iterate) |
|
| 118 | + { |
|
| 109 | 119 | [$source, $origin] = $this->parseDefinition($field, $definition[self::ITERATE] ?? $origin); |
| 110 | 120 | |
| 111 | 121 | $map[self::SCHEMA_ITERATE_SOURCE] = $source; |
@@ -128,7 +138,8 @@ discard block |
||
| 128 | 138 | */ |
| 129 | 139 | private function parseDefinition(string $field, string $definition): array |
| 130 | 140 | { |
| 131 | - if (!\str_contains($definition, ':')) { |
|
| 141 | + if (!\str_contains($definition, ':')) |
|
| 142 | + { |
|
| 132 | 143 | return ['data', empty($definition) ? $field : $definition]; |
| 133 | 144 | } |
| 134 | 145 | |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | |
| 25 | 25 | $bag = $parameters['filterBag']; |
| 26 | 26 | |
| 27 | - if ($bag->filter instanceof Filter) { |
|
| 27 | + if ($bag->filter instanceof Filter){ |
|
| 28 | 28 | $bag->filter->setData($bag->entity->toArray()); |
| 29 | 29 | } |
| 30 | 30 | |
@@ -24,7 +24,8 @@ |
||
| 24 | 24 | |
| 25 | 25 | $bag = $parameters['filterBag']; |
| 26 | 26 | |
| 27 | - if ($bag->filter instanceof Filter) { |
|
| 27 | + if ($bag->filter instanceof Filter) |
|
| 28 | + { |
|
| 28 | 29 | $bag->filter->setData($bag->entity->toArray()); |
| 29 | 30 | } |
| 30 | 31 | |
@@ -22,8 +22,8 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | private FooEvent $ev; |
| 24 | 24 | private AutowireListenerFactory $factory; |
| 25 | - private ContainerInterface|MockInterface $container; |
|
| 26 | - private ClassAndMethodAttribute|MockInterface $listener; |
|
| 25 | + private ContainerInterface | MockInterface $container; |
|
| 26 | + private ClassAndMethodAttribute | MockInterface $listener; |
|
| 27 | 27 | |
| 28 | 28 | protected function setUp(): void |
| 29 | 29 | { |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | $this->listener->shouldReceive('onFooEvent')->once()->with($this->ev); |
| 46 | 46 | |
| 47 | - ContainerScope::runScope($this->container, function () { |
|
| 47 | + ContainerScope::runScope($this->container, function (){ |
|
| 48 | 48 | $listener = $this->factory->create(ClassAndMethodAttribute::class, 'onFooEvent'); |
| 49 | 49 | $listener($this->ev); |
| 50 | 50 | }); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | { |
| 55 | 55 | $this->listener->shouldReceive('onFooEvent')->once()->with($this->ev); |
| 56 | 56 | |
| 57 | - ContainerScope::runScope($this->container, function () { |
|
| 57 | + ContainerScope::runScope($this->container, function (){ |
|
| 58 | 58 | $listener = $this->factory->create($this->listener, 'onFooEvent'); |
| 59 | 59 | $listener($this->ev); |
| 60 | 60 | }); |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | ->once() |
| 77 | 77 | ->with([$this->listener, 'onFooEventWithTwoArguments'], ['event' => $this->ev]); |
| 78 | 78 | |
| 79 | - ContainerScope::runScope($this->container, function () { |
|
| 79 | + ContainerScope::runScope($this->container, function (){ |
|
| 80 | 80 | $listener = $this->factory->create(ClassAndMethodAttribute::class, 'onFooEventWithTwoArguments'); |
| 81 | 81 | $listener($this->ev); |
| 82 | 82 | }); |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | ->once() |
| 94 | 94 | ->with([$this->listener, 'onFooEventWithTwoArguments'], ['event' => $this->ev]); |
| 95 | 95 | |
| 96 | - ContainerScope::runScope($this->container, function () { |
|
| 96 | + ContainerScope::runScope($this->container, function (){ |
|
| 97 | 97 | $listener = $this->factory->create($this->listener, 'onFooEventWithTwoArguments'); |
| 98 | 98 | $listener($this->ev); |
| 99 | 99 | }); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | 'Listener `Spiral\Tests\Events\Fixtures\Listener\ClassAndMethodAttribute` does not contain `test` method.' |
| 107 | 107 | ); |
| 108 | 108 | |
| 109 | - ContainerScope::runScope($this->container, function () { |
|
| 109 | + ContainerScope::runScope($this->container, function (){ |
|
| 110 | 110 | $this->factory->create(ClassAndMethodAttribute::class, 'test'); |
| 111 | 111 | }); |
| 112 | 112 | } |
@@ -44,7 +44,8 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | $this->listener->shouldReceive('onFooEvent')->once()->with($this->ev); |
| 46 | 46 | |
| 47 | - ContainerScope::runScope($this->container, function () { |
|
| 47 | + ContainerScope::runScope($this->container, function () |
|
| 48 | + { |
|
| 48 | 49 | $listener = $this->factory->create(ClassAndMethodAttribute::class, 'onFooEvent'); |
| 49 | 50 | $listener($this->ev); |
| 50 | 51 | }); |
@@ -54,7 +55,8 @@ discard block |
||
| 54 | 55 | { |
| 55 | 56 | $this->listener->shouldReceive('onFooEvent')->once()->with($this->ev); |
| 56 | 57 | |
| 57 | - ContainerScope::runScope($this->container, function () { |
|
| 58 | + ContainerScope::runScope($this->container, function () |
|
| 59 | + { |
|
| 58 | 60 | $listener = $this->factory->create($this->listener, 'onFooEvent'); |
| 59 | 61 | $listener($this->ev); |
| 60 | 62 | }); |
@@ -76,7 +78,8 @@ discard block |
||
| 76 | 78 | ->once() |
| 77 | 79 | ->with([$this->listener, 'onFooEventWithTwoArguments'], ['event' => $this->ev]); |
| 78 | 80 | |
| 79 | - ContainerScope::runScope($this->container, function () { |
|
| 81 | + ContainerScope::runScope($this->container, function () |
|
| 82 | + { |
|
| 80 | 83 | $listener = $this->factory->create(ClassAndMethodAttribute::class, 'onFooEventWithTwoArguments'); |
| 81 | 84 | $listener($this->ev); |
| 82 | 85 | }); |
@@ -93,7 +96,8 @@ discard block |
||
| 93 | 96 | ->once() |
| 94 | 97 | ->with([$this->listener, 'onFooEventWithTwoArguments'], ['event' => $this->ev]); |
| 95 | 98 | |
| 96 | - ContainerScope::runScope($this->container, function () { |
|
| 99 | + ContainerScope::runScope($this->container, function () |
|
| 100 | + { |
|
| 97 | 101 | $listener = $this->factory->create($this->listener, 'onFooEventWithTwoArguments'); |
| 98 | 102 | $listener($this->ev); |
| 99 | 103 | }); |
@@ -106,7 +110,8 @@ discard block |
||
| 106 | 110 | 'Listener `Spiral\Tests\Events\Fixtures\Listener\ClassAndMethodAttribute` does not contain `test` method.' |
| 107 | 111 | ); |
| 108 | 112 | |
| 109 | - ContainerScope::runScope($this->container, function () { |
|
| 113 | + ContainerScope::runScope($this->container, function () |
|
| 114 | + { |
|
| 110 | 115 | $this->factory->create(ClassAndMethodAttribute::class, 'test'); |
| 111 | 116 | }); |
| 112 | 117 | } |
@@ -8,6 +8,6 @@ |
||
| 8 | 8 | { |
| 9 | 9 | public function __construct( |
| 10 | 10 | public readonly string $some |
| 11 | - ) { |
|
| 11 | + ){ |
|
| 12 | 12 | } |
| 13 | 13 | } |