@@ -38,7 +38,7 @@ |
||
38 | 38 | AbstractDeclaration::ACCESS_PROTECTED, |
39 | 39 | AbstractDeclaration::ACCESS_PUBLIC, |
40 | 40 | ], true) |
41 | - ) { |
|
41 | + ){ |
|
42 | 42 | throw new ReactorException("Invalid declaration level '{$access}'"); |
43 | 43 | } |
44 | 44 |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | RendererInterface $renderer, |
60 | 60 | ResponseFactoryInterface $responseFactory, |
61 | 61 | ContainerInterface $container |
62 | - ) { |
|
62 | + ){ |
|
63 | 63 | $this->suppressErrors = $suppressErrors; |
64 | 64 | $this->renderer = $renderer; |
65 | 65 | $this->responseFactory = $responseFactory; |
@@ -73,22 +73,22 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function process(Request $request, Handler $handler): Response |
75 | 75 | { |
76 | - try { |
|
76 | + try{ |
|
77 | 77 | return $handler->handle($request); |
78 | - } catch (ClientException | RouterException $e) { |
|
79 | - if ($e instanceof ClientException) { |
|
78 | + }catch (ClientException | RouterException $e){ |
|
79 | + if ($e instanceof ClientException){ |
|
80 | 80 | $code = $e->getCode(); |
81 | - } else { |
|
81 | + }else{ |
|
82 | 82 | $code = 404; |
83 | 83 | } |
84 | - } catch (\Throwable $e) { |
|
84 | + }catch (\Throwable $e){ |
|
85 | 85 | $snapshotter = $this->getOptional(SnapshotterInterface::class); |
86 | - if ($snapshotter !== null) { |
|
86 | + if ($snapshotter !== null){ |
|
87 | 87 | /** @var SnapshotterInterface $snapshotter */ |
88 | 88 | $snapshotter->register($e); |
89 | 89 | } |
90 | 90 | |
91 | - if (!$this->suppressErrors->suppressed()) { |
|
91 | + if (!$this->suppressErrors->suppressed()){ |
|
92 | 92 | return $this->renderError($request, $e); |
93 | 93 | } |
94 | 94 | |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | { |
112 | 112 | $response = $this->responseFactory->createResponse(500); |
113 | 113 | |
114 | - if ($request->getHeaderLine('Accept') === 'application/json') { |
|
114 | + if ($request->getHeaderLine('Accept') === 'application/json'){ |
|
115 | 115 | $response = $response->withHeader('Content-Type', 'application/json'); |
116 | 116 | $handler = new JsonHandler(); |
117 | 117 | $response->getBody()->write( |
@@ -123,10 +123,10 @@ discard block |
||
123 | 123 | ) |
124 | 124 | ) |
125 | 125 | ); |
126 | - } else { |
|
126 | + }else{ |
|
127 | 127 | $handler = new HtmlHandler(); |
128 | 128 | $state = $this->getOptional(StateInterface::class); |
129 | - if ($state !== null) { |
|
129 | + if ($state !== null){ |
|
130 | 130 | $handler = $handler->withState($state); |
131 | 131 | } |
132 | 132 | |
@@ -162,9 +162,9 @@ discard block |
||
162 | 162 | */ |
163 | 163 | private function getOptional(string $class) |
164 | 164 | { |
165 | - try { |
|
165 | + try{ |
|
166 | 166 | return $this->container->get($class); |
167 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
167 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
168 | 168 | return null; |
169 | 169 | } |
170 | 170 | } |
@@ -73,22 +73,32 @@ discard block |
||
73 | 73 | */ |
74 | 74 | public function process(Request $request, Handler $handler): Response |
75 | 75 | { |
76 | - try { |
|
76 | + try |
|
77 | + { |
|
77 | 78 | return $handler->handle($request); |
78 | - } catch (ClientException | RouterException $e) { |
|
79 | - if ($e instanceof ClientException) { |
|
79 | + } |
|
80 | + catch (ClientException | RouterException $e) |
|
81 | + { |
|
82 | + if ($e instanceof ClientException) |
|
83 | + { |
|
80 | 84 | $code = $e->getCode(); |
81 | - } else { |
|
85 | + } |
|
86 | + else |
|
87 | + { |
|
82 | 88 | $code = 404; |
83 | 89 | } |
84 | - } catch (\Throwable $e) { |
|
90 | + } |
|
91 | + catch (\Throwable $e) |
|
92 | + { |
|
85 | 93 | $snapshotter = $this->getOptional(SnapshotterInterface::class); |
86 | - if ($snapshotter !== null) { |
|
94 | + if ($snapshotter !== null) |
|
95 | + { |
|
87 | 96 | /** @var SnapshotterInterface $snapshotter */ |
88 | 97 | $snapshotter->register($e); |
89 | 98 | } |
90 | 99 | |
91 | - if (!$this->suppressErrors->suppressed()) { |
|
100 | + if (!$this->suppressErrors->suppressed()) |
|
101 | + { |
|
92 | 102 | return $this->renderError($request, $e); |
93 | 103 | } |
94 | 104 | |
@@ -111,7 +121,8 @@ discard block |
||
111 | 121 | { |
112 | 122 | $response = $this->responseFactory->createResponse(500); |
113 | 123 | |
114 | - if ($request->getHeaderLine('Accept') === 'application/json') { |
|
124 | + if ($request->getHeaderLine('Accept') === 'application/json') |
|
125 | + { |
|
115 | 126 | $response = $response->withHeader('Content-Type', 'application/json'); |
116 | 127 | $handler = new JsonHandler(); |
117 | 128 | $response->getBody()->write( |
@@ -123,10 +134,13 @@ discard block |
||
123 | 134 | ) |
124 | 135 | ) |
125 | 136 | ); |
126 | - } else { |
|
137 | + } |
|
138 | + else |
|
139 | + { |
|
127 | 140 | $handler = new HtmlHandler(); |
128 | 141 | $state = $this->getOptional(StateInterface::class); |
129 | - if ($state !== null) { |
|
142 | + if ($state !== null) |
|
143 | + { |
|
130 | 144 | $handler = $handler->withState($state); |
131 | 145 | } |
132 | 146 | |
@@ -162,9 +176,12 @@ discard block |
||
162 | 176 | */ |
163 | 177 | private function getOptional(string $class) |
164 | 178 | { |
165 | - try { |
|
179 | + try |
|
180 | + { |
|
166 | 181 | return $this->container->get($class); |
167 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
182 | + } |
|
183 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
184 | + { |
|
168 | 185 | return null; |
169 | 186 | } |
170 | 187 | } |
@@ -62,10 +62,10 @@ |
||
62 | 62 | { |
63 | 63 | $app = TestApp::init( |
64 | 64 | [ |
65 | - 'root' => __DIR__ . '/../../..', |
|
66 | - 'app' => __DIR__ . '/../../emptyApp', |
|
67 | - 'runtime' => sys_get_temp_dir() . '/spiral', |
|
68 | - 'cache' => sys_get_temp_dir() . '/spiral', |
|
65 | + 'root' => __DIR__.'/../../..', |
|
66 | + 'app' => __DIR__.'/../../emptyApp', |
|
67 | + 'runtime' => sys_get_temp_dir().'/spiral', |
|
68 | + 'cache' => sys_get_temp_dir().'/spiral', |
|
69 | 69 | ], |
70 | 70 | new Environment(['SAFE_MIGRATIONS' => true]), |
71 | 71 | false |
@@ -62,9 +62,9 @@ discard block |
||
62 | 62 | $console->addCommand(Command\MiddlewareCommand::class); |
63 | 63 | $console->addCommand(Command\MigrationCommand::class); |
64 | 64 | |
65 | - try { |
|
65 | + try{ |
|
66 | 66 | $defaultNamespace = (new ReflectionClass($this->kernel))->getNamespaceName(); |
67 | - } catch (ReflectionException $e) { |
|
67 | + }catch (ReflectionException $e){ |
|
68 | 68 | $defaultNamespace = ''; |
69 | 69 | } |
70 | 70 | |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | * Base directory for generated classes, class will be automatically localed into sub directory |
84 | 84 | * using given namespace. |
85 | 85 | */ |
86 | - 'directory' => directory('app') . 'src/', |
|
86 | + 'directory' => directory('app').'src/', |
|
87 | 87 | |
88 | 88 | /* |
89 | 89 | * Default namespace to be applied for every generated class. By default uses Kernel namespace |
@@ -62,9 +62,12 @@ |
||
62 | 62 | $console->addCommand(Command\MiddlewareCommand::class); |
63 | 63 | $console->addCommand(Command\MigrationCommand::class); |
64 | 64 | |
65 | - try { |
|
65 | + try |
|
66 | + { |
|
66 | 67 | $defaultNamespace = (new ReflectionClass($this->kernel))->getNamespaceName(); |
67 | - } catch (ReflectionException $e) { |
|
68 | + } |
|
69 | + catch (ReflectionException $e) |
|
70 | + { |
|
68 | 71 | $defaultNamespace = ''; |
69 | 72 | } |
70 | 73 |
@@ -54,11 +54,11 @@ |
||
54 | 54 | /** @var ControllerDeclaration $declaration */ |
55 | 55 | $declaration = $this->createDeclaration(); |
56 | 56 | |
57 | - foreach ($this->option('action') as $action) { |
|
57 | + foreach ($this->option('action') as $action){ |
|
58 | 58 | $declaration->addAction($action); |
59 | 59 | } |
60 | 60 | |
61 | - if ((bool)$this->option('prototype')) { |
|
61 | + if ((bool)$this->option('prototype')){ |
|
62 | 62 | $declaration->addPrototypeTrait(); |
63 | 63 | } |
64 | 64 |
@@ -54,11 +54,13 @@ |
||
54 | 54 | /** @var ControllerDeclaration $declaration */ |
55 | 55 | $declaration = $this->createDeclaration(); |
56 | 56 | |
57 | - foreach ($this->option('action') as $action) { |
|
57 | + foreach ($this->option('action') as $action) |
|
58 | + { |
|
58 | 59 | $declaration->addAction($action); |
59 | 60 | } |
60 | 61 | |
61 | - if ((bool)$this->option('prototype')) { |
|
62 | + if ((bool)$this->option('prototype')) |
|
63 | + { |
|
62 | 64 | $declaration->addPrototypeTrait(); |
63 | 65 | } |
64 | 66 |
@@ -60,10 +60,10 @@ |
||
60 | 60 | /** @var MigrationDeclaration $declaration */ |
61 | 61 | $declaration = $this->createDeclaration(); |
62 | 62 | |
63 | - if (!empty($this->option('table'))) { |
|
63 | + if (!empty($this->option('table'))){ |
|
64 | 64 | $fields = []; |
65 | - foreach ($this->option('field') as $field) { |
|
66 | - if (strpos($field, ':') === false) { |
|
65 | + foreach ($this->option('field') as $field){ |
|
66 | + if (strpos($field, ':') === false){ |
|
67 | 67 | throw new ScaffolderException("Field definition must in 'name:type' form"); |
68 | 68 | } |
69 | 69 |
@@ -60,10 +60,13 @@ |
||
60 | 60 | /** @var MigrationDeclaration $declaration */ |
61 | 61 | $declaration = $this->createDeclaration(); |
62 | 62 | |
63 | - if (!empty($this->option('table'))) { |
|
63 | + if (!empty($this->option('table'))) |
|
64 | + { |
|
64 | 65 | $fields = []; |
65 | - foreach ($this->option('field') as $field) { |
|
66 | - if (strpos($field, ':') === false) { |
|
66 | + foreach ($this->option('field') as $field) |
|
67 | + { |
|
68 | + if (strpos($field, ':') === false) |
|
69 | + { |
|
67 | 70 | throw new ScaffolderException("Field definition must in 'name:type' form"); |
68 | 71 | } |
69 | 72 |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | FilesInterface $files, |
52 | 52 | ContainerInterface $container, |
53 | 53 | FactoryInterface $factory |
54 | - ) { |
|
54 | + ){ |
|
55 | 55 | $this->config = $config; |
56 | 56 | $this->files = $files; |
57 | 57 | $this->factory = $factory; |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $filename = $this->config->classFilename($type, (string)$this->argument('name')); |
111 | 111 | $filename = $this->files->normalizePath($filename); |
112 | 112 | |
113 | - if ($this->files->exists($filename)) { |
|
113 | + if ($this->files->exists($filename)){ |
|
114 | 114 | $this->writeln( |
115 | 115 | "<fg=red>Unable to create '<comment>{$declaration->getName()}</comment>' declaration, " |
116 | 116 | . "file '<comment>{$filename}</comment>' already exists.</fg=red>" |
@@ -110,7 +110,8 @@ |
||
110 | 110 | $filename = $this->config->classFilename($type, (string)$this->argument('name')); |
111 | 111 | $filename = $this->files->normalizePath($filename); |
112 | 112 | |
113 | - if ($this->files->exists($filename)) { |
|
113 | + if ($this->files->exists($filename)) |
|
114 | + { |
|
114 | 115 | $this->writeln( |
115 | 116 | "<fg=red>Unable to create '<comment>{$declaration->getName()}</comment>' declaration, " |
116 | 117 | . "file '<comment>{$filename}</comment>' already exists.</fg=red>" |
@@ -26,7 +26,7 @@ |
||
26 | 26 | ['name', InputArgument::REQUIRED, 'Command name'], |
27 | 27 | ['alias', InputArgument::OPTIONAL, 'Command id/alias'], |
28 | 28 | ]; |
29 | - protected const OPTIONS = [ |
|
29 | + protected const OPTIONS = [ |
|
30 | 30 | [ |
31 | 31 | 'description', |
32 | 32 | 'd', |
@@ -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); |
@@ -102,16 +102,16 @@ discard block |
||
102 | 102 | $source = null; |
103 | 103 | $origin = null; |
104 | 104 | |
105 | - if (strpos($field, '(') !== false) { |
|
105 | + if (strpos($field, '(') !== false){ |
|
106 | 106 | $source = substr($field, strpos($field, '(') + 1, -1); |
107 | 107 | $field = substr($field, 0, strpos($field, '(')); |
108 | 108 | |
109 | - if (strpos($source, ':') !== false) { |
|
109 | + if (strpos($source, ':') !== false){ |
|
110 | 110 | [$source, $origin] = explode(':', $source); |
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
114 | - if (strpos($field, ':') !== false) { |
|
114 | + if (strpos($field, ':') !== false){ |
|
115 | 115 | [$field, $type] = explode(':', $field); |
116 | 116 | } |
117 | 117 | |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | { |
128 | 128 | $fields = []; |
129 | 129 | $reflection = new ReflectionClass($name); |
130 | - foreach ($reflection->getProperties() as $property) { |
|
130 | + foreach ($reflection->getProperties() as $property){ |
|
131 | 131 | $type = $this->getTypedPropertyType($property) |
132 | 132 | ?? $this->getPropertyTypeFromDefaults($property, $reflection) |
133 | 133 | ?? $this->getPropertyTypeFromDocBlock($property); |
@@ -144,10 +144,10 @@ discard block |
||
144 | 144 | */ |
145 | 145 | private function getTypedPropertyType(ReflectionProperty $property): ?string |
146 | 146 | { |
147 | - if (method_exists($property, 'hasType') && method_exists($property, 'getType') && $property->hasType()) { |
|
147 | + if (method_exists($property, 'hasType') && method_exists($property, 'getType') && $property->hasType()){ |
|
148 | 148 | /** @var ReflectionType $type */ |
149 | 149 | $type = $property->getType(); |
150 | - if (method_exists($type, 'getName') && $this->isKnownType($type->getName())) { |
|
150 | + if (method_exists($type, 'getName') && $this->isKnownType($type->getName())){ |
|
151 | 151 | return $type->getName(); |
152 | 152 | } |
153 | 153 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | private function getPropertyTypeFromDefaults(ReflectionProperty $property, ReflectionClass $reflection): ?string |
164 | 164 | { |
165 | - if (!isset($reflection->getDefaultProperties()[$property->name])) { |
|
165 | + if (!isset($reflection->getDefaultProperties()[$property->name])){ |
|
166 | 166 | return null; |
167 | 167 | } |
168 | 168 | |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | private function getPropertyTypeFromDocBlock(ReflectionProperty $property): ?string |
179 | 179 | { |
180 | 180 | $doc = $property->getDocComment(); |
181 | - if (is_string($doc)) { |
|
181 | + if (is_string($doc)){ |
|
182 | 182 | preg_match('/@var\s*([\S]+)/i', $doc, $match); |
183 | - if (!empty($match[1]) && $this->isKnownType($match[1])) { |
|
183 | + if (!empty($match[1]) && $this->isKnownType($match[1])){ |
|
184 | 184 | return $match[1]; |
185 | 185 | } |
186 | 186 | } |
@@ -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); |
@@ -102,16 +110,19 @@ discard block |
||
102 | 110 | $source = null; |
103 | 111 | $origin = null; |
104 | 112 | |
105 | - if (strpos($field, '(') !== false) { |
|
113 | + if (strpos($field, '(') !== false) |
|
114 | + { |
|
106 | 115 | $source = substr($field, strpos($field, '(') + 1, -1); |
107 | 116 | $field = substr($field, 0, strpos($field, '(')); |
108 | 117 | |
109 | - if (strpos($source, ':') !== false) { |
|
118 | + if (strpos($source, ':') !== false) |
|
119 | + { |
|
110 | 120 | [$source, $origin] = explode(':', $source); |
111 | 121 | } |
112 | 122 | } |
113 | 123 | |
114 | - if (strpos($field, ':') !== false) { |
|
124 | + if (strpos($field, ':') !== false) |
|
125 | + { |
|
115 | 126 | [$field, $type] = explode(':', $field); |
116 | 127 | } |
117 | 128 | |
@@ -127,7 +138,8 @@ discard block |
||
127 | 138 | { |
128 | 139 | $fields = []; |
129 | 140 | $reflection = new ReflectionClass($name); |
130 | - foreach ($reflection->getProperties() as $property) { |
|
141 | + foreach ($reflection->getProperties() as $property) |
|
142 | + { |
|
131 | 143 | $type = $this->getTypedPropertyType($property) |
132 | 144 | ?? $this->getPropertyTypeFromDefaults($property, $reflection) |
133 | 145 | ?? $this->getPropertyTypeFromDocBlock($property); |
@@ -144,10 +156,12 @@ discard block |
||
144 | 156 | */ |
145 | 157 | private function getTypedPropertyType(ReflectionProperty $property): ?string |
146 | 158 | { |
147 | - if (method_exists($property, 'hasType') && method_exists($property, 'getType') && $property->hasType()) { |
|
159 | + if (method_exists($property, 'hasType') && method_exists($property, 'getType') && $property->hasType()) |
|
160 | + { |
|
148 | 161 | /** @var ReflectionType $type */ |
149 | 162 | $type = $property->getType(); |
150 | - if (method_exists($type, 'getName') && $this->isKnownType($type->getName())) { |
|
163 | + if (method_exists($type, 'getName') && $this->isKnownType($type->getName())) |
|
164 | + { |
|
151 | 165 | return $type->getName(); |
152 | 166 | } |
153 | 167 | } |
@@ -162,7 +176,8 @@ discard block |
||
162 | 176 | */ |
163 | 177 | private function getPropertyTypeFromDefaults(ReflectionProperty $property, ReflectionClass $reflection): ?string |
164 | 178 | { |
165 | - if (!isset($reflection->getDefaultProperties()[$property->name])) { |
|
179 | + if (!isset($reflection->getDefaultProperties()[$property->name])) |
|
180 | + { |
|
166 | 181 | return null; |
167 | 182 | } |
168 | 183 | |
@@ -178,9 +193,11 @@ discard block |
||
178 | 193 | private function getPropertyTypeFromDocBlock(ReflectionProperty $property): ?string |
179 | 194 | { |
180 | 195 | $doc = $property->getDocComment(); |
181 | - if (is_string($doc)) { |
|
196 | + if (is_string($doc)) |
|
197 | + { |
|
182 | 198 | preg_match('/@var\s*([\S]+)/i', $doc, $match); |
183 | - if (!empty($match[1]) && $this->isKnownType($match[1])) { |
|
199 | + if (!empty($match[1]) && $this->isKnownType($match[1])) |
|
200 | + { |
|
184 | 201 | return $match[1]; |
185 | 202 | } |
186 | 203 | } |