@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | { |
| 12 | 12 | public function __construct( |
| 13 | 13 | private readonly Sequences $sequences |
| 14 | - ) { |
|
| 14 | + ){ |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | public function resolve(ClassNode $definition): void |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | private function getConstructorReservedNames(ClassNode $definition): array |
| 26 | 26 | { |
| 27 | 27 | $names = \array_values($definition->constructorVars); |
| 28 | - foreach ($definition->constructorParams as $param) { |
|
| 28 | + foreach ($definition->constructorParams as $param){ |
|
| 29 | 29 | $names[] = $param->name; |
| 30 | 30 | } |
| 31 | 31 | |
@@ -35,12 +35,12 @@ discard block |
||
| 35 | 35 | private function initiateCounters(array $names): array |
| 36 | 36 | { |
| 37 | 37 | $counters = []; |
| 38 | - foreach ($names as $name) { |
|
| 38 | + foreach ($names as $name){ |
|
| 39 | 39 | $name = $this->parseName($name); |
| 40 | 40 | |
| 41 | - if (isset($counters[$name->name])) { |
|
| 41 | + if (isset($counters[$name->name])){ |
|
| 42 | 42 | $counters[$name->name][$name->sequence] = $name->fullName(); |
| 43 | - } else { |
|
| 43 | + }else{ |
|
| 44 | 44 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
| 45 | 45 | } |
| 46 | 46 | } |
@@ -50,18 +50,18 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | private function addPostfixes(ClassNode $definition, array $counters): void |
| 52 | 52 | { |
| 53 | - foreach ($definition->dependencies as $dependency) { |
|
| 53 | + foreach ($definition->dependencies as $dependency){ |
|
| 54 | 54 | $name = $this->parseName($dependency->var); |
| 55 | - if (isset($counters[$name->name])) { |
|
| 55 | + if (isset($counters[$name->name])){ |
|
| 56 | 56 | $sequence = $this->sequences->find(\array_keys($counters[$name->name]), $name->sequence); |
| 57 | - if ($sequence !== $name->sequence) { |
|
| 57 | + if ($sequence !== $name->sequence){ |
|
| 58 | 58 | $name->sequence = $sequence; |
| 59 | 59 | |
| 60 | 60 | $dependency->var = $name->fullName(); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | $counters[$name->name][$sequence] = $name->fullName(); |
| 64 | - } else { |
|
| 64 | + }else{ |
|
| 65 | 65 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -69,9 +69,9 @@ discard block |
||
| 69 | 69 | |
| 70 | 70 | private function parseName(string $name): NameEntity |
| 71 | 71 | { |
| 72 | - if (\preg_match("/\d+$/", $name, $match)) { |
|
| 72 | + if (\preg_match("/\d+$/", $name, $match)){ |
|
| 73 | 73 | $sequence = (int)$match[0]; |
| 74 | - if ($sequence > 0) { |
|
| 74 | + if ($sequence > 0){ |
|
| 75 | 75 | return NameEntity::createWithSequence(Utils::trimTrailingDigits($name, $sequence), $sequence); |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -25,7 +25,8 @@ discard block |
||
| 25 | 25 | private function getConstructorReservedNames(ClassNode $definition): array |
| 26 | 26 | { |
| 27 | 27 | $names = \array_values($definition->constructorVars); |
| 28 | - foreach ($definition->constructorParams as $param) { |
|
| 28 | + foreach ($definition->constructorParams as $param) |
|
| 29 | + { |
|
| 29 | 30 | $names[] = $param->name; |
| 30 | 31 | } |
| 31 | 32 | |
@@ -35,12 +36,16 @@ discard block |
||
| 35 | 36 | private function initiateCounters(array $names): array |
| 36 | 37 | { |
| 37 | 38 | $counters = []; |
| 38 | - foreach ($names as $name) { |
|
| 39 | + foreach ($names as $name) |
|
| 40 | + { |
|
| 39 | 41 | $name = $this->parseName($name); |
| 40 | 42 | |
| 41 | - if (isset($counters[$name->name])) { |
|
| 43 | + if (isset($counters[$name->name])) |
|
| 44 | + { |
|
| 42 | 45 | $counters[$name->name][$name->sequence] = $name->fullName(); |
| 43 | - } else { |
|
| 46 | + } |
|
| 47 | + else |
|
| 48 | + { |
|
| 44 | 49 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
| 45 | 50 | } |
| 46 | 51 | } |
@@ -50,18 +55,23 @@ discard block |
||
| 50 | 55 | |
| 51 | 56 | private function addPostfixes(ClassNode $definition, array $counters): void |
| 52 | 57 | { |
| 53 | - foreach ($definition->dependencies as $dependency) { |
|
| 58 | + foreach ($definition->dependencies as $dependency) |
|
| 59 | + { |
|
| 54 | 60 | $name = $this->parseName($dependency->var); |
| 55 | - if (isset($counters[$name->name])) { |
|
| 61 | + if (isset($counters[$name->name])) |
|
| 62 | + { |
|
| 56 | 63 | $sequence = $this->sequences->find(\array_keys($counters[$name->name]), $name->sequence); |
| 57 | - if ($sequence !== $name->sequence) { |
|
| 64 | + if ($sequence !== $name->sequence) |
|
| 65 | + { |
|
| 58 | 66 | $name->sequence = $sequence; |
| 59 | 67 | |
| 60 | 68 | $dependency->var = $name->fullName(); |
| 61 | 69 | } |
| 62 | 70 | |
| 63 | 71 | $counters[$name->name][$sequence] = $name->fullName(); |
| 64 | - } else { |
|
| 72 | + } |
|
| 73 | + else |
|
| 74 | + { |
|
| 65 | 75 | $counters[$name->name] = [$name->sequence => $name->fullName()]; |
| 66 | 76 | } |
| 67 | 77 | } |
@@ -69,9 +79,11 @@ discard block |
||
| 69 | 79 | |
| 70 | 80 | private function parseName(string $name): NameEntity |
| 71 | 81 | { |
| 72 | - if (\preg_match("/\d+$/", $name, $match)) { |
|
| 82 | + if (\preg_match("/\d+$/", $name, $match)) |
|
| 83 | + { |
|
| 73 | 84 | $sequence = (int)$match[0]; |
| 74 | - if ($sequence > 0) { |
|
| 85 | + if ($sequence > 0) |
|
| 86 | + { |
|
| 75 | 87 | return NameEntity::createWithSequence(Utils::trimTrailingDigits($name, $sequence), $sequence); |
| 76 | 88 | } |
| 77 | 89 | } |
@@ -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 | } |
@@ -20,13 +20,13 @@ discard block |
||
| 20 | 20 | public function __construct( |
| 21 | 21 | private readonly ReaderInterface $reader, |
| 22 | 22 | private readonly PrototypeRegistry $registry |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | public function listen(ReflectionClass $class): void |
| 27 | 27 | { |
| 28 | 28 | $attribute = $this->reader->firstClassMetadata($class, Prototyped::class); |
| 29 | - if ($attribute === null) { |
|
| 29 | + if ($attribute === null){ |
|
| 30 | 30 | return; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | public function finalize(): void |
| 37 | 37 | { |
| 38 | - foreach ($this->attributes as $property => $class) { |
|
| 38 | + foreach ($this->attributes as $property => $class){ |
|
| 39 | 39 | $this->registry->bindProperty($property, $class); |
| 40 | 40 | } |
| 41 | 41 | } |
@@ -26,7 +26,8 @@ discard block |
||
| 26 | 26 | public function listen(ReflectionClass $class): void |
| 27 | 27 | { |
| 28 | 28 | $attribute = $this->reader->firstClassMetadata($class, Prototyped::class); |
| 29 | - if ($attribute === null) { |
|
| 29 | + if ($attribute === null) |
|
| 30 | + { |
|
| 30 | 31 | return; |
| 31 | 32 | } |
| 32 | 33 | |
@@ -35,7 +36,8 @@ discard block |
||
| 35 | 36 | |
| 36 | 37 | public function finalize(): void |
| 37 | 38 | { |
| 38 | - foreach ($this->attributes as $property => $class) { |
|
| 39 | + foreach ($this->attributes as $property => $class) |
|
| 40 | + { |
|
| 39 | 41 | $this->registry->bindProperty($property, $class); |
| 40 | 42 | } |
| 41 | 43 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | public function perform(): int |
| 16 | 16 | { |
| 17 | 17 | $prototyped = $this->locator->getTargetClasses(); |
| 18 | - if ($prototyped === []) { |
|
| 18 | + if ($prototyped === []){ |
|
| 19 | 19 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 20 | 20 | |
| 21 | 21 | return self::SUCCESS; |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | |
| 24 | 24 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 25 | 25 | |
| 26 | - foreach ($prototyped as $class) { |
|
| 26 | + foreach ($prototyped as $class){ |
|
| 27 | 27 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 28 | 28 | |
| 29 | 29 | $grid->addRow([$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]); |
@@ -15,7 +15,8 @@ discard block |
||
| 15 | 15 | public function perform(): int |
| 16 | 16 | { |
| 17 | 17 | $prototyped = $this->locator->getTargetClasses(); |
| 18 | - if ($prototyped === []) { |
|
| 18 | + if ($prototyped === []) |
|
| 19 | + { |
|
| 19 | 20 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 20 | 21 | |
| 21 | 22 | return self::SUCCESS; |
@@ -23,7 +24,8 @@ discard block |
||
| 23 | 24 | |
| 24 | 25 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 25 | 26 | |
| 26 | - foreach ($prototyped as $class) { |
|
| 27 | + foreach ($prototyped as $class) |
|
| 28 | + { |
|
| 27 | 29 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 28 | 30 | |
| 29 | 31 | $grid->addRow([$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]); |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | protected readonly PrototypeLocator $locator, |
| 21 | 21 | protected readonly NodeExtractor $extractor, |
| 22 | 22 | protected readonly PrototypeRegistry $registry |
| 23 | - ) { |
|
| 23 | + ){ |
|
| 24 | 24 | parent::__construct(); |
| 25 | 25 | } |
| 26 | 26 | |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | $results = [$this->readProperties($class)]; |
| 36 | 36 | |
| 37 | 37 | $parent = $class->getParentClass(); |
| 38 | - while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])) { |
|
| 38 | + while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])){ |
|
| 39 | 39 | $results[] = $this->readProperties($parent); |
| 40 | 40 | $parent = $parent->getParentClass(); |
| 41 | 41 | } |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | { |
| 64 | 64 | $result = []; |
| 65 | 65 | |
| 66 | - foreach ($properties as $target) { |
|
| 67 | - if ($target instanceof Throwable) { |
|
| 66 | + foreach ($properties as $target){ |
|
| 67 | + if ($target instanceof Throwable){ |
|
| 68 | 68 | $result[] = \sprintf( |
| 69 | 69 | '<fg=red>%s [f: %s, l: %s]</fg=red>', |
| 70 | 70 | $target->getMessage(), |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | continue; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if ($target === null) { |
|
| 77 | + if ($target === null){ |
|
| 78 | 78 | $result[] = '<fg=yellow>undefined</fg=yellow>'; |
| 79 | 79 | continue; |
| 80 | 80 | } |
@@ -90,16 +90,16 @@ discard block |
||
| 90 | 90 | */ |
| 91 | 91 | private function readProperties(\ReflectionClass $class): array |
| 92 | 92 | { |
| 93 | - if (isset($this->cache[$class->getFileName()])) { |
|
| 93 | + if (isset($this->cache[$class->getFileName()])){ |
|
| 94 | 94 | $proto = $this->cache[$class->getFileName()]; |
| 95 | - } else { |
|
| 95 | + }else{ |
|
| 96 | 96 | $proto = $this->getExtractor()->getPrototypeProperties(\file_get_contents($class->getFileName())); |
| 97 | 97 | $this->cache[$class->getFileName()] = $proto; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | $result = []; |
| 101 | - foreach ($proto as $name) { |
|
| 102 | - if (!isset($result[$name])) { |
|
| 101 | + foreach ($proto as $name){ |
|
| 102 | + if (!isset($result[$name])){ |
|
| 103 | 103 | $result[$name] = $this->registry->resolveProperty($name); |
| 104 | 104 | } |
| 105 | 105 | } |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | */ |
| 117 | 117 | private function reverse(array $results): \Generator |
| 118 | 118 | { |
| 119 | - foreach (\array_reverse($results) as $result) { |
|
| 119 | + foreach (\array_reverse($results) as $result){ |
|
| 120 | 120 | yield from $result; |
| 121 | 121 | } |
| 122 | 122 | } |
@@ -35,7 +35,8 @@ discard block |
||
| 35 | 35 | $results = [$this->readProperties($class)]; |
| 36 | 36 | |
| 37 | 37 | $parent = $class->getParentClass(); |
| 38 | - while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])) { |
|
| 38 | + while ($parent instanceof \ReflectionClass && isset($all[$parent->getName()])) |
|
| 39 | + { |
|
| 39 | 40 | $results[] = $this->readProperties($parent); |
| 40 | 41 | $parent = $parent->getParentClass(); |
| 41 | 42 | } |
@@ -63,8 +64,10 @@ discard block |
||
| 63 | 64 | { |
| 64 | 65 | $result = []; |
| 65 | 66 | |
| 66 | - foreach ($properties as $target) { |
|
| 67 | - if ($target instanceof Throwable) { |
|
| 67 | + foreach ($properties as $target) |
|
| 68 | + { |
|
| 69 | + if ($target instanceof Throwable) |
|
| 70 | + { |
|
| 68 | 71 | $result[] = \sprintf( |
| 69 | 72 | '<fg=red>%s [f: %s, l: %s]</fg=red>', |
| 70 | 73 | $target->getMessage(), |
@@ -74,7 +77,8 @@ discard block |
||
| 74 | 77 | continue; |
| 75 | 78 | } |
| 76 | 79 | |
| 77 | - if ($target === null) { |
|
| 80 | + if ($target === null) |
|
| 81 | + { |
|
| 78 | 82 | $result[] = '<fg=yellow>undefined</fg=yellow>'; |
| 79 | 83 | continue; |
| 80 | 84 | } |
@@ -90,16 +94,21 @@ discard block |
||
| 90 | 94 | */ |
| 91 | 95 | private function readProperties(\ReflectionClass $class): array |
| 92 | 96 | { |
| 93 | - if (isset($this->cache[$class->getFileName()])) { |
|
| 97 | + if (isset($this->cache[$class->getFileName()])) |
|
| 98 | + { |
|
| 94 | 99 | $proto = $this->cache[$class->getFileName()]; |
| 95 | - } else { |
|
| 100 | + } |
|
| 101 | + else |
|
| 102 | + { |
|
| 96 | 103 | $proto = $this->getExtractor()->getPrototypeProperties(\file_get_contents($class->getFileName())); |
| 97 | 104 | $this->cache[$class->getFileName()] = $proto; |
| 98 | 105 | } |
| 99 | 106 | |
| 100 | 107 | $result = []; |
| 101 | - foreach ($proto as $name) { |
|
| 102 | - if (!isset($result[$name])) { |
|
| 108 | + foreach ($proto as $name) |
|
| 109 | + { |
|
| 110 | + if (!isset($result[$name])) |
|
| 111 | + { |
|
| 103 | 112 | $result[$name] = $this->registry->resolveProperty($name); |
| 104 | 113 | } |
| 105 | 114 | } |
@@ -116,7 +125,8 @@ discard block |
||
| 116 | 125 | */ |
| 117 | 126 | private function reverse(array $results): \Generator |
| 118 | 127 | { |
| 119 | - foreach (\array_reverse($results) as $result) { |
|
| 128 | + foreach (\array_reverse($results) as $result) |
|
| 129 | + { |
|
| 120 | 130 | yield from $result; |
| 121 | 131 | } |
| 122 | 132 | } |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | PrototypeLocator $locator, |
| 33 | 33 | NodeExtractor $extractor, |
| 34 | 34 | PrototypeRegistry $registry |
| 35 | - ) { |
|
| 35 | + ){ |
|
| 36 | 36 | parent::__construct($locator, $extractor, $registry); |
| 37 | 37 | $this->injector = new Injector(); |
| 38 | 38 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | public function perform(): int |
| 47 | 47 | { |
| 48 | 48 | $prototyped = $this->locator->getTargetClasses(); |
| 49 | - if ($prototyped === []) { |
|
| 49 | + if ($prototyped === []){ |
|
| 50 | 50 | $this->writeln('<comment>No prototyped classes found.</comment>'); |
| 51 | 51 | |
| 52 | 52 | return self::SUCCESS; |
@@ -54,18 +54,18 @@ discard block |
||
| 54 | 54 | |
| 55 | 55 | $targets = []; |
| 56 | 56 | |
| 57 | - foreach ($prototyped as $class) { |
|
| 57 | + foreach ($prototyped as $class){ |
|
| 58 | 58 | $proto = $this->getPrototypeProperties($class, $prototyped); |
| 59 | - if (empty($proto)) { |
|
| 59 | + if (empty($proto)){ |
|
| 60 | 60 | $modified = $this->modify($class, $proto); |
| 61 | - if ($modified !== null) { |
|
| 61 | + if ($modified !== null){ |
|
| 62 | 62 | $targets[] = $modified; |
| 63 | 63 | } |
| 64 | 64 | continue; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - foreach ($proto as $target) { |
|
| 68 | - if ($target instanceof \Throwable) { |
|
| 67 | + foreach ($proto as $target){ |
|
| 68 | + if ($target instanceof \Throwable){ |
|
| 69 | 69 | $targets[] = [ |
| 70 | 70 | $class->getName(), |
| 71 | 71 | $target->getMessage(), |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | continue 2; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if ($target === null) { |
|
| 77 | + if ($target === null){ |
|
| 78 | 78 | continue 2; |
| 79 | 79 | } |
| 80 | 80 | } |
@@ -82,14 +82,14 @@ discard block |
||
| 82 | 82 | $targets[] = [$class->getName(), $this->mergeNames($proto), $this->mergeTargets($proto)]; |
| 83 | 83 | |
| 84 | 84 | $modified = $this->modify($class, $proto); |
| 85 | - if ($modified !== null) { |
|
| 85 | + if ($modified !== null){ |
|
| 86 | 86 | $targets[] = $modified; |
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - if (!empty($targets)) { |
|
| 90 | + if (!empty($targets)){ |
|
| 91 | 91 | $grid = $this->table(['Class:', 'Property:', 'Target:']); |
| 92 | - foreach ($targets as $target) { |
|
| 92 | + foreach ($targets as $target){ |
|
| 93 | 93 | $grid->addRow($target); |
| 94 | 94 | } |
| 95 | 95 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | private function modify(\ReflectionClass $class, array $proto): ?array |
| 103 | 103 | { |
| 104 | 104 | $classDefinition = $this->extractor->extract($class->getFileName(), $proto); |
| 105 | - try { |
|
| 105 | + try{ |
|
| 106 | 106 | $modified = $this->injector->injectDependencies( |
| 107 | 107 | \file_get_contents($class->getFileName()), |
| 108 | 108 | $classDefinition, |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | \file_put_contents($class->getFileName(), $modified); |
| 115 | 115 | |
| 116 | 116 | return null; |
| 117 | - } catch (\Throwable $e) { |
|
| 117 | + }catch (\Throwable $e){ |
|
| 118 | 118 | return [$class->getName(), $e->getMessage(), \sprintf('%s:L%s', $e->getFile(), $e->getLine())]; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -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 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | public function __construct( |
| 75 | 75 | private readonly PrototypeRegistry $registry |
| 76 | - ) { |
|
| 76 | + ){ |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | public function init(ConsoleBootloader $console): void |
@@ -118,30 +118,30 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | private function initDefaults(ContainerInterface $container): void |
| 120 | 120 | { |
| 121 | - foreach (self::DEFAULT_SHORTCUTS as $property => $shortcut) { |
|
| 122 | - if (\is_array($shortcut) && isset($shortcut['resolve'])) { |
|
| 123 | - if (isset($shortcut['with'])) { |
|
| 121 | + foreach (self::DEFAULT_SHORTCUTS as $property => $shortcut){ |
|
| 122 | + if (\is_array($shortcut) && isset($shortcut['resolve'])){ |
|
| 123 | + if (isset($shortcut['with'])){ |
|
| 124 | 124 | // check dependencies |
| 125 | - foreach ($shortcut['with'] as $dep) { |
|
| 126 | - if (!\class_exists($dep, true) && !\interface_exists($dep, true)) { |
|
| 125 | + foreach ($shortcut['with'] as $dep){ |
|
| 126 | + if (!\class_exists($dep, true) && !\interface_exists($dep, true)){ |
|
| 127 | 127 | continue 2; |
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - try { |
|
| 132 | + try{ |
|
| 133 | 133 | $target = $container->get($shortcut['resolve']); |
| 134 | - if (\is_object($target)) { |
|
| 134 | + if (\is_object($target)){ |
|
| 135 | 135 | $this->bindProperty($property, $target::class); |
| 136 | 136 | } |
| 137 | - } catch (ContainerExceptionInterface) { |
|
| 137 | + }catch (ContainerExceptionInterface){ |
|
| 138 | 138 | continue; |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | continue; |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - if (\is_string($shortcut) && (\class_exists($shortcut, true) || \interface_exists($shortcut, true))) { |
|
| 144 | + if (\is_string($shortcut) && (\class_exists($shortcut, true) || \interface_exists($shortcut, true))){ |
|
| 145 | 145 | $this->bindProperty($property, $shortcut); |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -118,30 +118,40 @@ |
||
| 118 | 118 | |
| 119 | 119 | private function initDefaults(ContainerInterface $container): void |
| 120 | 120 | { |
| 121 | - foreach (self::DEFAULT_SHORTCUTS as $property => $shortcut) { |
|
| 122 | - if (\is_array($shortcut) && isset($shortcut['resolve'])) { |
|
| 123 | - if (isset($shortcut['with'])) { |
|
| 121 | + foreach (self::DEFAULT_SHORTCUTS as $property => $shortcut) |
|
| 122 | + { |
|
| 123 | + if (\is_array($shortcut) && isset($shortcut['resolve'])) |
|
| 124 | + { |
|
| 125 | + if (isset($shortcut['with'])) |
|
| 126 | + { |
|
| 124 | 127 | // check dependencies |
| 125 | - foreach ($shortcut['with'] as $dep) { |
|
| 126 | - if (!\class_exists($dep, true) && !\interface_exists($dep, true)) { |
|
| 128 | + foreach ($shortcut['with'] as $dep) |
|
| 129 | + { |
|
| 130 | + if (!\class_exists($dep, true) && !\interface_exists($dep, true)) |
|
| 131 | + { |
|
| 127 | 132 | continue 2; |
| 128 | 133 | } |
| 129 | 134 | } |
| 130 | 135 | } |
| 131 | 136 | |
| 132 | - try { |
|
| 137 | + try |
|
| 138 | + { |
|
| 133 | 139 | $target = $container->get($shortcut['resolve']); |
| 134 | - if (\is_object($target)) { |
|
| 140 | + if (\is_object($target)) |
|
| 141 | + { |
|
| 135 | 142 | $this->bindProperty($property, $target::class); |
| 136 | 143 | } |
| 137 | - } catch (ContainerExceptionInterface) { |
|
| 144 | + } |
|
| 145 | + catch (ContainerExceptionInterface) |
|
| 146 | + { |
|
| 138 | 147 | continue; |
| 139 | 148 | } |
| 140 | 149 | |
| 141 | 150 | continue; |
| 142 | 151 | } |
| 143 | 152 | |
| 144 | - if (\is_string($shortcut) && (\class_exists($shortcut, true) || \interface_exists($shortcut, true))) { |
|
| 153 | + if (\is_string($shortcut) && (\class_exists($shortcut, true) || \interface_exists($shortcut, true))) |
|
| 154 | + { |
|
| 145 | 155 | $this->bindProperty($property, $shortcut); |
| 146 | 156 | } |
| 147 | 157 | } |
@@ -16,22 +16,22 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | $lines = \explode("\n", $comment); |
| 18 | 18 | |
| 19 | - foreach ($lines as $line) { |
|
| 19 | + foreach ($lines as $line){ |
|
| 20 | 20 | // strip up comment prefix |
| 21 | 21 | $line = \preg_replace('/[\t ]*[\/]?\*[\/]? ?/', '', $line); |
| 22 | 22 | |
| 23 | - if (\preg_match('/ *@([^ ]+) (.*)/u', $line, $matches)) { |
|
| 23 | + if (\preg_match('/ *@([^ ]+) (.*)/u', $line, $matches)){ |
|
| 24 | 24 | $this->lines[] = new Line($matches[2], $matches[1]); |
| 25 | - } else { |
|
| 25 | + }else{ |
|
| 26 | 26 | $this->lines[] = new Line($line); |
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | - if (isset($this->lines[0]) && $this->lines[0]->isEmpty()) { |
|
| 30 | + if (isset($this->lines[0]) && $this->lines[0]->isEmpty()){ |
|
| 31 | 31 | \array_shift($this->lines); |
| 32 | 32 | } |
| 33 | 33 | |
| 34 | - if (isset($this->lines[\count($this->lines) - 1]) && $this->lines[\count($this->lines) - 1]->isEmpty()) { |
|
| 34 | + if (isset($this->lines[\count($this->lines) - 1]) && $this->lines[\count($this->lines) - 1]->isEmpty()){ |
|
| 35 | 35 | \array_pop($this->lines); |
| 36 | 36 | } |
| 37 | 37 | } |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | $result[] = '/**'; |
| 43 | 43 | |
| 44 | 44 | // skip first and last tokens |
| 45 | - foreach ($this->lines as $line) { |
|
| 46 | - if ($line->type === null) { |
|
| 45 | + foreach ($this->lines as $line){ |
|
| 46 | + if ($line->type === null){ |
|
| 47 | 47 | $result[] = \sprintf(' * %s', $line->value); |
| 48 | 48 | continue; |
| 49 | 49 | } |
@@ -16,22 +16,28 @@ discard block |
||
| 16 | 16 | { |
| 17 | 17 | $lines = \explode("\n", $comment); |
| 18 | 18 | |
| 19 | - foreach ($lines as $line) { |
|
| 19 | + foreach ($lines as $line) |
|
| 20 | + { |
|
| 20 | 21 | // strip up comment prefix |
| 21 | 22 | $line = \preg_replace('/[\t ]*[\/]?\*[\/]? ?/', '', $line); |
| 22 | 23 | |
| 23 | - if (\preg_match('/ *@([^ ]+) (.*)/u', $line, $matches)) { |
|
| 24 | + if (\preg_match('/ *@([^ ]+) (.*)/u', $line, $matches)) |
|
| 25 | + { |
|
| 24 | 26 | $this->lines[] = new Line($matches[2], $matches[1]); |
| 25 | - } else { |
|
| 27 | + } |
|
| 28 | + else |
|
| 29 | + { |
|
| 26 | 30 | $this->lines[] = new Line($line); |
| 27 | 31 | } |
| 28 | 32 | } |
| 29 | 33 | |
| 30 | - if (isset($this->lines[0]) && $this->lines[0]->isEmpty()) { |
|
| 34 | + if (isset($this->lines[0]) && $this->lines[0]->isEmpty()) |
|
| 35 | + { |
|
| 31 | 36 | \array_shift($this->lines); |
| 32 | 37 | } |
| 33 | 38 | |
| 34 | - if (isset($this->lines[\count($this->lines) - 1]) && $this->lines[\count($this->lines) - 1]->isEmpty()) { |
|
| 39 | + if (isset($this->lines[\count($this->lines) - 1]) && $this->lines[\count($this->lines) - 1]->isEmpty()) |
|
| 40 | + { |
|
| 35 | 41 | \array_pop($this->lines); |
| 36 | 42 | } |
| 37 | 43 | } |
@@ -42,8 +48,10 @@ discard block |
||
| 42 | 48 | $result[] = '/**'; |
| 43 | 49 | |
| 44 | 50 | // skip first and last tokens |
| 45 | - foreach ($this->lines as $line) { |
|
| 46 | - if ($line->type === null) { |
|
| 51 | + foreach ($this->lines as $line) |
|
| 52 | + { |
|
| 53 | + if ($line->type === null) |
|
| 54 | + { |
|
| 47 | 55 | $result[] = \sprintf(' * %s', $line->value); |
| 48 | 56 | continue; |
| 49 | 57 | } |
@@ -25,6 +25,6 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | public function __construct( |
| 27 | 27 | public readonly string $property |
| 28 | - ) { |
|
| 28 | + ){ |
|
| 29 | 29 | } |
| 30 | 30 | } |