@@ -63,11 +63,11 @@ discard block |
||
| 63 | 63 | $declaration = $this->createDeclaration(); |
| 64 | 64 | |
| 65 | 65 | $fields = []; |
| 66 | - if ($this->option('entity')) { |
|
| 66 | + if ($this->option('entity')){ |
|
| 67 | 67 | $name = $this->option('entity'); |
| 68 | - try { |
|
| 68 | + try{ |
|
| 69 | 69 | $fields = $this->parseSourceEntity($name); |
| 70 | - } catch (ReflectionException $e) { |
|
| 70 | + }catch (ReflectionException $e){ |
|
| 71 | 71 | $this->writeln( |
| 72 | 72 | "<fg=red>Unable to create '<comment>{$declaration->getName()} from $name</comment>' declaration: " |
| 73 | 73 | . "'<comment>{$e->getMessage()}' at {$e->getFile()}:{$e->getLine()}.</comment></fg=red>" |
@@ -75,13 +75,13 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | return; |
| 77 | 77 | } |
| 78 | - } else { |
|
| 79 | - foreach ($this->option('field') as $field) { |
|
| 78 | + }else{ |
|
| 79 | + foreach ($this->option('field') as $field){ |
|
| 80 | 80 | $fields[] = $this->parseField($field); |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - foreach ($fields as $values) { |
|
| 84 | + foreach ($fields as $values){ |
|
| 85 | 85 | [$field, $type, $source, $origin] = $values; |
| 86 | 86 | |
| 87 | 87 | $declaration->declareField($field, $type, $source, $origin); |
@@ -99,16 +99,16 @@ discard block |
||
| 99 | 99 | $source = null; |
| 100 | 100 | $origin = null; |
| 101 | 101 | |
| 102 | - if (strpos($field, '(') !== false) { |
|
| 102 | + if (strpos($field, '(') !== false){ |
|
| 103 | 103 | $source = substr($field, strpos($field, '(') + 1, -1); |
| 104 | 104 | $field = substr($field, 0, strpos($field, '(')); |
| 105 | 105 | |
| 106 | - if (strpos($source, ':') !== false) { |
|
| 106 | + if (strpos($source, ':') !== false){ |
|
| 107 | 107 | [$source, $origin] = explode(':', $source); |
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if (strpos($field, ':') !== false) { |
|
| 111 | + if (strpos($field, ':') !== false){ |
|
| 112 | 112 | [$field, $type] = explode(':', $field); |
| 113 | 113 | } |
| 114 | 114 | |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | { |
| 123 | 123 | $fields = []; |
| 124 | 124 | $reflection = new ReflectionClass($name); |
| 125 | - foreach ($reflection->getProperties() as $property) { |
|
| 125 | + foreach ($reflection->getProperties() as $property){ |
|
| 126 | 126 | $type = $this->getTypedPropertyType($property) |
| 127 | 127 | ?? $this->getPropertyTypeFromDefaults($property, $reflection) |
| 128 | 128 | ?? $this->getPropertyTypeFromDocBlock($property); |
@@ -135,9 +135,9 @@ discard block |
||
| 135 | 135 | |
| 136 | 136 | private function getTypedPropertyType(ReflectionProperty $property): ?string |
| 137 | 137 | { |
| 138 | - if (method_exists($property, 'hasType') && method_exists($property, 'getType') && $property->hasType()) { |
|
| 138 | + if (method_exists($property, 'hasType') && method_exists($property, 'getType') && $property->hasType()){ |
|
| 139 | 139 | $type = $property->getType(); |
| 140 | - if (method_exists($type, 'getName') && $this->isKnownType($type->getName())) { |
|
| 140 | + if (method_exists($type, 'getName') && $this->isKnownType($type->getName())){ |
|
| 141 | 141 | return $type->getName(); |
| 142 | 142 | } |
| 143 | 143 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | private function getPropertyTypeFromDefaults(ReflectionProperty $property, ReflectionClass $reflection): ?string |
| 149 | 149 | { |
| 150 | - if (!isset($reflection->getDefaultProperties()[$property->name])) { |
|
| 150 | + if (!isset($reflection->getDefaultProperties()[$property->name])){ |
|
| 151 | 151 | return null; |
| 152 | 152 | } |
| 153 | 153 | |
@@ -159,9 +159,9 @@ discard block |
||
| 159 | 159 | private function getPropertyTypeFromDocBlock(ReflectionProperty $property): ?string |
| 160 | 160 | { |
| 161 | 161 | $doc = $property->getDocComment(); |
| 162 | - if (is_string($doc)) { |
|
| 162 | + if (is_string($doc)){ |
|
| 163 | 163 | preg_match('/@var\s*([\S]+)/i', $doc, $match); |
| 164 | - if (!empty($match[1]) && $this->isKnownType($match[1])) { |
|
| 164 | + if (!empty($match[1]) && $this->isKnownType($match[1])){ |
|
| 165 | 165 | return $match[1]; |
| 166 | 166 | } |
| 167 | 167 | } |
@@ -63,11 +63,15 @@ discard block |
||
| 63 | 63 | $declaration = $this->createDeclaration(); |
| 64 | 64 | |
| 65 | 65 | $fields = []; |
| 66 | - if ($this->option('entity')) { |
|
| 66 | + if ($this->option('entity')) |
|
| 67 | + { |
|
| 67 | 68 | $name = $this->option('entity'); |
| 68 | - try { |
|
| 69 | + try |
|
| 70 | + { |
|
| 69 | 71 | $fields = $this->parseSourceEntity($name); |
| 70 | - } catch (ReflectionException $e) { |
|
| 72 | + } |
|
| 73 | + catch (ReflectionException $e) |
|
| 74 | + { |
|
| 71 | 75 | $this->writeln( |
| 72 | 76 | "<fg=red>Unable to create '<comment>{$declaration->getName()} from $name</comment>' declaration: " |
| 73 | 77 | . "'<comment>{$e->getMessage()}' at {$e->getFile()}:{$e->getLine()}.</comment></fg=red>" |
@@ -75,13 +79,17 @@ discard block |
||
| 75 | 79 | |
| 76 | 80 | return; |
| 77 | 81 | } |
| 78 | - } else { |
|
| 79 | - foreach ($this->option('field') as $field) { |
|
| 82 | + } |
|
| 83 | + else |
|
| 84 | + { |
|
| 85 | + foreach ($this->option('field') as $field) |
|
| 86 | + { |
|
| 80 | 87 | $fields[] = $this->parseField($field); |
| 81 | 88 | } |
| 82 | 89 | } |
| 83 | 90 | |
| 84 | - foreach ($fields as $values) { |
|
| 91 | + foreach ($fields as $values) |
|
| 92 | + { |
|
| 85 | 93 | [$field, $type, $source, $origin] = $values; |
| 86 | 94 | |
| 87 | 95 | $declaration->declareField($field, $type, $source, $origin); |
@@ -99,16 +107,19 @@ discard block |
||
| 99 | 107 | $source = null; |
| 100 | 108 | $origin = null; |
| 101 | 109 | |
| 102 | - if (strpos($field, '(') !== false) { |
|
| 110 | + if (strpos($field, '(') !== false) |
|
| 111 | + { |
|
| 103 | 112 | $source = substr($field, strpos($field, '(') + 1, -1); |
| 104 | 113 | $field = substr($field, 0, strpos($field, '(')); |
| 105 | 114 | |
| 106 | - if (strpos($source, ':') !== false) { |
|
| 115 | + if (strpos($source, ':') !== false) |
|
| 116 | + { |
|
| 107 | 117 | [$source, $origin] = explode(':', $source); |
| 108 | 118 | } |
| 109 | 119 | } |
| 110 | 120 | |
| 111 | - if (strpos($field, ':') !== false) { |
|
| 121 | + if (strpos($field, ':') !== false) |
|
| 122 | + { |
|
| 112 | 123 | [$field, $type] = explode(':', $field); |
| 113 | 124 | } |
| 114 | 125 | |
@@ -122,7 +133,8 @@ discard block |
||
| 122 | 133 | { |
| 123 | 134 | $fields = []; |
| 124 | 135 | $reflection = new ReflectionClass($name); |
| 125 | - foreach ($reflection->getProperties() as $property) { |
|
| 136 | + foreach ($reflection->getProperties() as $property) |
|
| 137 | + { |
|
| 126 | 138 | $type = $this->getTypedPropertyType($property) |
| 127 | 139 | ?? $this->getPropertyTypeFromDefaults($property, $reflection) |
| 128 | 140 | ?? $this->getPropertyTypeFromDocBlock($property); |
@@ -135,9 +147,11 @@ discard block |
||
| 135 | 147 | |
| 136 | 148 | private function getTypedPropertyType(ReflectionProperty $property): ?string |
| 137 | 149 | { |
| 138 | - if (method_exists($property, 'hasType') && method_exists($property, 'getType') && $property->hasType()) { |
|
| 150 | + if (method_exists($property, 'hasType') && method_exists($property, 'getType') && $property->hasType()) |
|
| 151 | + { |
|
| 139 | 152 | $type = $property->getType(); |
| 140 | - if (method_exists($type, 'getName') && $this->isKnownType($type->getName())) { |
|
| 153 | + if (method_exists($type, 'getName') && $this->isKnownType($type->getName())) |
|
| 154 | + { |
|
| 141 | 155 | return $type->getName(); |
| 142 | 156 | } |
| 143 | 157 | } |
@@ -147,7 +161,8 @@ discard block |
||
| 147 | 161 | |
| 148 | 162 | private function getPropertyTypeFromDefaults(ReflectionProperty $property, ReflectionClass $reflection): ?string |
| 149 | 163 | { |
| 150 | - if (!isset($reflection->getDefaultProperties()[$property->name])) { |
|
| 164 | + if (!isset($reflection->getDefaultProperties()[$property->name])) |
|
| 165 | + { |
|
| 151 | 166 | return null; |
| 152 | 167 | } |
| 153 | 168 | |
@@ -159,9 +174,11 @@ discard block |
||
| 159 | 174 | private function getPropertyTypeFromDocBlock(ReflectionProperty $property): ?string |
| 160 | 175 | { |
| 161 | 176 | $doc = $property->getDocComment(); |
| 162 | - if (is_string($doc)) { |
|
| 177 | + if (is_string($doc)) |
|
| 178 | + { |
|
| 163 | 179 | preg_match('/@var\s*([\S]+)/i', $doc, $match); |
| 164 | - if (!empty($match[1]) && $this->isKnownType($match[1])) { |
|
| 180 | + if (!empty($match[1]) && $this->isKnownType($match[1])) |
|
| 181 | + { |
|
| 165 | 182 | return $match[1]; |
| 166 | 183 | } |
| 167 | 184 | } |