@@ -36,21 +36,21 @@ |
||
36 | 36 | */ |
37 | 37 | public function withValue($value): ?SpecificationInterface |
38 | 38 | { |
39 | - if (!is_array($value)) { |
|
39 | + if (!is_array($value)){ |
|
40 | 40 | // only array values are expected |
41 | 41 | return null; |
42 | 42 | } |
43 | 43 | |
44 | 44 | $map = $this->clone($value); |
45 | - foreach ($this->filters as $name => $filter) { |
|
45 | + foreach ($this->filters as $name => $filter){ |
|
46 | 46 | $name = (string)$name; |
47 | - if (!hasKey($value, $name)) { |
|
47 | + if (!hasKey($value, $name)){ |
|
48 | 48 | // all values must be provided |
49 | 49 | return null; |
50 | 50 | } |
51 | 51 | |
52 | 52 | $applied = $filter->withValue($value[$name]); |
53 | - if ($applied === null) { |
|
53 | + if ($applied === null){ |
|
54 | 54 | return null; |
55 | 55 | } |
56 | 56 |
@@ -36,21 +36,25 @@ |
||
36 | 36 | */ |
37 | 37 | public function withValue($value): ?SpecificationInterface |
38 | 38 | { |
39 | - if (!is_array($value)) { |
|
39 | + if (!is_array($value)) |
|
40 | + { |
|
40 | 41 | // only array values are expected |
41 | 42 | return null; |
42 | 43 | } |
43 | 44 | |
44 | 45 | $map = $this->clone($value); |
45 | - foreach ($this->filters as $name => $filter) { |
|
46 | + foreach ($this->filters as $name => $filter) |
|
47 | + { |
|
46 | 48 | $name = (string)$name; |
47 | - if (!hasKey($value, $name)) { |
|
49 | + if (!hasKey($value, $name)) |
|
50 | + { |
|
48 | 51 | // all values must be provided |
49 | 52 | return null; |
50 | 53 | } |
51 | 54 | |
52 | 55 | $applied = $filter->withValue($value[$name]); |
53 | - if ($applied === null) { |
|
56 | + if ($applied === null) |
|
57 | + { |
|
54 | 58 | return null; |
55 | 59 | } |
56 | 60 |
@@ -31,7 +31,7 @@ |
||
31 | 31 | */ |
32 | 32 | public function convert($value) |
33 | 33 | { |
34 | - if (is_numeric($value)) { |
|
34 | + if (is_numeric($value)){ |
|
35 | 35 | return $value + 0; |
36 | 36 | } |
37 | 37 |
@@ -31,7 +31,8 @@ |
||
31 | 31 | */ |
32 | 32 | public function convert($value) |
33 | 33 | { |
34 | - if (is_numeric($value)) { |
|
34 | + if (is_numeric($value)) |
|
35 | + { |
|
35 | 36 | return $value + 0; |
36 | 37 | } |
37 | 38 |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | */ |
66 | 66 | private function validateBoundaries(RangeValue\Boundary $from, RangeValue\Boundary $to): void |
67 | 67 | { |
68 | - if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)) { |
|
68 | + if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)){ |
|
69 | 69 | throw new ValueException('Range boundaries should be applicable via passed type.'); |
70 | 70 | } |
71 | 71 | |
72 | - if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)) { |
|
72 | + if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)){ |
|
73 | 73 | throw new ValueException('Range boundaries should be different.'); |
74 | 74 | } |
75 | 75 | } |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | */ |
99 | 99 | private function acceptsFrom($value): bool |
100 | 100 | { |
101 | - if ($this->from->empty) { |
|
101 | + if ($this->from->empty){ |
|
102 | 102 | return true; |
103 | 103 | } |
104 | 104 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | */ |
114 | 114 | private function acceptsTo($value): bool |
115 | 115 | { |
116 | - if ($this->to->empty) { |
|
116 | + if ($this->to->empty){ |
|
117 | 117 | return true; |
118 | 118 | } |
119 | 119 | |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | private function setBoundaries(RangeValue\Boundary $from, RangeValue\Boundary $to): void |
130 | 130 | { |
131 | 131 | //Swap if from < to and both not empty |
132 | - if (!$from->empty && !$to->empty && $from->value > $to->value) { |
|
132 | + if (!$from->empty && !$to->empty && $from->value > $to->value){ |
|
133 | 133 | [$from, $to] = [$to, $from]; |
134 | 134 | } |
135 | 135 |
@@ -65,11 +65,13 @@ discard block |
||
65 | 65 | */ |
66 | 66 | private function validateBoundaries(RangeValue\Boundary $from, RangeValue\Boundary $to): void |
67 | 67 | { |
68 | - if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)) { |
|
68 | + if (!$this->acceptsBoundary($from) || !$this->acceptsBoundary($to)) |
|
69 | + { |
|
69 | 70 | throw new ValueException('Range boundaries should be applicable via passed type.'); |
70 | 71 | } |
71 | 72 | |
72 | - if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)) { |
|
73 | + if ($this->convertBoundaryValue($from) === $this->convertBoundaryValue($to)) |
|
74 | + { |
|
73 | 75 | throw new ValueException('Range boundaries should be different.'); |
74 | 76 | } |
75 | 77 | } |
@@ -98,7 +100,8 @@ discard block |
||
98 | 100 | */ |
99 | 101 | private function acceptsFrom($value): bool |
100 | 102 | { |
101 | - if ($this->from->empty) { |
|
103 | + if ($this->from->empty) |
|
104 | + { |
|
102 | 105 | return true; |
103 | 106 | } |
104 | 107 | |
@@ -113,7 +116,8 @@ discard block |
||
113 | 116 | */ |
114 | 117 | private function acceptsTo($value): bool |
115 | 118 | { |
116 | - if ($this->to->empty) { |
|
119 | + if ($this->to->empty) |
|
120 | + { |
|
117 | 121 | return true; |
118 | 122 | } |
119 | 123 | |
@@ -129,7 +133,8 @@ discard block |
||
129 | 133 | private function setBoundaries(RangeValue\Boundary $from, RangeValue\Boundary $to): void |
130 | 134 | { |
131 | 135 | //Swap if from < to and both not empty |
132 | - if (!$from->empty && !$to->empty && $from->value > $to->value) { |
|
136 | + if (!$from->empty && !$to->empty && $from->value > $to->value) |
|
137 | + { |
|
133 | 138 | [$from, $to] = [$to, $from]; |
134 | 139 | } |
135 | 140 |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function __construct(ValueInterface $base, ...$values) |
31 | 31 | { |
32 | - if ($base instanceof static) { |
|
32 | + if ($base instanceof static){ |
|
33 | 33 | throw new ValueException(sprintf('Nested value type not allowed, got `%s`', get_class($base))); |
34 | 34 | } |
35 | 35 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function accepts($value): bool |
44 | 44 | { |
45 | - if (!$this->base->accepts($value)) { |
|
45 | + if (!$this->base->accepts($value)){ |
|
46 | 46 | return false; |
47 | 47 | } |
48 | 48 | |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | */ |
64 | 64 | private function convertEnum(array $values): array |
65 | 65 | { |
66 | - if (empty($values)) { |
|
66 | + if (empty($values)){ |
|
67 | 67 | throw new ValueException('Enum set should not be empty'); |
68 | 68 | } |
69 | 69 | |
70 | 70 | $type = new ArrayValue($this->base); |
71 | - if (!$type->accepts($values)) { |
|
71 | + if (!$type->accepts($values)){ |
|
72 | 72 | throw new ValueException( |
73 | 73 | sprintf( |
74 | 74 | '"Got non-compatible values, expected only compatible with `%s`.', |
@@ -29,7 +29,8 @@ discard block |
||
29 | 29 | */ |
30 | 30 | public function __construct(ValueInterface $base, ...$values) |
31 | 31 | { |
32 | - if ($base instanceof static) { |
|
32 | + if ($base instanceof static) |
|
33 | + { |
|
33 | 34 | throw new ValueException(sprintf('Nested value type not allowed, got `%s`', get_class($base))); |
34 | 35 | } |
35 | 36 | |
@@ -42,7 +43,8 @@ discard block |
||
42 | 43 | */ |
43 | 44 | public function accepts($value): bool |
44 | 45 | { |
45 | - if (!$this->base->accepts($value)) { |
|
46 | + if (!$this->base->accepts($value)) |
|
47 | + { |
|
46 | 48 | return false; |
47 | 49 | } |
48 | 50 | |
@@ -63,12 +65,14 @@ discard block |
||
63 | 65 | */ |
64 | 66 | private function convertEnum(array $values): array |
65 | 67 | { |
66 | - if (empty($values)) { |
|
68 | + if (empty($values)) |
|
69 | + { |
|
67 | 70 | throw new ValueException('Enum set should not be empty'); |
68 | 71 | } |
69 | 72 | |
70 | 73 | $type = new ArrayValue($this->base); |
71 | - if (!$type->accepts($values)) { |
|
74 | + if (!$type->accepts($values)) |
|
75 | + { |
|
72 | 76 | throw new ValueException( |
73 | 77 | sprintf( |
74 | 78 | '"Got non-compatible values, expected only compatible with `%s`.', |
@@ -32,11 +32,11 @@ |
||
32 | 32 | */ |
33 | 33 | public function convert($value): ?DateTimeImmutable |
34 | 34 | { |
35 | - try { |
|
35 | + try{ |
|
36 | 36 | $value = (string)$value; |
37 | 37 | |
38 | 38 | return new DateTimeImmutable(is_numeric($value) ? "@$value" : $value); |
39 | - } catch (Throwable $e) { |
|
39 | + }catch (Throwable $e){ |
|
40 | 40 | return null; |
41 | 41 | } |
42 | 42 | } |
@@ -32,11 +32,14 @@ |
||
32 | 32 | */ |
33 | 33 | public function convert($value): ?DateTimeImmutable |
34 | 34 | { |
35 | - try { |
|
35 | + try |
|
36 | + { |
|
36 | 37 | $value = (string)$value; |
37 | 38 | |
38 | 39 | return new DateTimeImmutable(is_numeric($value) ? "@$value" : $value); |
39 | - } catch (Throwable $e) { |
|
40 | + } |
|
41 | + catch (Throwable $e) |
|
42 | + { |
|
40 | 43 | return null; |
41 | 44 | } |
42 | 45 | } |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | { |
36 | 36 | $values = (array)$values; |
37 | 37 | |
38 | - if (count($values) === 1) { |
|
38 | + if (count($values) === 1){ |
|
39 | 39 | return $this->enum->accepts(array_values($values)[0]); |
40 | 40 | } |
41 | 41 | |
42 | - foreach ($values as $value) { |
|
43 | - if ($this->enum->accepts($value)) { |
|
42 | + foreach ($values as $value){ |
|
43 | + if ($this->enum->accepts($value)){ |
|
44 | 44 | return true; |
45 | 45 | } |
46 | 46 | } |
@@ -55,8 +55,8 @@ discard block |
||
55 | 55 | public function convert($values): array |
56 | 56 | { |
57 | 57 | $result = []; |
58 | - foreach ((array)$values as $value) { |
|
59 | - if ($this->enum->accepts($value)) { |
|
58 | + foreach ((array)$values as $value){ |
|
59 | + if ($this->enum->accepts($value)){ |
|
60 | 60 | $result[] = $this->enum->convert($value); |
61 | 61 | } |
62 | 62 | } |
@@ -35,12 +35,15 @@ discard block |
||
35 | 35 | { |
36 | 36 | $values = (array)$values; |
37 | 37 | |
38 | - if (count($values) === 1) { |
|
38 | + if (count($values) === 1) |
|
39 | + { |
|
39 | 40 | return $this->enum->accepts(array_values($values)[0]); |
40 | 41 | } |
41 | 42 | |
42 | - foreach ($values as $value) { |
|
43 | - if ($this->enum->accepts($value)) { |
|
43 | + foreach ($values as $value) |
|
44 | + { |
|
45 | + if ($this->enum->accepts($value)) |
|
46 | + { |
|
44 | 47 | return true; |
45 | 48 | } |
46 | 49 | } |
@@ -55,8 +58,10 @@ discard block |
||
55 | 58 | public function convert($values): array |
56 | 59 | { |
57 | 60 | $result = []; |
58 | - foreach ((array)$values as $value) { |
|
59 | - if ($this->enum->accepts($value)) { |
|
61 | + foreach ((array)$values as $value) |
|
62 | + { |
|
63 | + if ($this->enum->accepts($value)) |
|
64 | + { |
|
60 | 65 | $result[] = $this->enum->convert($value); |
61 | 66 | } |
62 | 67 | } |
@@ -23,11 +23,11 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function accepts($value): bool |
25 | 25 | { |
26 | - if (is_bool($value)) { |
|
26 | + if (is_bool($value)){ |
|
27 | 27 | return true; |
28 | 28 | } |
29 | 29 | |
30 | - if (is_scalar($value)) { |
|
30 | + if (is_scalar($value)){ |
|
31 | 31 | return in_array(strtolower((string)$value), ['0', '1', 'true', 'false'], true); |
32 | 32 | } |
33 | 33 | |
@@ -40,12 +40,12 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function convert($value): bool |
42 | 42 | { |
43 | - if (is_bool($value)) { |
|
43 | + if (is_bool($value)){ |
|
44 | 44 | return $value; |
45 | 45 | } |
46 | 46 | |
47 | - if (is_scalar($value)) { |
|
48 | - switch (strtolower((string)$value)) { |
|
47 | + if (is_scalar($value)){ |
|
48 | + switch (strtolower((string)$value)){ |
|
49 | 49 | case '0': |
50 | 50 | case 'false': |
51 | 51 | return false; |
@@ -23,11 +23,13 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function accepts($value): bool |
25 | 25 | { |
26 | - if (is_bool($value)) { |
|
26 | + if (is_bool($value)) |
|
27 | + { |
|
27 | 28 | return true; |
28 | 29 | } |
29 | 30 | |
30 | - if (is_scalar($value)) { |
|
31 | + if (is_scalar($value)) |
|
32 | + { |
|
31 | 33 | return in_array(strtolower((string)$value), ['0', '1', 'true', 'false'], true); |
32 | 34 | } |
33 | 35 | |
@@ -40,12 +42,15 @@ discard block |
||
40 | 42 | */ |
41 | 43 | public function convert($value): bool |
42 | 44 | { |
43 | - if (is_bool($value)) { |
|
45 | + if (is_bool($value)) |
|
46 | + { |
|
44 | 47 | return $value; |
45 | 48 | } |
46 | 49 | |
47 | - if (is_scalar($value)) { |
|
48 | - switch (strtolower((string)$value)) { |
|
50 | + if (is_scalar($value)) |
|
51 | + { |
|
52 | + switch (strtolower((string)$value)) |
|
53 | + { |
|
49 | 54 | case '0': |
50 | 55 | case 'false': |
51 | 56 | return false; |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function __construct(ValueInterface $base) |
25 | 25 | { |
26 | - if ($base instanceof ArrayValue) { |
|
26 | + if ($base instanceof ArrayValue){ |
|
27 | 27 | throw new ValueException(sprintf('Scalar value type expected, got `%s`', get_class($base))); |
28 | 28 | } |
29 | 29 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function accepts($value): bool |
38 | 38 | { |
39 | - if (!$this->base->accepts($value)) { |
|
39 | + if (!$this->base->accepts($value)){ |
|
40 | 40 | return false; |
41 | 41 | } |
42 | 42 |
@@ -23,7 +23,8 @@ discard block |
||
23 | 23 | */ |
24 | 24 | public function __construct(ValueInterface $base) |
25 | 25 | { |
26 | - if ($base instanceof ArrayValue) { |
|
26 | + if ($base instanceof ArrayValue) |
|
27 | + { |
|
27 | 28 | throw new ValueException(sprintf('Scalar value type expected, got `%s`', get_class($base))); |
28 | 29 | } |
29 | 30 | |
@@ -36,7 +37,8 @@ discard block |
||
36 | 37 | */ |
37 | 38 | public function accepts($value): bool |
38 | 39 | { |
39 | - if (!$this->base->accepts($value)) { |
|
40 | + if (!$this->base->accepts($value)) |
|
41 | + { |
|
40 | 42 | return false; |
41 | 43 | } |
42 | 44 |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | { |
62 | 62 | $this->mask = strtolower($mask); |
63 | 63 | |
64 | - if ($this->mask !== self::NIL && !isset(self::PATTERNS[$this->mask])) { |
|
64 | + if ($this->mask !== self::NIL && !isset(self::PATTERNS[$this->mask])){ |
|
65 | 65 | throw new ValueException('Invalid UUID version mask given. Please choose one of the constants.'); |
66 | 66 | } |
67 | 67 | |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | { |
94 | 94 | $uuid = str_replace(['urn:', 'uuid:', '{', '}'], '', $value); |
95 | 95 | |
96 | - if ($this->mask === self::NIL) { |
|
96 | + if ($this->mask === self::NIL){ |
|
97 | 97 | return $value === self::NIL_VALUE; |
98 | 98 | } |
99 | 99 |
@@ -61,7 +61,8 @@ discard block |
||
61 | 61 | { |
62 | 62 | $this->mask = strtolower($mask); |
63 | 63 | |
64 | - if ($this->mask !== self::NIL && !isset(self::PATTERNS[$this->mask])) { |
|
64 | + if ($this->mask !== self::NIL && !isset(self::PATTERNS[$this->mask])) |
|
65 | + { |
|
65 | 66 | throw new ValueException('Invalid UUID version mask given. Please choose one of the constants.'); |
66 | 67 | } |
67 | 68 | |
@@ -93,7 +94,8 @@ discard block |
||
93 | 94 | { |
94 | 95 | $uuid = str_replace(['urn:', 'uuid:', '{', '}'], '', $value); |
95 | 96 | |
96 | - if ($this->mask === self::NIL) { |
|
97 | + if ($this->mask === self::NIL) |
|
98 | + { |
|
97 | 99 | return $value === self::NIL_VALUE; |
98 | 100 | } |
99 | 101 |