@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | public function perform(): void |
| 23 | 23 | { |
| 24 | 24 | $prototyped = $this->locator->getTargetClasses(); |
| 25 | - if ($prototyped === []) { |
|
| 25 | + if ($prototyped === []){ |
|
| 26 | 26 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 27 | 27 | |
| 28 | 28 | return; |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 32 | 32 | |
| 33 | - foreach ($prototyped as $class) { |
|
| 33 | + foreach ($prototyped as $class){ |
|
| 34 | 34 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 35 | 35 | |
| 36 | 36 | $grid->addRow([$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]); |
@@ -22,7 +22,8 @@ discard block |
||
| 22 | 22 | public function perform(): void |
| 23 | 23 | { |
| 24 | 24 | $prototyped = $this->locator->getTargetClasses(); |
| 25 | - if ($prototyped === []) { |
|
| 25 | + if ($prototyped === []) |
|
| 26 | + { |
|
| 26 | 27 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 27 | 28 | |
| 28 | 29 | return; |
@@ -30,7 +31,8 @@ discard block |
||
| 30 | 31 | |
| 31 | 32 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 32 | 33 | |
| 33 | - foreach ($prototyped as $class) { |
|
| 34 | + foreach ($prototyped as $class) |
|
| 35 | + { |
|
| 34 | 36 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 35 | 37 | |
| 36 | 38 | $grid->addRow([$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | public function perform(): void |
| 33 | 33 | { |
| 34 | 34 | $prototyped = $this->locator->getTargetClasses(); |
| 35 | - if ($prototyped === []) { |
|
| 35 | + if ($prototyped === []){ |
|
| 36 | 36 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 37 | 37 | |
| 38 | 38 | return; |
@@ -40,18 +40,18 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | $targets = []; |
| 42 | 42 | |
| 43 | - foreach ($prototyped as $class) { |
|
| 43 | + foreach ($prototyped as $class){ |
|
| 44 | 44 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 45 | - if (empty($proto)) { |
|
| 45 | + if (empty($proto)){ |
|
| 46 | 46 | $modified = $this->modify($class, $proto); |
| 47 | - if ($modified !== null) { |
|
| 47 | + if ($modified !== null){ |
|
| 48 | 48 | $targets[] = $modified; |
| 49 | 49 | } |
| 50 | 50 | continue; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - foreach ($proto as $target) { |
|
| 54 | - if ($target instanceof \Throwable) { |
|
| 53 | + foreach ($proto as $target){ |
|
| 54 | + if ($target instanceof \Throwable){ |
|
| 55 | 55 | $targets[] = [ |
| 56 | 56 | $class->getName(), |
| 57 | 57 | $target->getMessage(), |
@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | continue 2; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - if ($target === null) { |
|
| 63 | + if ($target === null){ |
|
| 64 | 64 | continue 2; |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -68,14 +68,14 @@ discard block |
||
| 68 | 68 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
| 69 | 69 | |
| 70 | 70 | $modified = $this->modify($class, $proto); |
| 71 | - if ($modified !== null) { |
|
| 71 | + if ($modified !== null){ |
|
| 72 | 72 | $targets[] = $modified; |
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - if (!empty($targets)) { |
|
| 76 | + if (!empty($targets)){ |
|
| 77 | 77 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 78 | - foreach ($targets as $target) { |
|
| 78 | + foreach ($targets as $target){ |
|
| 79 | 79 | $grid->addRow($target); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | private function modify(\ReflectionClass $class, array $proto): ?array |
| 87 | 87 | { |
| 88 | 88 | $classDefinition = $this->extractor->extract($class->getFilename(), $proto); |
| 89 | - try { |
|
| 89 | + try{ |
|
| 90 | 90 | $modified = (new Injector())->injectDependencies( |
| 91 | 91 | file_get_contents($class->getFileName()), |
| 92 | 92 | $classDefinition, |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | |
| 96 | 96 | file_put_contents($class->getFileName(), $modified); |
| 97 | 97 | return null; |
| 98 | - } catch (\Throwable $e) { |
|
| 98 | + }catch (\Throwable $e){ |
|
| 99 | 99 | return [$class->getName(), $e->getMessage(), "{$e->getFile()}:L{$e->getLine()}"]; |
| 100 | 100 | } |
| 101 | 101 | } |
@@ -32,7 +32,8 @@ discard block |
||
| 32 | 32 | public function perform(): void |
| 33 | 33 | { |
| 34 | 34 | $prototyped = $this->locator->getTargetClasses(); |
| 35 | - if ($prototyped === []) { |
|
| 35 | + if ($prototyped === []) |
|
| 36 | + { |
|
| 36 | 37 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 37 | 38 | |
| 38 | 39 | return; |
@@ -40,18 +41,23 @@ discard block |
||
| 40 | 41 | |
| 41 | 42 | $targets = []; |
| 42 | 43 | |
| 43 | - foreach ($prototyped as $class) { |
|
| 44 | + foreach ($prototyped as $class) |
|
| 45 | + { |
|
| 44 | 46 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 45 | - if (empty($proto)) { |
|
| 47 | + if (empty($proto)) |
|
| 48 | + { |
|
| 46 | 49 | $modified = $this->modify($class, $proto); |
| 47 | - if ($modified !== null) { |
|
| 50 | + if ($modified !== null) |
|
| 51 | + { |
|
| 48 | 52 | $targets[] = $modified; |
| 49 | 53 | } |
| 50 | 54 | continue; |
| 51 | 55 | } |
| 52 | 56 | |
| 53 | - foreach ($proto as $target) { |
|
| 54 | - if ($target instanceof \Throwable) { |
|
| 57 | + foreach ($proto as $target) |
|
| 58 | + { |
|
| 59 | + if ($target instanceof \Throwable) |
|
| 60 | + { |
|
| 55 | 61 | $targets[] = [ |
| 56 | 62 | $class->getName(), |
| 57 | 63 | $target->getMessage(), |
@@ -60,7 +66,8 @@ discard block |
||
| 60 | 66 | continue 2; |
| 61 | 67 | } |
| 62 | 68 | |
| 63 | - if ($target === null) { |
|
| 69 | + if ($target === null) |
|
| 70 | + { |
|
| 64 | 71 | continue 2; |
| 65 | 72 | } |
| 66 | 73 | } |
@@ -68,14 +75,17 @@ discard block |
||
| 68 | 75 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
| 69 | 76 | |
| 70 | 77 | $modified = $this->modify($class, $proto); |
| 71 | - if ($modified !== null) { |
|
| 78 | + if ($modified !== null) |
|
| 79 | + { |
|
| 72 | 80 | $targets[] = $modified; |
| 73 | 81 | } |
| 74 | 82 | } |
| 75 | 83 | |
| 76 | - if (!empty($targets)) { |
|
| 84 | + if (!empty($targets)) |
|
| 85 | + { |
|
| 77 | 86 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 78 | - foreach ($targets as $target) { |
|
| 87 | + foreach ($targets as $target) |
|
| 88 | + { |
|
| 79 | 89 | $grid->addRow($target); |
| 80 | 90 | } |
| 81 | 91 | |
@@ -86,7 +96,8 @@ discard block |
||
| 86 | 96 | private function modify(\ReflectionClass $class, array $proto): ?array |
| 87 | 97 | { |
| 88 | 98 | $classDefinition = $this->extractor->extract($class->getFilename(), $proto); |
| 89 | - try { |
|
| 99 | + try |
|
| 100 | + { |
|
| 90 | 101 | $modified = (new Injector())->injectDependencies( |
| 91 | 102 | file_get_contents($class->getFileName()), |
| 92 | 103 | $classDefinition, |
@@ -95,7 +106,9 @@ discard block |
||
| 95 | 106 | |
| 96 | 107 | file_put_contents($class->getFileName(), $modified); |
| 97 | 108 | return null; |
| 98 | - } catch (\Throwable $e) { |
|
| 109 | + } |
|
| 110 | + catch (\Throwable $e) |
|
| 111 | + { |
|
| 99 | 112 | return [$class->getName(), $e->getMessage(), "{$e->getFile()}:L{$e->getLine()}"]; |
| 100 | 113 | } |
| 101 | 114 | } |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | $results = [$this->readProperties($class)]; |
| 59 | 59 | |
| 60 | 60 | $parent = $class->getParentClass(); |
| 61 | - while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])) { |
|
| 61 | + while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])){ |
|
| 62 | 62 | $results[] = $this->readProperties($parent); |
| 63 | 63 | $parent = $parent->getParentClass(); |
| 64 | 64 | } |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | { |
| 92 | 92 | $result = []; |
| 93 | 93 | |
| 94 | - foreach ($properties as $target) { |
|
| 95 | - if ($target instanceof \Throwable) { |
|
| 94 | + foreach ($properties as $target){ |
|
| 95 | + if ($target instanceof \Throwable){ |
|
| 96 | 96 | $result[] = sprintf( |
| 97 | 97 | '<fg=red>%s [f: %s, l: %s]</fg=red>', |
| 98 | 98 | $target->getMessage(), |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | continue; |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - if ($target === null) { |
|
| 105 | + if ($target === null){ |
|
| 106 | 106 | $result[] = '<fg=yellow>undefined</fg=yellow>'; |
| 107 | 107 | continue; |
| 108 | 108 | } |
@@ -115,16 +115,16 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | private function readProperties(\ReflectionClass $class): array |
| 117 | 117 | { |
| 118 | - if (isset($this->cache[$class->getFileName()])) { |
|
| 118 | + if (isset($this->cache[$class->getFileName()])){ |
|
| 119 | 119 | $proto = $this->cache[$class->getFileName()]; |
| 120 | - } else { |
|
| 120 | + }else{ |
|
| 121 | 121 | $proto = $this->getExtractor()->getPrototypeProperties(file_get_contents($class->getFilename())); |
| 122 | 122 | $this->cache[$class->getFileName()] = $proto; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | $result = []; |
| 126 | - foreach ($proto as $name) { |
|
| 127 | - if (!isset($result[$name])) { |
|
| 126 | + foreach ($proto as $name){ |
|
| 127 | + if (!isset($result[$name])){ |
|
| 128 | 128 | $result[$name] = $this->registry->resolveProperty($name); |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | private function reverse(array $results): ?\Generator |
| 136 | 136 | { |
| 137 | - foreach (array_reverse($results) as $result) { |
|
| 137 | + foreach (array_reverse($results) as $result){ |
|
| 138 | 138 | yield from $result; |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -58,7 +58,8 @@ discard block |
||
| 58 | 58 | $results = [$this->readProperties($class)]; |
| 59 | 59 | |
| 60 | 60 | $parent = $class->getParentClass(); |
| 61 | - while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])) { |
|
| 61 | + while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])) |
|
| 62 | + { |
|
| 62 | 63 | $results[] = $this->readProperties($parent); |
| 63 | 64 | $parent = $parent->getParentClass(); |
| 64 | 65 | } |
@@ -91,8 +92,10 @@ discard block |
||
| 91 | 92 | { |
| 92 | 93 | $result = []; |
| 93 | 94 | |
| 94 | - foreach ($properties as $target) { |
|
| 95 | - if ($target instanceof \Throwable) { |
|
| 95 | + foreach ($properties as $target) |
|
| 96 | + { |
|
| 97 | + if ($target instanceof \Throwable) |
|
| 98 | + { |
|
| 96 | 99 | $result[] = sprintf( |
| 97 | 100 | '<fg=red>%s [f: %s, l: %s]</fg=red>', |
| 98 | 101 | $target->getMessage(), |
@@ -102,7 +105,8 @@ discard block |
||
| 102 | 105 | continue; |
| 103 | 106 | } |
| 104 | 107 | |
| 105 | - if ($target === null) { |
|
| 108 | + if ($target === null) |
|
| 109 | + { |
|
| 106 | 110 | $result[] = '<fg=yellow>undefined</fg=yellow>'; |
| 107 | 111 | continue; |
| 108 | 112 | } |
@@ -115,16 +119,21 @@ discard block |
||
| 115 | 119 | |
| 116 | 120 | private function readProperties(\ReflectionClass $class): array |
| 117 | 121 | { |
| 118 | - if (isset($this->cache[$class->getFileName()])) { |
|
| 122 | + if (isset($this->cache[$class->getFileName()])) |
|
| 123 | + { |
|
| 119 | 124 | $proto = $this->cache[$class->getFileName()]; |
| 120 | - } else { |
|
| 125 | + } |
|
| 126 | + else |
|
| 127 | + { |
|
| 121 | 128 | $proto = $this->getExtractor()->getPrototypeProperties(file_get_contents($class->getFilename())); |
| 122 | 129 | $this->cache[$class->getFileName()] = $proto; |
| 123 | 130 | } |
| 124 | 131 | |
| 125 | 132 | $result = []; |
| 126 | - foreach ($proto as $name) { |
|
| 127 | - if (!isset($result[$name])) { |
|
| 133 | + foreach ($proto as $name) |
|
| 134 | + { |
|
| 135 | + if (!isset($result[$name])) |
|
| 136 | + { |
|
| 128 | 137 | $result[$name] = $this->registry->resolveProperty($name); |
| 129 | 138 | } |
| 130 | 139 | } |
@@ -134,7 +143,8 @@ discard block |
||
| 134 | 143 | |
| 135 | 144 | private function reverse(array $results): ?\Generator |
| 136 | 145 | { |
| 137 | - foreach (array_reverse($results) as $result) { |
|
| 146 | + foreach (array_reverse($results) as $result) |
|
| 147 | + { |
|
| 138 | 148 | yield from $result; |
| 139 | 149 | } |
| 140 | 150 | } |