@@ -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 |
@@ -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 | } |
@@ -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; |
@@ -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 |
@@ -32,12 +32,12 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function accepts($value): bool |
34 | 34 | { |
35 | - if (!is_array($value)) { |
|
35 | + if (!is_array($value)){ |
|
36 | 36 | return false; |
37 | 37 | } |
38 | 38 | |
39 | - foreach ($value as $child) { |
|
40 | - if (!$this->base->accepts($child)) { |
|
39 | + foreach ($value as $child){ |
|
40 | + if (!$this->base->accepts($child)){ |
|
41 | 41 | return false; |
42 | 42 | } |
43 | 43 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | public function convert($value): array |
53 | 53 | { |
54 | 54 | $result = []; |
55 | - foreach ($value as $child) { |
|
55 | + foreach ($value as $child){ |
|
56 | 56 | $result[] = $this->base->convert($child); |
57 | 57 | } |
58 | 58 |
@@ -32,12 +32,15 @@ discard block |
||
32 | 32 | */ |
33 | 33 | public function accepts($value): bool |
34 | 34 | { |
35 | - if (!is_array($value)) { |
|
35 | + if (!is_array($value)) |
|
36 | + { |
|
36 | 37 | return false; |
37 | 38 | } |
38 | 39 | |
39 | - foreach ($value as $child) { |
|
40 | - if (!$this->base->accepts($child)) { |
|
40 | + foreach ($value as $child) |
|
41 | + { |
|
42 | + if (!$this->base->accepts($child)) |
|
43 | + { |
|
41 | 44 | return false; |
42 | 45 | } |
43 | 46 | } |
@@ -52,7 +55,8 @@ discard block |
||
52 | 55 | public function convert($value): array |
53 | 56 | { |
54 | 57 | $result = []; |
55 | - foreach ($value as $child) { |
|
58 | + foreach ($value as $child) |
|
59 | + { |
|
56 | 60 | $result[] = $this->base->convert($child); |
57 | 61 | } |
58 | 62 |
@@ -30,11 +30,11 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function accepts($value): bool |
32 | 32 | { |
33 | - if (empty($value)) { |
|
33 | + if (empty($value)){ |
|
34 | 34 | return false; |
35 | 35 | } |
36 | 36 | |
37 | - if ($this->value instanceof ValueInterface) { |
|
37 | + if ($this->value instanceof ValueInterface){ |
|
38 | 38 | return $this->value->accepts($value); |
39 | 39 | } |
40 | 40 | |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | */ |
47 | 47 | public function convert($value) |
48 | 48 | { |
49 | - if ($this->value instanceof ValueInterface) { |
|
49 | + if ($this->value instanceof ValueInterface){ |
|
50 | 50 | return $this->value->convert($value); |
51 | 51 | } |
52 | 52 |
@@ -30,11 +30,13 @@ discard block |
||
30 | 30 | */ |
31 | 31 | public function accepts($value): bool |
32 | 32 | { |
33 | - if (empty($value)) { |
|
33 | + if (empty($value)) |
|
34 | + { |
|
34 | 35 | return false; |
35 | 36 | } |
36 | 37 | |
37 | - if ($this->value instanceof ValueInterface) { |
|
38 | + if ($this->value instanceof ValueInterface) |
|
39 | + { |
|
38 | 40 | return $this->value->accepts($value); |
39 | 41 | } |
40 | 42 | |
@@ -46,7 +48,8 @@ discard block |
||
46 | 48 | */ |
47 | 49 | public function convert($value) |
48 | 50 | { |
49 | - if ($this->value instanceof ValueInterface) { |
|
51 | + if ($this->value instanceof ValueInterface) |
|
52 | + { |
|
50 | 53 | return $this->value->convert($value); |
51 | 54 | } |
52 | 55 |
@@ -51,15 +51,15 @@ discard block |
||
51 | 51 | public function withValue($value): ?SpecificationInterface |
52 | 52 | { |
53 | 53 | $paginator = clone $this; |
54 | - if (!is_array($value)) { |
|
54 | + if (!is_array($value)){ |
|
55 | 55 | return $paginator; |
56 | 56 | } |
57 | 57 | |
58 | - if (isset($value['limit']) && $paginator->limitValue->accepts($value['limit'])) { |
|
58 | + if (isset($value['limit']) && $paginator->limitValue->accepts($value['limit'])){ |
|
59 | 59 | $paginator->limit = $paginator->limitValue->convert($value['limit']); |
60 | 60 | } |
61 | 61 | |
62 | - if (isset($value['page']) && is_numeric($value['page'])) { |
|
62 | + if (isset($value['page']) && is_numeric($value['page'])){ |
|
63 | 63 | $paginator->page = max((int)$value['page'], 1); |
64 | 64 | } |
65 | 65 | |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | public function getSpecifications(): array |
73 | 73 | { |
74 | 74 | $specifications = [new Limit($this->limit)]; |
75 | - if ($this->page > 1) { |
|
75 | + if ($this->page > 1){ |
|
76 | 76 | $specifications[] = new Offset($this->limit * ($this->page - 1)); |
77 | 77 | } |
78 | 78 |
@@ -51,15 +51,18 @@ discard block |
||
51 | 51 | public function withValue($value): ?SpecificationInterface |
52 | 52 | { |
53 | 53 | $paginator = clone $this; |
54 | - if (!is_array($value)) { |
|
54 | + if (!is_array($value)) |
|
55 | + { |
|
55 | 56 | return $paginator; |
56 | 57 | } |
57 | 58 | |
58 | - if (isset($value['limit']) && $paginator->limitValue->accepts($value['limit'])) { |
|
59 | + if (isset($value['limit']) && $paginator->limitValue->accepts($value['limit'])) |
|
60 | + { |
|
59 | 61 | $paginator->limit = $paginator->limitValue->convert($value['limit']); |
60 | 62 | } |
61 | 63 | |
62 | - if (isset($value['page']) && is_numeric($value['page'])) { |
|
64 | + if (isset($value['page']) && is_numeric($value['page'])) |
|
65 | + { |
|
63 | 66 | $paginator->page = max((int)$value['page'], 1); |
64 | 67 | } |
65 | 68 | |
@@ -72,7 +75,8 @@ discard block |
||
72 | 75 | public function getSpecifications(): array |
73 | 76 | { |
74 | 77 | $specifications = [new Limit($this->limit)]; |
75 | - if ($this->page > 1) { |
|
78 | + if ($this->page > 1) |
|
79 | + { |
|
76 | 80 | $specifications[] = new Offset($this->limit * ($this->page - 1)); |
77 | 81 | } |
78 | 82 |
@@ -41,25 +41,25 @@ |
||
41 | 41 | */ |
42 | 42 | public function compile($source, SpecificationInterface ...$specifications) |
43 | 43 | { |
44 | - if ($source === null) { |
|
44 | + if ($source === null){ |
|
45 | 45 | return null; |
46 | 46 | } |
47 | 47 | |
48 | - foreach ($specifications as $specification) { |
|
49 | - if ($specification instanceof SequenceInterface) { |
|
48 | + foreach ($specifications as $specification){ |
|
49 | + if ($specification instanceof SequenceInterface){ |
|
50 | 50 | return $this->compile($source, ...$specification->getSpecifications()); |
51 | 51 | } |
52 | 52 | |
53 | 53 | $isWritten = false; |
54 | - foreach ($this->writers as $writer) { |
|
54 | + foreach ($this->writers as $writer){ |
|
55 | 55 | $result = $writer->write($source, $specification, $this); |
56 | - if ($result !== null) { |
|
56 | + if ($result !== null){ |
|
57 | 57 | $source = $result; |
58 | 58 | $isWritten = true; |
59 | 59 | } |
60 | 60 | } |
61 | 61 | |
62 | - if ($isWritten) { |
|
62 | + if ($isWritten){ |
|
63 | 63 | continue; |
64 | 64 | } |
65 | 65 |
@@ -41,25 +41,31 @@ |
||
41 | 41 | */ |
42 | 42 | public function compile($source, SpecificationInterface ...$specifications) |
43 | 43 | { |
44 | - if ($source === null) { |
|
44 | + if ($source === null) |
|
45 | + { |
|
45 | 46 | return null; |
46 | 47 | } |
47 | 48 | |
48 | - foreach ($specifications as $specification) { |
|
49 | - if ($specification instanceof SequenceInterface) { |
|
49 | + foreach ($specifications as $specification) |
|
50 | + { |
|
51 | + if ($specification instanceof SequenceInterface) |
|
52 | + { |
|
50 | 53 | return $this->compile($source, ...$specification->getSpecifications()); |
51 | 54 | } |
52 | 55 | |
53 | 56 | $isWritten = false; |
54 | - foreach ($this->writers as $writer) { |
|
57 | + foreach ($this->writers as $writer) |
|
58 | + { |
|
55 | 59 | $result = $writer->write($source, $specification, $this); |
56 | - if ($result !== null) { |
|
60 | + if ($result !== null) |
|
61 | + { |
|
57 | 62 | $source = $result; |
58 | 63 | $isWritten = true; |
59 | 64 | } |
60 | 65 | } |
61 | 66 | |
62 | - if ($isWritten) { |
|
67 | + if ($isWritten) |
|
68 | + { |
|
63 | 69 | continue; |
64 | 70 | } |
65 | 71 |