@@ -29,7 +29,8 @@ discard block |
||
29 | 29 | public function listen(ReflectionClass $class): void |
30 | 30 | { |
31 | 31 | $attribute = $this->reader->firstClassMetadata($class, Prototyped::class); |
32 | - if ($attribute === null) { |
|
32 | + if ($attribute === null) |
|
33 | + { |
|
33 | 34 | return; |
34 | 35 | } |
35 | 36 | |
@@ -38,7 +39,8 @@ discard block |
||
38 | 39 | |
39 | 40 | public function finalize(): void |
40 | 41 | { |
41 | - foreach ($this->attributes as $property => $class) { |
|
42 | + foreach ($this->attributes as $property => $class) |
|
43 | + { |
|
42 | 44 | $this->prototype->bindProperty($property, $class); |
43 | 45 | } |
44 | 46 | } |
@@ -12,7 +12,8 @@ discard block |
||
12 | 12 | public function perform(): int |
13 | 13 | { |
14 | 14 | $bindings = $this->getRegistry()->getPropertyBindings(); |
15 | - if ($bindings === []) { |
|
15 | + if ($bindings === []) |
|
16 | + { |
|
16 | 17 | $this->comment('No prototype dependencies found.'); |
17 | 18 | |
18 | 19 | return self::SUCCESS; |
@@ -20,7 +21,8 @@ discard block |
||
20 | 21 | |
21 | 22 | $grid = $this->table(['Name:', 'Target:']); |
22 | 23 | |
23 | - foreach ($bindings as $binding) { |
|
24 | + foreach ($bindings as $binding) |
|
25 | + { |
|
24 | 26 | $grid->addRow([$binding->property, $binding->type->name()]); |
25 | 27 | } |
26 | 28 |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | $results = [$this->readProperties($class)]; |
35 | 35 | |
36 | 36 | $parent = $class->getParentClass(); |
37 | - while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])) { |
|
37 | + while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])) |
|
38 | + { |
|
38 | 39 | $results[] = $this->readProperties($parent); |
39 | 40 | $parent = $parent->getParentClass(); |
40 | 41 | } |
@@ -67,8 +68,10 @@ discard block |
||
67 | 68 | { |
68 | 69 | $result = []; |
69 | 70 | |
70 | - foreach ($properties as $target) { |
|
71 | - if ($target instanceof Throwable) { |
|
71 | + foreach ($properties as $target) |
|
72 | + { |
|
73 | + if ($target instanceof Throwable) |
|
74 | + { |
|
72 | 75 | $result[] = \sprintf( |
73 | 76 | '<fg=red>%s [f: %s, l: %s]</fg=red>', |
74 | 77 | $target->getMessage(), |
@@ -78,7 +81,8 @@ discard block |
||
78 | 81 | continue; |
79 | 82 | } |
80 | 83 | |
81 | - if ($target === null) { |
|
84 | + if ($target === null) |
|
85 | + { |
|
82 | 86 | $result[] = '<fg=yellow>undefined</fg=yellow>'; |
83 | 87 | continue; |
84 | 88 | } |
@@ -94,16 +98,21 @@ discard block |
||
94 | 98 | */ |
95 | 99 | private function readProperties(\ReflectionClass $class): array |
96 | 100 | { |
97 | - if (isset($this->cache[$class->getFileName()])) { |
|
101 | + if (isset($this->cache[$class->getFileName()])) |
|
102 | + { |
|
98 | 103 | $proto = $this->cache[$class->getFileName()]; |
99 | - } else { |
|
104 | + } |
|
105 | + else |
|
106 | + { |
|
100 | 107 | $proto = $this->getExtractor()->getPrototypeProperties(\file_get_contents($class->getFileName())); |
101 | 108 | $this->cache[$class->getFileName()] = $proto; |
102 | 109 | } |
103 | 110 | |
104 | 111 | $result = []; |
105 | - foreach ($proto as $name) { |
|
106 | - if (!isset($result[$name])) { |
|
112 | + foreach ($proto as $name) |
|
113 | + { |
|
114 | + if (!isset($result[$name])) |
|
115 | + { |
|
107 | 116 | $result[$name] = $this->getRegistry()->resolveProperty($name); |
108 | 117 | } |
109 | 118 | } |
@@ -120,7 +129,8 @@ discard block |
||
120 | 129 | */ |
121 | 130 | private function reverse(array $results): \Generator |
122 | 131 | { |
123 | - foreach (\array_reverse($results) as $result) { |
|
132 | + foreach (\array_reverse($results) as $result) |
|
133 | + { |
|
124 | 134 | yield from $result; |
125 | 135 | } |
126 | 136 | } |
@@ -124,30 +124,40 @@ |
||
124 | 124 | { |
125 | 125 | $registry = new PrototypeRegistry($container); |
126 | 126 | |
127 | - foreach ($config->getBindings() as $property => $shortcut) { |
|
128 | - if (\is_array($shortcut) && isset($shortcut['resolve'])) { |
|
129 | - if (isset($shortcut['with'])) { |
|
127 | + foreach ($config->getBindings() as $property => $shortcut) |
|
128 | + { |
|
129 | + if (\is_array($shortcut) && isset($shortcut['resolve'])) |
|
130 | + { |
|
131 | + if (isset($shortcut['with'])) |
|
132 | + { |
|
130 | 133 | // check dependencies |
131 | - foreach ($shortcut['with'] as $dep) { |
|
132 | - if (!\class_exists($dep, true) && !\interface_exists($dep, true)) { |
|
134 | + foreach ($shortcut['with'] as $dep) |
|
135 | + { |
|
136 | + if (!\class_exists($dep, true) && !\interface_exists($dep, true)) |
|
137 | + { |
|
133 | 138 | continue 2; |
134 | 139 | } |
135 | 140 | } |
136 | 141 | } |
137 | 142 | |
138 | - try { |
|
143 | + try |
|
144 | + { |
|
139 | 145 | $target = $container->get($shortcut['resolve']); |
140 | - if (\is_object($target)) { |
|
146 | + if (\is_object($target)) |
|
147 | + { |
|
141 | 148 | $registry->bindProperty($property, $target::class); |
142 | 149 | } |
143 | - } catch (ContainerExceptionInterface) { |
|
150 | + } |
|
151 | + catch (ContainerExceptionInterface) |
|
152 | + { |
|
144 | 153 | continue; |
145 | 154 | } |
146 | 155 | |
147 | 156 | continue; |
148 | 157 | } |
149 | 158 | |
150 | - if (\is_string($shortcut) && (\class_exists($shortcut, true) || \interface_exists($shortcut, true))) { |
|
159 | + if (\is_string($shortcut) && (\class_exists($shortcut, true) || \interface_exists($shortcut, true))) |
|
160 | + { |
|
151 | 161 | $registry->bindProperty($property, $shortcut); |
152 | 162 | } |
153 | 163 | } |
@@ -23,7 +23,8 @@ discard block |
||
23 | 23 | public function perform(Writer $writer): int |
24 | 24 | { |
25 | 25 | $dependencies = $this->getRegistry()->getPropertyBindings(); |
26 | - if ($dependencies === []) { |
|
26 | + if ($dependencies === []) |
|
27 | + { |
|
27 | 28 | $this->comment('No prototyped shortcuts found.'); |
28 | 29 | |
29 | 30 | return self::SUCCESS; |
@@ -35,11 +36,14 @@ discard block |
||
35 | 36 | $file = FileDeclaration::fromReflection($ref); |
36 | 37 | $trait = $file->getTrait(PrototypeTrait::class); |
37 | 38 | |
38 | - try { |
|
39 | + try |
|
40 | + { |
|
39 | 41 | $this->buildAnnotation($trait, $dependencies); |
40 | 42 | |
41 | 43 | $writer->write($ref->getFileName(), $file); |
42 | - } catch (\Throwable $e) { |
|
44 | + } |
|
45 | + catch (\Throwable $e) |
|
46 | + { |
|
43 | 47 | $this->write('<fg=red>' . $e->getMessage() . "</fg=red>\n"); |
44 | 48 | |
45 | 49 | return self::FAILURE; |
@@ -47,10 +51,12 @@ discard block |
||
47 | 51 | |
48 | 52 | $this->write("<fg=green>complete</fg=green>\n"); |
49 | 53 | |
50 | - if ($this->isVerbose()) { |
|
54 | + if ($this->isVerbose()) |
|
55 | + { |
|
51 | 56 | $grid = $this->table(['Property:', 'Target:']); |
52 | 57 | |
53 | - foreach ($dependencies as $dependency) { |
|
58 | + foreach ($dependencies as $dependency) |
|
59 | + { |
|
54 | 60 | $grid->addRow([$dependency->var, $dependency->type->fullName]); |
55 | 61 | } |
56 | 62 | |
@@ -66,7 +72,8 @@ discard block |
||
66 | 72 | $trait->addComment('This DocComment is auto-generated, do not edit or commit this file to repository.'); |
67 | 73 | $trait->addComment(''); |
68 | 74 | |
69 | - foreach ($dependencies as $dependency) { |
|
75 | + foreach ($dependencies as $dependency) |
|
76 | + { |
|
70 | 77 | $trait->addComment(\sprintf('@property \\%s $%s', $dependency->type->fullName, $dependency->var)); |
71 | 78 | } |
72 | 79 | } |