@@ -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)]); |
@@ -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 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | NodeExtractor $extractor, |
| 42 | 42 | PrototypeRegistry $registry, |
| 43 | 43 | Injector $injector |
| 44 | - ) { |
|
| 44 | + ){ |
|
| 45 | 45 | parent::__construct($locator, $extractor, $registry); |
| 46 | 46 | $this->injector = $injector; |
| 47 | 47 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | public function perform(): void |
| 56 | 56 | { |
| 57 | 57 | $prototyped = $this->locator->getTargetClasses(); |
| 58 | - if ($prototyped === []) { |
|
| 58 | + if ($prototyped === []){ |
|
| 59 | 59 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 60 | 60 | |
| 61 | 61 | return; |
@@ -63,18 +63,18 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | $targets = []; |
| 65 | 65 | |
| 66 | - foreach ($prototyped as $class) { |
|
| 66 | + foreach ($prototyped as $class){ |
|
| 67 | 67 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 68 | - if (empty($proto)) { |
|
| 68 | + if (empty($proto)){ |
|
| 69 | 69 | $modified = $this->modify($class, $proto); |
| 70 | - if ($modified !== null) { |
|
| 70 | + if ($modified !== null){ |
|
| 71 | 71 | $targets[] = $modified; |
| 72 | 72 | } |
| 73 | 73 | continue; |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - foreach ($proto as $target) { |
|
| 77 | - if ($target instanceof \Throwable) { |
|
| 76 | + foreach ($proto as $target){ |
|
| 77 | + if ($target instanceof \Throwable){ |
|
| 78 | 78 | $targets[] = [ |
| 79 | 79 | $class->getName(), |
| 80 | 80 | $target->getMessage(), |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | continue 2; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if ($target === null) { |
|
| 86 | + if ($target === null){ |
|
| 87 | 87 | continue 2; |
| 88 | 88 | } |
| 89 | 89 | } |
@@ -91,14 +91,14 @@ discard block |
||
| 91 | 91 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
| 92 | 92 | |
| 93 | 93 | $modified = $this->modify($class, $proto); |
| 94 | - if ($modified !== null) { |
|
| 94 | + if ($modified !== null){ |
|
| 95 | 95 | $targets[] = $modified; |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - if (!empty($targets)) { |
|
| 99 | + if (!empty($targets)){ |
|
| 100 | 100 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 101 | - foreach ($targets as $target) { |
|
| 101 | + foreach ($targets as $target){ |
|
| 102 | 102 | $grid->addRow($target); |
| 103 | 103 | } |
| 104 | 104 | |
@@ -109,7 +109,7 @@ discard block |
||
| 109 | 109 | private function modify(\ReflectionClass $class, array $proto): ?array |
| 110 | 110 | { |
| 111 | 111 | $classDefinition = $this->extractor->extract($class->getFilename(), $proto); |
| 112 | - try { |
|
| 112 | + try{ |
|
| 113 | 113 | $modified = $this->injector->injectDependencies( |
| 114 | 114 | file_get_contents($class->getFileName()), |
| 115 | 115 | $classDefinition, |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | file_put_contents($class->getFileName(), $modified); |
| 122 | 122 | return null; |
| 123 | - } catch (\Throwable $e) { |
|
| 123 | + }catch (\Throwable $e){ |
|
| 124 | 124 | return [$class->getName(), $e->getMessage(), "{$e->getFile()}:L{$e->getLine()}"]; |
| 125 | 125 | } |
| 126 | 126 | } |
@@ -55,7 +55,8 @@ discard block |
||
| 55 | 55 | public function perform(): void |
| 56 | 56 | { |
| 57 | 57 | $prototyped = $this->locator->getTargetClasses(); |
| 58 | - if ($prototyped === []) { |
|
| 58 | + if ($prototyped === []) |
|
| 59 | + { |
|
| 59 | 60 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 60 | 61 | |
| 61 | 62 | return; |
@@ -63,18 +64,23 @@ discard block |
||
| 63 | 64 | |
| 64 | 65 | $targets = []; |
| 65 | 66 | |
| 66 | - foreach ($prototyped as $class) { |
|
| 67 | + foreach ($prototyped as $class) |
|
| 68 | + { |
|
| 67 | 69 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 68 | - if (empty($proto)) { |
|
| 70 | + if (empty($proto)) |
|
| 71 | + { |
|
| 69 | 72 | $modified = $this->modify($class, $proto); |
| 70 | - if ($modified !== null) { |
|
| 73 | + if ($modified !== null) |
|
| 74 | + { |
|
| 71 | 75 | $targets[] = $modified; |
| 72 | 76 | } |
| 73 | 77 | continue; |
| 74 | 78 | } |
| 75 | 79 | |
| 76 | - foreach ($proto as $target) { |
|
| 77 | - if ($target instanceof \Throwable) { |
|
| 80 | + foreach ($proto as $target) |
|
| 81 | + { |
|
| 82 | + if ($target instanceof \Throwable) |
|
| 83 | + { |
|
| 78 | 84 | $targets[] = [ |
| 79 | 85 | $class->getName(), |
| 80 | 86 | $target->getMessage(), |
@@ -83,7 +89,8 @@ discard block |
||
| 83 | 89 | continue 2; |
| 84 | 90 | } |
| 85 | 91 | |
| 86 | - if ($target === null) { |
|
| 92 | + if ($target === null) |
|
| 93 | + { |
|
| 87 | 94 | continue 2; |
| 88 | 95 | } |
| 89 | 96 | } |
@@ -91,14 +98,17 @@ discard block |
||
| 91 | 98 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
| 92 | 99 | |
| 93 | 100 | $modified = $this->modify($class, $proto); |
| 94 | - if ($modified !== null) { |
|
| 101 | + if ($modified !== null) |
|
| 102 | + { |
|
| 95 | 103 | $targets[] = $modified; |
| 96 | 104 | } |
| 97 | 105 | } |
| 98 | 106 | |
| 99 | - if (!empty($targets)) { |
|
| 107 | + if (!empty($targets)) |
|
| 108 | + { |
|
| 100 | 109 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 101 | - foreach ($targets as $target) { |
|
| 110 | + foreach ($targets as $target) |
|
| 111 | + { |
|
| 102 | 112 | $grid->addRow($target); |
| 103 | 113 | } |
| 104 | 114 | |
@@ -109,7 +119,8 @@ discard block |
||
| 109 | 119 | private function modify(\ReflectionClass $class, array $proto): ?array |
| 110 | 120 | { |
| 111 | 121 | $classDefinition = $this->extractor->extract($class->getFilename(), $proto); |
| 112 | - try { |
|
| 122 | + try |
|
| 123 | + { |
|
| 113 | 124 | $modified = $this->injector->injectDependencies( |
| 114 | 125 | file_get_contents($class->getFileName()), |
| 115 | 126 | $classDefinition, |
@@ -120,7 +131,9 @@ discard block |
||
| 120 | 131 | |
| 121 | 132 | file_put_contents($class->getFileName(), $modified); |
| 122 | 133 | return null; |
| 123 | - } catch (\Throwable $e) { |
|
| 134 | + } |
|
| 135 | + catch (\Throwable $e) |
|
| 136 | + { |
|
| 124 | 137 | return [$class->getName(), $e->getMessage(), "{$e->getFile()}:L{$e->getLine()}"]; |
| 125 | 138 | } |
| 126 | 139 | } |