@@ -14,19 +14,19 @@ |
||
14 | 14 | */ |
15 | 15 | final class RemoveUse extends NodeVisitorAbstract |
16 | 16 | { |
17 | - public function leaveNode(Node $node): int|Node|null |
|
17 | + public function leaveNode(Node $node): int | Node | null |
|
18 | 18 | { |
19 | - if (!$node instanceof Node\Stmt\Use_) { |
|
19 | + if (!$node instanceof Node\Stmt\Use_){ |
|
20 | 20 | return null; |
21 | 21 | } |
22 | 22 | |
23 | - foreach ($node->uses as $index => $use) { |
|
24 | - if ($use->name->toString() === PrototypeTrait::class) { |
|
23 | + foreach ($node->uses as $index => $use){ |
|
24 | + if ($use->name->toString() === PrototypeTrait::class){ |
|
25 | 25 | unset($node->uses[$index]); |
26 | 26 | } |
27 | 27 | } |
28 | 28 | |
29 | - if (empty($node->uses)) { |
|
29 | + if (empty($node->uses)){ |
|
30 | 30 | return NodeTraverser::REMOVE_NODE; |
31 | 31 | } |
32 | 32 |
@@ -16,17 +16,21 @@ |
||
16 | 16 | { |
17 | 17 | public function leaveNode(Node $node): int|Node|null |
18 | 18 | { |
19 | - if (!$node instanceof Node\Stmt\Use_) { |
|
19 | + if (!$node instanceof Node\Stmt\Use_) |
|
20 | + { |
|
20 | 21 | return null; |
21 | 22 | } |
22 | 23 | |
23 | - foreach ($node->uses as $index => $use) { |
|
24 | - if ($use->name->toString() === PrototypeTrait::class) { |
|
24 | + foreach ($node->uses as $index => $use) |
|
25 | + { |
|
26 | + if ($use->name->toString() === PrototypeTrait::class) |
|
27 | + { |
|
25 | 28 | unset($node->uses[$index]); |
26 | 29 | } |
27 | 30 | } |
28 | 31 | |
29 | - if (empty($node->uses)) { |
|
32 | + if (empty($node->uses)) |
|
33 | + { |
|
30 | 34 | return NodeTraverser::REMOVE_NODE; |
31 | 35 | } |
32 | 36 |
@@ -14,21 +14,21 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function find(array $sequences, int $originSequence): int |
16 | 16 | { |
17 | - if (empty($sequences) || $originSequence > \max($sequences)) { |
|
17 | + if (empty($sequences) || $originSequence > \max($sequences)){ |
|
18 | 18 | return $originSequence; |
19 | 19 | } |
20 | 20 | |
21 | 21 | $gaps = $this->skippedSequences($sequences); |
22 | 22 | |
23 | - if (isset($gaps[$originSequence])) { |
|
23 | + if (isset($gaps[$originSequence])){ |
|
24 | 24 | return $originSequence; |
25 | 25 | } |
26 | 26 | |
27 | 27 | //we do not add "1" as postfix: $var, $var2, $var3, etc |
28 | 28 | unset($gaps[1]); |
29 | - if (empty($gaps)) { |
|
29 | + if (empty($gaps)){ |
|
30 | 30 | $max = \max($sequences); |
31 | - if ($max === 0) { |
|
31 | + if ($max === 0){ |
|
32 | 32 | return 2; |
33 | 33 | } |
34 | 34 | |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | { |
43 | 43 | $skipped = []; |
44 | 44 | $max = \max($sequences); |
45 | - for ($i = 0; $i < $max; $i++) { |
|
46 | - if (!\in_array($i, $sequences, true)) { |
|
45 | + for ($i = 0; $i < $max; $i++){ |
|
46 | + if (!\in_array($i, $sequences, true)){ |
|
47 | 47 | $skipped[$i] = $i; |
48 | 48 | } |
49 | 49 | } |
@@ -14,21 +14,25 @@ discard block |
||
14 | 14 | */ |
15 | 15 | public function find(array $sequences, int $originSequence): int |
16 | 16 | { |
17 | - if (empty($sequences) || $originSequence > \max($sequences)) { |
|
17 | + if (empty($sequences) || $originSequence > \max($sequences)) |
|
18 | + { |
|
18 | 19 | return $originSequence; |
19 | 20 | } |
20 | 21 | |
21 | 22 | $gaps = $this->skippedSequences($sequences); |
22 | 23 | |
23 | - if (isset($gaps[$originSequence])) { |
|
24 | + if (isset($gaps[$originSequence])) |
|
25 | + { |
|
24 | 26 | return $originSequence; |
25 | 27 | } |
26 | 28 | |
27 | 29 | //we do not add "1" as postfix: $var, $var2, $var3, etc |
28 | 30 | unset($gaps[1]); |
29 | - if (empty($gaps)) { |
|
31 | + if (empty($gaps)) |
|
32 | + { |
|
30 | 33 | $max = \max($sequences); |
31 | - if ($max === 0) { |
|
34 | + if ($max === 0) |
|
35 | + { |
|
32 | 36 | return 2; |
33 | 37 | } |
34 | 38 | |
@@ -42,8 +46,10 @@ discard block |
||
42 | 46 | { |
43 | 47 | $skipped = []; |
44 | 48 | $max = \max($sequences); |
45 | - for ($i = 0; $i < $max; $i++) { |
|
46 | - if (!\in_array($i, $sequences, true)) { |
|
49 | + for ($i = 0; $i < $max; $i++) |
|
50 | + { |
|
51 | + if (!\in_array($i, $sequences, true)) |
|
52 | + { |
|
47 | 53 | $skipped[$i] = $i; |
48 | 54 | } |
49 | 55 | } |
@@ -46,7 +46,8 @@ discard block |
||
46 | 46 | public function perform(): int |
47 | 47 | { |
48 | 48 | $prototyped = $this->locator->getTargetClasses(); |
49 | - if ($prototyped === []) { |
|
49 | + if ($prototyped === []) |
|
50 | + { |
|
50 | 51 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
51 | 52 | |
52 | 53 | return self::SUCCESS; |
@@ -54,18 +55,23 @@ discard block |
||
54 | 55 | |
55 | 56 | $targets = []; |
56 | 57 | |
57 | - foreach ($prototyped as $class) { |
|
58 | + foreach ($prototyped as $class) |
|
59 | + { |
|
58 | 60 | $proto = $this->getPrototypeProperties($class, $prototyped); |
59 | - if (empty($proto)) { |
|
61 | + if (empty($proto)) |
|
62 | + { |
|
60 | 63 | $modified = $this->modify($class, $proto); |
61 | - if ($modified !== null) { |
|
64 | + if ($modified !== null) |
|
65 | + { |
|
62 | 66 | $targets[] = $modified; |
63 | 67 | } |
64 | 68 | continue; |
65 | 69 | } |
66 | 70 | |
67 | - foreach ($proto as $target) { |
|
68 | - if ($target instanceof \Throwable) { |
|
71 | + foreach ($proto as $target) |
|
72 | + { |
|
73 | + if ($target instanceof \Throwable) |
|
74 | + { |
|
69 | 75 | $targets[] = [ |
70 | 76 | $class->getName(), |
71 | 77 | $target->getMessage(), |
@@ -74,7 +80,8 @@ discard block |
||
74 | 80 | continue 2; |
75 | 81 | } |
76 | 82 | |
77 | - if ($target === null) { |
|
83 | + if ($target === null) |
|
84 | + { |
|
78 | 85 | continue 2; |
79 | 86 | } |
80 | 87 | } |
@@ -82,14 +89,17 @@ discard block |
||
82 | 89 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
83 | 90 | |
84 | 91 | $modified = $this->modify($class, $proto); |
85 | - if ($modified !== null) { |
|
92 | + if ($modified !== null) |
|
93 | + { |
|
86 | 94 | $targets[] = $modified; |
87 | 95 | } |
88 | 96 | } |
89 | 97 | |
90 | - if (!empty($targets)) { |
|
98 | + if (!empty($targets)) |
|
99 | + { |
|
91 | 100 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
92 | - foreach ($targets as $target) { |
|
101 | + foreach ($targets as $target) |
|
102 | + { |
|
93 | 103 | $grid->addRow($target); |
94 | 104 | } |
95 | 105 | |
@@ -102,7 +112,8 @@ discard block |
||
102 | 112 | private function modify(\ReflectionClass $class, array $proto): ?array |
103 | 113 | { |
104 | 114 | $classDefinition = $this->extractor->extract($class->getFileName(), $proto); |
105 | - try { |
|
115 | + try |
|
116 | + { |
|
106 | 117 | $modified = $this->injector->injectDependencies( |
107 | 118 | \file_get_contents($class->getFileName()), |
108 | 119 | $classDefinition, |
@@ -114,7 +125,9 @@ discard block |
||
114 | 125 | \file_put_contents($class->getFileName(), $modified); |
115 | 126 | |
116 | 127 | return null; |
117 | - } catch (\Throwable $e) { |
|
128 | + } |
|
129 | + catch (\Throwable $e) |
|
130 | + { |
|
118 | 131 | return [$class->getName(), $e->getMessage(), \sprintf('%s:L%s', $e->getFile(), $e->getLine())]; |
119 | 132 | } |
120 | 133 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | public function perform(): int |
36 | 36 | { |
37 | 37 | $prototyped = $this->locator->getTargetClasses(); |
38 | - if ($prototyped === []) { |
|
38 | + if ($prototyped === []){ |
|
39 | 39 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
40 | 40 | |
41 | 41 | return self::SUCCESS; |
@@ -43,18 +43,18 @@ discard block |
||
43 | 43 | |
44 | 44 | $targets = []; |
45 | 45 | |
46 | - foreach ($prototyped as $class) { |
|
46 | + foreach ($prototyped as $class){ |
|
47 | 47 | $proto = $this->getPrototypeProperties($class, $prototyped); |
48 | - if (empty($proto)) { |
|
48 | + if (empty($proto)){ |
|
49 | 49 | $modified = $this->modify($class, $proto); |
50 | - if ($modified !== null) { |
|
50 | + if ($modified !== null){ |
|
51 | 51 | $targets[] = $modified; |
52 | 52 | } |
53 | 53 | continue; |
54 | 54 | } |
55 | 55 | |
56 | - foreach ($proto as $target) { |
|
57 | - if ($target instanceof \Throwable) { |
|
56 | + foreach ($proto as $target){ |
|
57 | + if ($target instanceof \Throwable){ |
|
58 | 58 | $targets[] = [ |
59 | 59 | $class->getName(), |
60 | 60 | $target->getMessage(), |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | continue 2; |
64 | 64 | } |
65 | 65 | |
66 | - if ($target === null) { |
|
66 | + if ($target === null){ |
|
67 | 67 | continue 2; |
68 | 68 | } |
69 | 69 | } |
@@ -71,14 +71,14 @@ discard block |
||
71 | 71 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
72 | 72 | |
73 | 73 | $modified = $this->modify($class, $proto); |
74 | - if ($modified !== null) { |
|
74 | + if ($modified !== null){ |
|
75 | 75 | $targets[] = $modified; |
76 | 76 | } |
77 | 77 | } |
78 | 78 | |
79 | - if (!empty($targets)) { |
|
79 | + if (!empty($targets)){ |
|
80 | 80 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
81 | - foreach ($targets as $target) { |
|
81 | + foreach ($targets as $target){ |
|
82 | 82 | $grid->addRow($target); |
83 | 83 | } |
84 | 84 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | private function modify(\ReflectionClass $class, array $proto): ?array |
92 | 92 | { |
93 | 93 | $classDefinition = $this->extractor->extract($class->getFileName(), $proto); |
94 | - try { |
|
94 | + try{ |
|
95 | 95 | $modified = $this->injector->injectDependencies( |
96 | 96 | \file_get_contents($class->getFileName()), |
97 | 97 | $classDefinition, |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | \file_put_contents($class->getFileName(), $modified); |
102 | 102 | |
103 | 103 | return null; |
104 | - } catch (\Throwable $e) { |
|
104 | + }catch (\Throwable $e){ |
|
105 | 105 | return [$class->getName(), $e->getMessage(), \sprintf('%s:L%s', $e->getFile(), $e->getLine())]; |
106 | 106 | } |
107 | 107 | } |
@@ -28,7 +28,8 @@ |
||
28 | 28 | |
29 | 29 | protected function getMutator(string $field, string $type): mixed |
30 | 30 | { |
31 | - if (isset($this->schema[ModelSchema::MUTATORS][$type][$field])) { |
|
31 | + if (isset($this->schema[ModelSchema::MUTATORS][$type][$field])) |
|
32 | + { |
|
32 | 33 | return $this->schema[ModelSchema::MUTATORS][$type][$field]; |
33 | 34 | } |
34 | 35 |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | public function __construct( |
13 | 13 | array $data, |
14 | 14 | private array $schema, |
15 | - ) { |
|
15 | + ){ |
|
16 | 16 | parent::__construct($data); |
17 | 17 | } |
18 | 18 | |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | |
29 | 29 | protected function getMutator(string $field, string $type): mixed |
30 | 30 | { |
31 | - if (isset($this->schema[ModelSchema::MUTATORS][$type][$field])) { |
|
31 | + if (isset($this->schema[ModelSchema::MUTATORS][$type][$field])){ |
|
32 | 32 | return $this->schema[ModelSchema::MUTATORS][$type][$field]; |
33 | 33 | } |
34 | 34 |
@@ -16,13 +16,13 @@ |
||
16 | 16 | { |
17 | 17 | $traits = []; |
18 | 18 | |
19 | - do { |
|
19 | + do{ |
|
20 | 20 | $traits = \array_merge(\class_uses($class), $traits); |
21 | 21 | $class = \get_parent_class($class); |
22 | - } while ($class !== false); |
|
22 | + }while ($class !== false); |
|
23 | 23 | |
24 | 24 | //Traits from traits |
25 | - foreach (\array_flip($traits) as $trait) { |
|
25 | + foreach (\array_flip($traits) as $trait){ |
|
26 | 26 | $traits = \array_merge(\class_uses($trait), $traits); |
27 | 27 | } |
28 | 28 |
@@ -16,13 +16,15 @@ |
||
16 | 16 | { |
17 | 17 | $traits = []; |
18 | 18 | |
19 | - do { |
|
19 | + do |
|
20 | + { |
|
20 | 21 | $traits = \array_merge(\class_uses($class), $traits); |
21 | 22 | $class = \get_parent_class($class); |
22 | 23 | } while ($class !== false); |
23 | 24 | |
24 | 25 | //Traits from traits |
25 | - foreach (\array_flip($traits) as $trait) { |
|
26 | + foreach (\array_flip($traits) as $trait) |
|
27 | + { |
|
26 | 28 | $traits = \array_merge(\class_uses($trait), $traits); |
27 | 29 | } |
28 | 30 |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | public function getInvocations(\ReflectionFunctionAbstract $function): array |
22 | 22 | { |
23 | 23 | $result = []; |
24 | - foreach ($this->availableInvocations($function->getName()) as $invocation) { |
|
25 | - if ($this->isTargeted($invocation, $function)) { |
|
24 | + foreach ($this->availableInvocations($function->getName()) as $invocation){ |
|
25 | + if ($this->isTargeted($invocation, $function)){ |
|
26 | 26 | $result[] = $invocation; |
27 | 27 | } |
28 | 28 | } |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | protected function availableInvocations(string $signature = ''): \Generator |
40 | 40 | { |
41 | 41 | $signature = \strtolower(\trim($signature, '\\')); |
42 | - foreach ($this->availableReflections() as $reflection) { |
|
43 | - foreach ($reflection->getInvocations() as $invocation) { |
|
42 | + foreach ($this->availableReflections() as $reflection){ |
|
43 | + foreach ($reflection->getInvocations() as $invocation){ |
|
44 | 44 | if ( |
45 | 45 | !empty($signature) |
46 | 46 | && \strtolower(\trim($invocation->getName(), '\\')) !== $signature |
47 | - ) { |
|
47 | + ){ |
|
48 | 48 | continue; |
49 | 49 | } |
50 | 50 | |
@@ -55,14 +55,14 @@ discard block |
||
55 | 55 | |
56 | 56 | protected function isTargeted(ReflectionInvocation $invocation, \ReflectionFunctionAbstract $function): bool |
57 | 57 | { |
58 | - if ($function instanceof \ReflectionFunction) { |
|
58 | + if ($function instanceof \ReflectionFunction){ |
|
59 | 59 | return !$invocation->isMethod(); |
60 | 60 | } |
61 | 61 | |
62 | - try { |
|
62 | + try{ |
|
63 | 63 | $reflection = $this->classReflection($invocation->getClass()); |
64 | - } catch (LocatorException $e) { |
|
65 | - if ($this->debug) { |
|
64 | + }catch (LocatorException $e){ |
|
65 | + if ($this->debug){ |
|
66 | 66 | throw $e; |
67 | 67 | } |
68 | 68 | |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | */ |
75 | 75 | $target = $function->getDeclaringClass(); |
76 | 76 | |
77 | - if ($target->isTrait()) { |
|
77 | + if ($target->isTrait()){ |
|
78 | 78 | //Let's compare traits |
79 | 79 | return \in_array($target->getName(), $this->fetchTraits($invocation->getClass())); |
80 | 80 | } |
@@ -21,8 +21,10 @@ discard block |
||
21 | 21 | public function getInvocations(\ReflectionFunctionAbstract $function): array |
22 | 22 | { |
23 | 23 | $result = []; |
24 | - foreach ($this->availableInvocations($function->getName()) as $invocation) { |
|
25 | - if ($this->isTargeted($invocation, $function)) { |
|
24 | + foreach ($this->availableInvocations($function->getName()) as $invocation) |
|
25 | + { |
|
26 | + if ($this->isTargeted($invocation, $function)) |
|
27 | + { |
|
26 | 28 | $result[] = $invocation; |
27 | 29 | } |
28 | 30 | } |
@@ -39,8 +41,10 @@ discard block |
||
39 | 41 | protected function availableInvocations(string $signature = ''): \Generator |
40 | 42 | { |
41 | 43 | $signature = \strtolower(\trim($signature, '\\')); |
42 | - foreach ($this->availableReflections() as $reflection) { |
|
43 | - foreach ($reflection->getInvocations() as $invocation) { |
|
44 | + foreach ($this->availableReflections() as $reflection) |
|
45 | + { |
|
46 | + foreach ($reflection->getInvocations() as $invocation) |
|
47 | + { |
|
44 | 48 | if ( |
45 | 49 | !empty($signature) |
46 | 50 | && \strtolower(\trim($invocation->getName(), '\\')) !== $signature |
@@ -55,14 +59,19 @@ discard block |
||
55 | 59 | |
56 | 60 | protected function isTargeted(ReflectionInvocation $invocation, \ReflectionFunctionAbstract $function): bool |
57 | 61 | { |
58 | - if ($function instanceof \ReflectionFunction) { |
|
62 | + if ($function instanceof \ReflectionFunction) |
|
63 | + { |
|
59 | 64 | return !$invocation->isMethod(); |
60 | 65 | } |
61 | 66 | |
62 | - try { |
|
67 | + try |
|
68 | + { |
|
63 | 69 | $reflection = $this->classReflection($invocation->getClass()); |
64 | - } catch (LocatorException $e) { |
|
65 | - if ($this->debug) { |
|
70 | + } |
|
71 | + catch (LocatorException $e) |
|
72 | + { |
|
73 | + if ($this->debug) |
|
74 | + { |
|
66 | 75 | throw $e; |
67 | 76 | } |
68 | 77 | |
@@ -74,7 +83,8 @@ discard block |
||
74 | 83 | */ |
75 | 84 | $target = $function->getDeclaringClass(); |
76 | 85 | |
77 | - if ($target->isTrait()) { |
|
86 | + if ($target->isTrait()) |
|
87 | + { |
|
78 | 88 | //Let's compare traits |
79 | 89 | return \in_array($target->getName(), $this->fetchTraits($invocation->getClass())); |
80 | 90 | } |
@@ -17,5 +17,5 @@ |
||
17 | 17 | * results. |
18 | 18 | * @return \ReflectionClass[] |
19 | 19 | */ |
20 | - public function getScopedClasses(string $scope, object|string|null $target = null): array; |
|
20 | + public function getScopedClasses(string $scope, object | string | null $target = null): array; |
|
21 | 21 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | return new \DateTimeImmutable(); |
22 | 22 | } |
23 | 23 | |
24 | - private function ttlToTimestamp(null|int|\DateInterval|\DateTimeInterface $ttl = null): int |
|
24 | + private function ttlToTimestamp(null | int | \DateInterval | \DateTimeInterface $ttl = null): int |
|
25 | 25 | { |
26 | 26 | return match (true) { |
27 | 27 | $ttl instanceof \DateInterval => $this->now()->add($ttl)->getTimestamp(), |
@@ -17,7 +17,7 @@ |
||
17 | 17 | |
18 | 18 | public function load(string $path): Source |
19 | 19 | { |
20 | - if (!\array_key_exists($path, $this->paths)) { |
|
20 | + if (!\array_key_exists($path, $this->paths)){ |
|
21 | 21 | throw new LoaderException(\sprintf('Unable to load path `%s`', $path)); |
22 | 22 | } |
23 | 23 |
@@ -17,7 +17,8 @@ |
||
17 | 17 | |
18 | 18 | public function load(string $path): Source |
19 | 19 | { |
20 | - if (!\array_key_exists($path, $this->paths)) { |
|
20 | + if (!\array_key_exists($path, $this->paths)) |
|
21 | + { |
|
21 | 22 | throw new LoaderException(\sprintf('Unable to load path `%s`', $path)); |
22 | 23 | } |
23 | 24 |