@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | |
25 | 25 | public function getHandler(string $jobType): HandlerInterface |
26 | 26 | { |
27 | - try { |
|
27 | + try{ |
|
28 | 28 | $handler = $this->container->get($this->className($jobType)); |
29 | - } catch (ContainerException $e) { |
|
29 | + }catch (ContainerException $e){ |
|
30 | 30 | throw new JobException($e->getMessage(), $e->getCode(), $e); |
31 | 31 | } |
32 | 32 | |
33 | - if (!$handler instanceof HandlerInterface) { |
|
33 | + if (!$handler instanceof HandlerInterface){ |
|
34 | 34 | throw new JobException("Unable to resolve job handler for `{$jobType}`"); |
35 | 35 | } |
36 | 36 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | private function className(string $jobType): string |
41 | 41 | { |
42 | 42 | $names = explode('.', $jobType); |
43 | - $names = array_map(function (string $value) { |
|
43 | + $names = array_map(function (string $value){ |
|
44 | 44 | return $this->inflector->classify($value); |
45 | 45 | }, $names); |
46 | 46 |
@@ -24,13 +24,17 @@ discard block |
||
24 | 24 | |
25 | 25 | public function getHandler(string $jobType): HandlerInterface |
26 | 26 | { |
27 | - try { |
|
27 | + try |
|
28 | + { |
|
28 | 29 | $handler = $this->container->get($this->className($jobType)); |
29 | - } catch (ContainerException $e) { |
|
30 | + } |
|
31 | + catch (ContainerException $e) |
|
32 | + { |
|
30 | 33 | throw new JobException($e->getMessage(), $e->getCode(), $e); |
31 | 34 | } |
32 | 35 | |
33 | - if (!$handler instanceof HandlerInterface) { |
|
36 | + if (!$handler instanceof HandlerInterface) |
|
37 | + { |
|
34 | 38 | throw new JobException("Unable to resolve job handler for `{$jobType}`"); |
35 | 39 | } |
36 | 40 | |
@@ -40,7 +44,8 @@ discard block |
||
40 | 44 | private function className(string $jobType): string |
41 | 45 | { |
42 | 46 | $names = explode('.', $jobType); |
43 | - $names = array_map(function (string $value) { |
|
47 | + $names = array_map(function (string $value) |
|
48 | + { |
|
44 | 49 | return $this->inflector->classify($value); |
45 | 50 | }, $names); |
46 | 51 |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $registry = $container->get(HandlerRegistryInterface::class); |
58 | 58 | $config = $container->get(QueueConfig::class); |
59 | 59 | |
60 | - foreach ($config->getRegistryHandlers() as $jobType => $handler) { |
|
60 | + foreach ($config->getRegistryHandlers() as $jobType => $handler){ |
|
61 | 61 | $registry->setHandler($jobType, $handler); |
62 | 62 | } |
63 | 63 | }); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | |
84 | 84 | private function registerJobsSerializer(Container $container): void |
85 | 85 | { |
86 | - $container->bindSingleton(SerializerInterface::class, static function () { |
|
86 | + $container->bindSingleton(SerializerInterface::class, static function (){ |
|
87 | 87 | return new DefaultSerializer(); |
88 | 88 | }); |
89 | 89 | } |
@@ -57,7 +57,8 @@ discard block |
||
57 | 57 | $registry = $container->get(HandlerRegistryInterface::class); |
58 | 58 | $config = $container->get(QueueConfig::class); |
59 | 59 | |
60 | - foreach ($config->getRegistryHandlers() as $jobType => $handler) { |
|
60 | + foreach ($config->getRegistryHandlers() as $jobType => $handler) |
|
61 | + { |
|
61 | 62 | $registry->setHandler($jobType, $handler); |
62 | 63 | } |
63 | 64 | }); |
@@ -83,7 +84,8 @@ discard block |
||
83 | 84 | |
84 | 85 | private function registerJobsSerializer(Container $container): void |
85 | 86 | { |
86 | - $container->bindSingleton(SerializerInterface::class, static function () { |
|
87 | + $container->bindSingleton(SerializerInterface::class, static function () |
|
88 | + { |
|
87 | 89 | return new DefaultSerializer(); |
88 | 90 | }); |
89 | 91 | } |
@@ -16,9 +16,9 @@ discard block |
||
16 | 16 | */ |
17 | 17 | public function serialize(array $payload): string |
18 | 18 | { |
19 | - try { |
|
19 | + try{ |
|
20 | 20 | return \Opis\Closure\serialize($payload); |
21 | - } catch (\Throwable $e) { |
|
21 | + }catch (\Throwable $e){ |
|
22 | 22 | throw new SerializationException($e->getMessage(), (int)$e->getCode(), $e); |
23 | 23 | } |
24 | 24 | } |
@@ -28,9 +28,9 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function deserialize(string $payload): array |
30 | 30 | { |
31 | - try { |
|
31 | + try{ |
|
32 | 32 | return (array)\Opis\Closure\unserialize($payload); |
33 | - } catch (\Throwable $e) { |
|
33 | + }catch (\Throwable $e){ |
|
34 | 34 | throw new SerializationException($e->getMessage(), (int)$e->getCode(), $e); |
35 | 35 | } |
36 | 36 | } |
@@ -16,9 +16,12 @@ discard block |
||
16 | 16 | */ |
17 | 17 | public function serialize(array $payload): string |
18 | 18 | { |
19 | - try { |
|
19 | + try |
|
20 | + { |
|
20 | 21 | return \Opis\Closure\serialize($payload); |
21 | - } catch (\Throwable $e) { |
|
22 | + } |
|
23 | + catch (\Throwable $e) |
|
24 | + { |
|
22 | 25 | throw new SerializationException($e->getMessage(), (int)$e->getCode(), $e); |
23 | 26 | } |
24 | 27 | } |
@@ -28,9 +31,12 @@ discard block |
||
28 | 31 | */ |
29 | 32 | public function deserialize(string $payload): array |
30 | 33 | { |
31 | - try { |
|
34 | + try |
|
35 | + { |
|
32 | 36 | return (array)\Opis\Closure\unserialize($payload); |
33 | - } catch (\Throwable $e) { |
|
37 | + } |
|
38 | + catch (\Throwable $e) |
|
39 | + { |
|
34 | 40 | throw new SerializationException($e->getMessage(), (int)$e->getCode(), $e); |
35 | 41 | } |
36 | 42 | } |
@@ -65,7 +65,8 @@ discard block |
||
65 | 65 | |
66 | 66 | $response = $this->scope->runScope( |
67 | 67 | [AuthContextInterface::class => $authContext], |
68 | - static function () use ($request, $handler, $authContext) { |
|
68 | + static function () use ($request, $handler, $authContext) |
|
69 | + { |
|
69 | 70 | return $handler->handle($request->withAttribute(self::ATTRIBUTE, $authContext)); |
70 | 71 | } |
71 | 72 | ); |
@@ -75,14 +76,17 @@ discard block |
||
75 | 76 | |
76 | 77 | private function initContext(Request $request, AuthContextInterface $authContext): AuthContextInterface |
77 | 78 | { |
78 | - foreach ($this->transportRegistry->getTransports() as $name => $transport) { |
|
79 | + foreach ($this->transportRegistry->getTransports() as $name => $transport) |
|
80 | + { |
|
79 | 81 | $tokenID = $transport->fetchToken($request); |
80 | - if ($tokenID === null) { |
|
82 | + if ($tokenID === null) |
|
83 | + { |
|
81 | 84 | continue; |
82 | 85 | } |
83 | 86 | |
84 | 87 | $token = $this->tokenStorage->load($tokenID); |
85 | - if ($token === null) { |
|
88 | + if ($token === null) |
|
89 | + { |
|
86 | 90 | continue; |
87 | 91 | } |
88 | 92 | |
@@ -96,13 +100,15 @@ discard block |
||
96 | 100 | |
97 | 101 | private function closeContext(Request $request, Response $response, AuthContextInterface $authContext): Response |
98 | 102 | { |
99 | - if ($authContext->getToken() === null) { |
|
103 | + if ($authContext->getToken() === null) |
|
104 | + { |
|
100 | 105 | return $response; |
101 | 106 | } |
102 | 107 | |
103 | 108 | $transport = $this->transportRegistry->getTransport($authContext->getTransport()); |
104 | 109 | |
105 | - if ($authContext->isClosed()) { |
|
110 | + if ($authContext->isClosed()) |
|
111 | + { |
|
106 | 112 | $this->tokenStorage->delete($authContext->getToken()); |
107 | 113 | |
108 | 114 | return $transport->removeToken( |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | public function __construct(array $config = []) |
35 | 35 | { |
36 | 36 | parent::__construct($config); |
37 | - if (!empty($this->config['aliases'])) { |
|
37 | + if (!empty($this->config['aliases'])){ |
|
38 | 38 | $this->config['aliases'] = $this->normalizeAliases($this->config['aliases']); |
39 | 39 | } |
40 | 40 | } |
@@ -50,12 +50,12 @@ discard block |
||
50 | 50 | */ |
51 | 51 | public function getChecker(string $name): Autowire |
52 | 52 | { |
53 | - if (!$this->hasChecker($name)) { |
|
53 | + if (!$this->hasChecker($name)){ |
|
54 | 54 | throw new ValidationException("Undefined checker `{$name}``."); |
55 | 55 | } |
56 | 56 | |
57 | 57 | $instance = $this->wire('checkers', $name); |
58 | - if ($instance !== null) { |
|
58 | + if ($instance !== null){ |
|
59 | 59 | return $instance; |
60 | 60 | } |
61 | 61 | |
@@ -69,12 +69,12 @@ discard block |
||
69 | 69 | |
70 | 70 | public function getCondition(string $name): Autowire |
71 | 71 | { |
72 | - if (!$this->hasCondition($name)) { |
|
72 | + if (!$this->hasCondition($name)){ |
|
73 | 73 | throw new ValidationException("Undefined condition `{$name}`."); |
74 | 74 | } |
75 | 75 | |
76 | 76 | $instance = $this->wire('conditions', $name); |
77 | - if ($instance !== null) { |
|
77 | + if ($instance !== null){ |
|
78 | 78 | return $instance; |
79 | 79 | } |
80 | 80 | |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public function mapFunction($function) |
92 | 92 | { |
93 | - if (is_string($function)) { |
|
93 | + if (is_string($function)){ |
|
94 | 94 | $function = $this->resolveAlias($function); |
95 | - if (strpos($function, ':') !== false) { |
|
95 | + if (strpos($function, ':') !== false){ |
|
96 | 96 | $function = explode(':', $function); |
97 | 97 | } |
98 | 98 | } |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | |
103 | 103 | private function wire(string $section, string $name): ?Autowire |
104 | 104 | { |
105 | - if (is_string($this->config[$section][$name])) { |
|
105 | + if (is_string($this->config[$section][$name])){ |
|
106 | 106 | return new Autowire($this->config[$section][$name]); |
107 | 107 | } |
108 | 108 | |
109 | - if (isset($this->config[$section][$name]['class'])) { |
|
109 | + if (isset($this->config[$section][$name]['class'])){ |
|
110 | 110 | return new Autowire( |
111 | 111 | $this->config[$section][$name]['class'], |
112 | 112 | $this->config[$section][$name]['options'] ?? [] |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | */ |
124 | 124 | private function normalizeAliases(array $aliases): array |
125 | 125 | { |
126 | - return array_map(static function ($value) { |
|
126 | + return array_map(static function ($value){ |
|
127 | 127 | return str_replace('::', ':', $value); |
128 | 128 | }, $aliases); |
129 | 129 | } |
@@ -34,7 +34,8 @@ discard block |
||
34 | 34 | public function __construct(array $config = []) |
35 | 35 | { |
36 | 36 | parent::__construct($config); |
37 | - if (!empty($this->config['aliases'])) { |
|
37 | + if (!empty($this->config['aliases'])) |
|
38 | + { |
|
38 | 39 | $this->config['aliases'] = $this->normalizeAliases($this->config['aliases']); |
39 | 40 | } |
40 | 41 | } |
@@ -50,12 +51,14 @@ discard block |
||
50 | 51 | */ |
51 | 52 | public function getChecker(string $name): Autowire |
52 | 53 | { |
53 | - if (!$this->hasChecker($name)) { |
|
54 | + if (!$this->hasChecker($name)) |
|
55 | + { |
|
54 | 56 | throw new ValidationException("Undefined checker `{$name}``."); |
55 | 57 | } |
56 | 58 | |
57 | 59 | $instance = $this->wire('checkers', $name); |
58 | - if ($instance !== null) { |
|
60 | + if ($instance !== null) |
|
61 | + { |
|
59 | 62 | return $instance; |
60 | 63 | } |
61 | 64 | |
@@ -69,12 +72,14 @@ discard block |
||
69 | 72 | |
70 | 73 | public function getCondition(string $name): Autowire |
71 | 74 | { |
72 | - if (!$this->hasCondition($name)) { |
|
75 | + if (!$this->hasCondition($name)) |
|
76 | + { |
|
73 | 77 | throw new ValidationException("Undefined condition `{$name}`."); |
74 | 78 | } |
75 | 79 | |
76 | 80 | $instance = $this->wire('conditions', $name); |
77 | - if ($instance !== null) { |
|
81 | + if ($instance !== null) |
|
82 | + { |
|
78 | 83 | return $instance; |
79 | 84 | } |
80 | 85 | |
@@ -90,9 +95,11 @@ discard block |
||
90 | 95 | */ |
91 | 96 | public function mapFunction($function) |
92 | 97 | { |
93 | - if (is_string($function)) { |
|
98 | + if (is_string($function)) |
|
99 | + { |
|
94 | 100 | $function = $this->resolveAlias($function); |
95 | - if (strpos($function, ':') !== false) { |
|
101 | + if (strpos($function, ':') !== false) |
|
102 | + { |
|
96 | 103 | $function = explode(':', $function); |
97 | 104 | } |
98 | 105 | } |
@@ -102,11 +109,13 @@ discard block |
||
102 | 109 | |
103 | 110 | private function wire(string $section, string $name): ?Autowire |
104 | 111 | { |
105 | - if (is_string($this->config[$section][$name])) { |
|
112 | + if (is_string($this->config[$section][$name])) |
|
113 | + { |
|
106 | 114 | return new Autowire($this->config[$section][$name]); |
107 | 115 | } |
108 | 116 | |
109 | - if (isset($this->config[$section][$name]['class'])) { |
|
117 | + if (isset($this->config[$section][$name]['class'])) |
|
118 | + { |
|
110 | 119 | return new Autowire( |
111 | 120 | $this->config[$section][$name]['class'], |
112 | 121 | $this->config[$section][$name]['options'] ?? [] |
@@ -123,7 +132,8 @@ discard block |
||
123 | 132 | */ |
124 | 133 | private function normalizeAliases(array $aliases): array |
125 | 134 | { |
126 | - return array_map(static function ($value) { |
|
135 | + return array_map(static function ($value) |
|
136 | + { |
|
127 | 137 | return str_replace('::', ':', $value); |
128 | 138 | }, $aliases); |
129 | 139 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function __construct(array $items = []) |
38 | 38 | { |
39 | - foreach ($items as $item) { |
|
39 | + foreach ($items as $item){ |
|
40 | 40 | $this->addItem($item); |
41 | 41 | } |
42 | 42 | } |
@@ -51,9 +51,9 @@ discard block |
||
51 | 51 | $header = new static(); |
52 | 52 | |
53 | 53 | $parts = explode(',', $raw); |
54 | - foreach ($parts as $part) { |
|
54 | + foreach ($parts as $part){ |
|
55 | 55 | $part = trim($part); |
56 | - if ($part !== '') { |
|
56 | + if ($part !== ''){ |
|
57 | 57 | $header->addItem($part); |
58 | 58 | } |
59 | 59 | } |
@@ -87,11 +87,11 @@ discard block |
||
87 | 87 | */ |
88 | 88 | public function getAll(): array |
89 | 89 | { |
90 | - if (!$this->sorted) { |
|
90 | + if (!$this->sorted){ |
|
91 | 91 | /** |
92 | 92 | * Sort item in descending order. |
93 | 93 | */ |
94 | - uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b) { |
|
94 | + uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b){ |
|
95 | 95 | return self::compare($a, $b) * -1; |
96 | 96 | }); |
97 | 97 | |
@@ -108,12 +108,12 @@ discard block |
||
108 | 108 | */ |
109 | 109 | private function addItem($item): void |
110 | 110 | { |
111 | - if (is_scalar($item)) { |
|
111 | + if (is_scalar($item)){ |
|
112 | 112 | $item = AcceptHeaderItem::fromString((string)$item); |
113 | 113 | } |
114 | 114 | |
115 | 115 | /** @var AcceptHeaderItem|array $item */ |
116 | - if (!$item instanceof AcceptHeaderItem) { |
|
116 | + if (!$item instanceof AcceptHeaderItem){ |
|
117 | 117 | throw new AcceptHeaderException(sprintf( |
118 | 118 | 'Accept Header item expected to be an instance of `%s` or a string, got `%s`', |
119 | 119 | AcceptHeaderItem::class, |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | $value = strtolower($item->getValue()); |
125 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
125 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)){ |
|
126 | 126 | $this->sorted = false; |
127 | 127 | $this->items[$value] = $item; |
128 | 128 | } |
@@ -137,9 +137,9 @@ discard block |
||
137 | 137 | */ |
138 | 138 | private static function compare(AcceptHeaderItem $a, AcceptHeaderItem $b): int |
139 | 139 | { |
140 | - if ($a->getQuality() === $b->getQuality()) { |
|
140 | + if ($a->getQuality() === $b->getQuality()){ |
|
141 | 141 | // If quality are same value with more params has more weight. |
142 | - if (count($a->getParams()) === count($b->getParams())) { |
|
142 | + if (count($a->getParams()) === count($b->getParams())){ |
|
143 | 143 | // If quality and params then check for specific type or subtype. |
144 | 144 | // Means */* or * has less weight. |
145 | 145 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -158,11 +158,11 @@ discard block |
||
158 | 158 | private static function compareValue(string $a, string $b): int |
159 | 159 | { |
160 | 160 | // Check "Accept" headers values with it is type and subtype. |
161 | - if (strpos($a, '/') !== false && strpos($b, '/') !== false) { |
|
161 | + if (strpos($a, '/') !== false && strpos($b, '/') !== false){ |
|
162 | 162 | [$typeA, $subtypeA] = explode('/', $a, 2); |
163 | 163 | [$typeB, $subtypeB] = explode('/', $b, 2); |
164 | 164 | |
165 | - if ($typeA === $typeB) { |
|
165 | + if ($typeA === $typeB){ |
|
166 | 166 | return static::compareAtomic($subtypeA, $subtypeB); |
167 | 167 | } |
168 | 168 | |
@@ -174,23 +174,23 @@ discard block |
||
174 | 174 | |
175 | 175 | private static function compareAtomic(string $a, string $b): int |
176 | 176 | { |
177 | - if (mb_strpos($a, '*/') === 0) { |
|
177 | + if (mb_strpos($a, '*/') === 0){ |
|
178 | 178 | $a = '*'; |
179 | 179 | } |
180 | 180 | |
181 | - if (mb_strpos($b, '*/') === 0) { |
|
181 | + if (mb_strpos($b, '*/') === 0){ |
|
182 | 182 | $b = '*'; |
183 | 183 | } |
184 | 184 | |
185 | - if (strtolower($a) === strtolower($b)) { |
|
185 | + if (strtolower($a) === strtolower($b)){ |
|
186 | 186 | return 0; |
187 | 187 | } |
188 | 188 | |
189 | - if ($a === '*') { |
|
189 | + if ($a === '*'){ |
|
190 | 190 | return -1; |
191 | 191 | } |
192 | 192 | |
193 | - if ($b === '*') { |
|
193 | + if ($b === '*'){ |
|
194 | 194 | return 1; |
195 | 195 | } |
196 | 196 |
@@ -36,7 +36,8 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function __construct(array $items = []) |
38 | 38 | { |
39 | - foreach ($items as $item) { |
|
39 | + foreach ($items as $item) |
|
40 | + { |
|
40 | 41 | $this->addItem($item); |
41 | 42 | } |
42 | 43 | } |
@@ -51,9 +52,11 @@ discard block |
||
51 | 52 | $header = new static(); |
52 | 53 | |
53 | 54 | $parts = explode(',', $raw); |
54 | - foreach ($parts as $part) { |
|
55 | + foreach ($parts as $part) |
|
56 | + { |
|
55 | 57 | $part = trim($part); |
56 | - if ($part !== '') { |
|
58 | + if ($part !== '') |
|
59 | + { |
|
57 | 60 | $header->addItem($part); |
58 | 61 | } |
59 | 62 | } |
@@ -87,11 +90,13 @@ discard block |
||
87 | 90 | */ |
88 | 91 | public function getAll(): array |
89 | 92 | { |
90 | - if (!$this->sorted) { |
|
93 | + if (!$this->sorted) |
|
94 | + { |
|
91 | 95 | /** |
92 | 96 | * Sort item in descending order. |
93 | 97 | */ |
94 | - uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b) { |
|
98 | + uasort($this->items, static function (AcceptHeaderItem $a, AcceptHeaderItem $b) |
|
99 | + { |
|
95 | 100 | return self::compare($a, $b) * -1; |
96 | 101 | }); |
97 | 102 | |
@@ -108,12 +113,14 @@ discard block |
||
108 | 113 | */ |
109 | 114 | private function addItem($item): void |
110 | 115 | { |
111 | - if (is_scalar($item)) { |
|
116 | + if (is_scalar($item)) |
|
117 | + { |
|
112 | 118 | $item = AcceptHeaderItem::fromString((string)$item); |
113 | 119 | } |
114 | 120 | |
115 | 121 | /** @var AcceptHeaderItem|array $item */ |
116 | - if (!$item instanceof AcceptHeaderItem) { |
|
122 | + if (!$item instanceof AcceptHeaderItem) |
|
123 | + { |
|
117 | 124 | throw new AcceptHeaderException(sprintf( |
118 | 125 | 'Accept Header item expected to be an instance of `%s` or a string, got `%s`', |
119 | 126 | AcceptHeaderItem::class, |
@@ -122,7 +129,8 @@ discard block |
||
122 | 129 | } |
123 | 130 | |
124 | 131 | $value = strtolower($item->getValue()); |
125 | - if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) { |
|
132 | + if ($value !== '' && (!$this->has($value) || self::compare($item, $this->get($value)) === 1)) |
|
133 | + { |
|
126 | 134 | $this->sorted = false; |
127 | 135 | $this->items[$value] = $item; |
128 | 136 | } |
@@ -137,9 +145,11 @@ discard block |
||
137 | 145 | */ |
138 | 146 | private static function compare(AcceptHeaderItem $a, AcceptHeaderItem $b): int |
139 | 147 | { |
140 | - if ($a->getQuality() === $b->getQuality()) { |
|
148 | + if ($a->getQuality() === $b->getQuality()) |
|
149 | + { |
|
141 | 150 | // If quality are same value with more params has more weight. |
142 | - if (count($a->getParams()) === count($b->getParams())) { |
|
151 | + if (count($a->getParams()) === count($b->getParams())) |
|
152 | + { |
|
143 | 153 | // If quality and params then check for specific type or subtype. |
144 | 154 | // Means */* or * has less weight. |
145 | 155 | return static::compareValue($a->getValue(), $b->getValue()); |
@@ -158,11 +168,13 @@ discard block |
||
158 | 168 | private static function compareValue(string $a, string $b): int |
159 | 169 | { |
160 | 170 | // Check "Accept" headers values with it is type and subtype. |
161 | - if (strpos($a, '/') !== false && strpos($b, '/') !== false) { |
|
171 | + if (strpos($a, '/') !== false && strpos($b, '/') !== false) |
|
172 | + { |
|
162 | 173 | [$typeA, $subtypeA] = explode('/', $a, 2); |
163 | 174 | [$typeB, $subtypeB] = explode('/', $b, 2); |
164 | 175 | |
165 | - if ($typeA === $typeB) { |
|
176 | + if ($typeA === $typeB) |
|
177 | + { |
|
166 | 178 | return static::compareAtomic($subtypeA, $subtypeB); |
167 | 179 | } |
168 | 180 | |
@@ -174,23 +186,28 @@ discard block |
||
174 | 186 | |
175 | 187 | private static function compareAtomic(string $a, string $b): int |
176 | 188 | { |
177 | - if (mb_strpos($a, '*/') === 0) { |
|
189 | + if (mb_strpos($a, '*/') === 0) |
|
190 | + { |
|
178 | 191 | $a = '*'; |
179 | 192 | } |
180 | 193 | |
181 | - if (mb_strpos($b, '*/') === 0) { |
|
194 | + if (mb_strpos($b, '*/') === 0) |
|
195 | + { |
|
182 | 196 | $b = '*'; |
183 | 197 | } |
184 | 198 | |
185 | - if (strtolower($a) === strtolower($b)) { |
|
199 | + if (strtolower($a) === strtolower($b)) |
|
200 | + { |
|
186 | 201 | return 0; |
187 | 202 | } |
188 | 203 | |
189 | - if ($a === '*') { |
|
204 | + if ($a === '*') |
|
205 | + { |
|
190 | 206 | return -1; |
191 | 207 | } |
192 | 208 | |
193 | - if ($b === '*') { |
|
209 | + if ($b === '*') |
|
210 | + { |
|
194 | 211 | return 1; |
195 | 212 | } |
196 | 213 |
@@ -105,8 +105,8 @@ discard block |
||
105 | 105 | { |
106 | 106 | $eval = new ConstExprEvaluator($this->evaluator($file, $context)); |
107 | 107 | |
108 | - foreach ($groups as $group) { |
|
109 | - foreach ($group->attrs as $attr) { |
|
108 | + foreach ($groups as $group){ |
|
109 | + foreach ($group->attrs as $attr){ |
|
110 | 110 | $arguments = $this->parseAttributeArguments($attr, $file, $eval); |
111 | 111 | |
112 | 112 | yield new AttributePrototype($attr->name->toString(), $arguments); |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | |
124 | 124 | private function read(string $file): string |
125 | 125 | { |
126 | - if (!\is_readable($file)) { |
|
127 | - throw new \InvalidArgumentException('Unable to read file "' . $file . '"'); |
|
126 | + if (!\is_readable($file)){ |
|
127 | + throw new \InvalidArgumentException('Unable to read file "'.$file.'"'); |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | return \file_get_contents($file); |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | private function evaluator(string $file, array $context): \Closure |
134 | 134 | { |
135 | 135 | return static function (Expr $expr) use ($file, $context) { |
136 | - switch (\get_class($expr)) { |
|
136 | + switch (\get_class($expr)){ |
|
137 | 137 | case Scalar\MagicConst\File::class: |
138 | 138 | return $file; |
139 | 139 | |
@@ -147,19 +147,19 @@ discard block |
||
147 | 147 | $namespace = $context[self::CTX_NAMESPACE] ?? ''; |
148 | 148 | $function = $context[self::CTX_FUNCTION] ?? ''; |
149 | 149 | |
150 | - return \ltrim($namespace . '\\' . $function, '\\'); |
|
150 | + return \ltrim($namespace.'\\'.$function, '\\'); |
|
151 | 151 | |
152 | 152 | case Expr\ClassConstFetch::class: |
153 | 153 | $constant = $expr->name->toString(); |
154 | 154 | $class = $expr->class->toString(); |
155 | 155 | |
156 | - if (\strtolower($constant) === 'class') { |
|
156 | + if (\strtolower($constant) === 'class'){ |
|
157 | 157 | return $class; |
158 | 158 | } |
159 | 159 | |
160 | - $definition = $class . '::' . $constant; |
|
160 | + $definition = $class.'::'.$constant; |
|
161 | 161 | |
162 | - if (!\defined($definition)) { |
|
162 | + if (!\defined($definition)){ |
|
163 | 163 | $exception = new \ParseError(\sprintf(self::ERROR_BAD_CONSTANT, $definition)); |
164 | 164 | throw Exception::withLocation($exception, $file, $expr->getStartLine()); |
165 | 165 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | return \constant($definition); |
168 | 168 | } |
169 | 169 | |
170 | - if ($expr instanceof Scalar\MagicConst) { |
|
170 | + if ($expr instanceof Scalar\MagicConst){ |
|
171 | 171 | return $context[$expr->getName()] ?? ''; |
172 | 172 | } |
173 | 173 | |
@@ -185,13 +185,13 @@ discard block |
||
185 | 185 | $hasNamedArguments = false; |
186 | 186 | $arguments = []; |
187 | 187 | |
188 | - foreach ($attr->args as $argument) { |
|
188 | + foreach ($attr->args as $argument){ |
|
189 | 189 | $value = $eval->evaluateDirectly($argument->value); |
190 | 190 | |
191 | - if ($argument->name === null) { |
|
191 | + if ($argument->name === null){ |
|
192 | 192 | $arguments[] = $value; |
193 | 193 | |
194 | - if ($hasNamedArguments) { |
|
194 | + if ($hasNamedArguments){ |
|
195 | 195 | $exception = new \ParseError(self::ERROR_NAMED_ARGUMENTS_ORDER); |
196 | 196 | throw Exception::withLocation($exception, $file, $argument->getStartLine()); |
197 | 197 | } |
@@ -105,8 +105,10 @@ discard block |
||
105 | 105 | { |
106 | 106 | $eval = new ConstExprEvaluator($this->evaluator($file, $context)); |
107 | 107 | |
108 | - foreach ($groups as $group) { |
|
109 | - foreach ($group->attrs as $attr) { |
|
108 | + foreach ($groups as $group) |
|
109 | + { |
|
110 | + foreach ($group->attrs as $attr) |
|
111 | + { |
|
110 | 112 | $arguments = $this->parseAttributeArguments($attr, $file, $eval); |
111 | 113 | |
112 | 114 | yield new AttributePrototype($attr->name->toString(), $arguments); |
@@ -123,7 +125,8 @@ discard block |
||
123 | 125 | |
124 | 126 | private function read(string $file): string |
125 | 127 | { |
126 | - if (!\is_readable($file)) { |
|
128 | + if (!\is_readable($file)) |
|
129 | + { |
|
127 | 130 | throw new \InvalidArgumentException('Unable to read file "' . $file . '"'); |
128 | 131 | } |
129 | 132 | |
@@ -132,8 +135,10 @@ discard block |
||
132 | 135 | |
133 | 136 | private function evaluator(string $file, array $context): \Closure |
134 | 137 | { |
135 | - return static function (Expr $expr) use ($file, $context) { |
|
136 | - switch (\get_class($expr)) { |
|
138 | + return static function (Expr $expr) use ($file, $context) |
|
139 | + { |
|
140 | + switch (\get_class($expr)) |
|
141 | + { |
|
137 | 142 | case Scalar\MagicConst\File::class: |
138 | 143 | return $file; |
139 | 144 | |
@@ -153,13 +158,15 @@ discard block |
||
153 | 158 | $constant = $expr->name->toString(); |
154 | 159 | $class = $expr->class->toString(); |
155 | 160 | |
156 | - if (\strtolower($constant) === 'class') { |
|
161 | + if (\strtolower($constant) === 'class') |
|
162 | + { |
|
157 | 163 | return $class; |
158 | 164 | } |
159 | 165 | |
160 | 166 | $definition = $class . '::' . $constant; |
161 | 167 | |
162 | - if (!\defined($definition)) { |
|
168 | + if (!\defined($definition)) |
|
169 | + { |
|
163 | 170 | $exception = new \ParseError(\sprintf(self::ERROR_BAD_CONSTANT, $definition)); |
164 | 171 | throw Exception::withLocation($exception, $file, $expr->getStartLine()); |
165 | 172 | } |
@@ -167,7 +174,8 @@ discard block |
||
167 | 174 | return \constant($definition); |
168 | 175 | } |
169 | 176 | |
170 | - if ($expr instanceof Scalar\MagicConst) { |
|
177 | + if ($expr instanceof Scalar\MagicConst) |
|
178 | + { |
|
171 | 179 | return $context[$expr->getName()] ?? ''; |
172 | 180 | } |
173 | 181 | |
@@ -185,13 +193,16 @@ discard block |
||
185 | 193 | $hasNamedArguments = false; |
186 | 194 | $arguments = []; |
187 | 195 | |
188 | - foreach ($attr->args as $argument) { |
|
196 | + foreach ($attr->args as $argument) |
|
197 | + { |
|
189 | 198 | $value = $eval->evaluateDirectly($argument->value); |
190 | 199 | |
191 | - if ($argument->name === null) { |
|
200 | + if ($argument->name === null) |
|
201 | + { |
|
192 | 202 | $arguments[] = $value; |
193 | 203 | |
194 | - if ($hasNamedArguments) { |
|
204 | + if ($hasNamedArguments) |
|
205 | + { |
|
195 | 206 | $exception = new \ParseError(self::ERROR_NAMED_ARGUMENTS_ORDER); |
196 | 207 | throw Exception::withLocation($exception, $file, $argument->getStartLine()); |
197 | 208 | } |
@@ -140,23 +140,23 @@ discard block |
||
140 | 140 | { |
141 | 141 | $this->updateContext($node); |
142 | 142 | |
143 | - if ($node instanceof Node\Stmt\ClassLike) { |
|
144 | - foreach ($this->parse($node->attrGroups) as $prototype) { |
|
143 | + if ($node instanceof Node\Stmt\ClassLike){ |
|
144 | + foreach ($this->parse($node->attrGroups) as $prototype){ |
|
145 | 145 | $this->classes[$node->namespacedName->toString()][] = $prototype; |
146 | 146 | } |
147 | 147 | |
148 | 148 | return null; |
149 | 149 | } |
150 | 150 | |
151 | - if ($node instanceof Node\FunctionLike) { |
|
151 | + if ($node instanceof Node\FunctionLike){ |
|
152 | 152 | $line = $node->getEndLine(); |
153 | 153 | |
154 | - foreach ($this->parse($node->getAttrGroups()) as $prototype) { |
|
154 | + foreach ($this->parse($node->getAttrGroups()) as $prototype){ |
|
155 | 155 | $this->functions[$line][] = $prototype; |
156 | 156 | } |
157 | 157 | |
158 | - foreach ($node->getParams() as $param) { |
|
159 | - foreach ($this->parse($param->attrGroups) as $prototype) { |
|
158 | + foreach ($node->getParams() as $param){ |
|
159 | + foreach ($this->parse($param->attrGroups) as $prototype){ |
|
160 | 160 | assert(\is_string($param->var->name), 'Function parameter name should be an identifier'); |
161 | 161 | |
162 | 162 | $this->parameters[$line][$param->var->name][] = $prototype; |
@@ -166,11 +166,11 @@ discard block |
||
166 | 166 | return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
167 | 167 | } |
168 | 168 | |
169 | - if ($node instanceof Node\Stmt\ClassConst) { |
|
169 | + if ($node instanceof Node\Stmt\ClassConst){ |
|
170 | 170 | $class = $this->fqn(); |
171 | 171 | |
172 | - foreach ($this->parse($node->attrGroups) as $prototype) { |
|
173 | - foreach ($node->consts as $const) { |
|
172 | + foreach ($this->parse($node->attrGroups) as $prototype){ |
|
173 | + foreach ($node->consts as $const){ |
|
174 | 174 | $this->constants[$class][$this->name($const->name)][] = $prototype; |
175 | 175 | } |
176 | 176 | } |
@@ -178,11 +178,11 @@ discard block |
||
178 | 178 | return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
179 | 179 | } |
180 | 180 | |
181 | - if ($node instanceof Property) { |
|
181 | + if ($node instanceof Property){ |
|
182 | 182 | $class = $this->fqn(); |
183 | 183 | |
184 | - foreach ($this->parse($node->attrGroups) as $prototype) { |
|
185 | - foreach ($node->props as $property) { |
|
184 | + foreach ($this->parse($node->attrGroups) as $prototype){ |
|
185 | + foreach ($node->props as $property){ |
|
186 | 186 | $this->properties[$class][$this->name($property->name)][] = $prototype; |
187 | 187 | } |
188 | 188 | } |
@@ -195,27 +195,27 @@ discard block |
||
195 | 195 | |
196 | 196 | public function leaveNode(Node $node): void |
197 | 197 | { |
198 | - if ($node instanceof Node\Stmt\Namespace_) { |
|
198 | + if ($node instanceof Node\Stmt\Namespace_){ |
|
199 | 199 | $this->context[AttributeParser::CTX_NAMESPACE] = ''; |
200 | 200 | |
201 | 201 | return; |
202 | 202 | } |
203 | 203 | |
204 | - if ($node instanceof Node\Stmt\ClassLike) { |
|
204 | + if ($node instanceof Node\Stmt\ClassLike){ |
|
205 | 205 | $this->context[AttributeParser::CTX_CLASS] = ''; |
206 | 206 | $this->context[AttributeParser::CTX_TRAIT] = ''; |
207 | 207 | |
208 | 208 | return; |
209 | 209 | } |
210 | 210 | |
211 | - if ($node instanceof Node\FunctionLike) { |
|
211 | + if ($node instanceof Node\FunctionLike){ |
|
212 | 212 | $this->context[AttributeParser::CTX_FUNCTION] = ''; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | |
216 | 216 | private function updateContext(Node $node): void |
217 | 217 | { |
218 | - switch (true) { |
|
218 | + switch (true){ |
|
219 | 219 | case $node instanceof Node\Stmt\Namespace_: |
220 | 220 | $this->context[AttributeParser::CTX_NAMESPACE] = $this->name($node->name); |
221 | 221 | break; |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | */ |
241 | 241 | private function name($name): string |
242 | 242 | { |
243 | - if ($name === null) { |
|
243 | + if ($name === null){ |
|
244 | 244 | return ''; |
245 | 245 | } |
246 | 246 | |
@@ -262,6 +262,6 @@ discard block |
||
262 | 262 | $namespace = $this->context[AttributeParser::CTX_NAMESPACE] ?? ''; |
263 | 263 | $class = $this->context[AttributeParser::CTX_CLASS] ?? ''; |
264 | 264 | |
265 | - return \trim($namespace . '\\' . $class, '\\'); |
|
265 | + return \trim($namespace.'\\'.$class, '\\'); |
|
266 | 266 | } |
267 | 267 | } |
@@ -140,23 +140,29 @@ discard block |
||
140 | 140 | { |
141 | 141 | $this->updateContext($node); |
142 | 142 | |
143 | - if ($node instanceof Node\Stmt\ClassLike) { |
|
144 | - foreach ($this->parse($node->attrGroups) as $prototype) { |
|
143 | + if ($node instanceof Node\Stmt\ClassLike) |
|
144 | + { |
|
145 | + foreach ($this->parse($node->attrGroups) as $prototype) |
|
146 | + { |
|
145 | 147 | $this->classes[$node->namespacedName->toString()][] = $prototype; |
146 | 148 | } |
147 | 149 | |
148 | 150 | return null; |
149 | 151 | } |
150 | 152 | |
151 | - if ($node instanceof Node\FunctionLike) { |
|
153 | + if ($node instanceof Node\FunctionLike) |
|
154 | + { |
|
152 | 155 | $line = $node->getEndLine(); |
153 | 156 | |
154 | - foreach ($this->parse($node->getAttrGroups()) as $prototype) { |
|
157 | + foreach ($this->parse($node->getAttrGroups()) as $prototype) |
|
158 | + { |
|
155 | 159 | $this->functions[$line][] = $prototype; |
156 | 160 | } |
157 | 161 | |
158 | - foreach ($node->getParams() as $param) { |
|
159 | - foreach ($this->parse($param->attrGroups) as $prototype) { |
|
162 | + foreach ($node->getParams() as $param) |
|
163 | + { |
|
164 | + foreach ($this->parse($param->attrGroups) as $prototype) |
|
165 | + { |
|
160 | 166 | assert(\is_string($param->var->name), 'Function parameter name should be an identifier'); |
161 | 167 | |
162 | 168 | $this->parameters[$line][$param->var->name][] = $prototype; |
@@ -166,11 +172,14 @@ discard block |
||
166 | 172 | return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
167 | 173 | } |
168 | 174 | |
169 | - if ($node instanceof Node\Stmt\ClassConst) { |
|
175 | + if ($node instanceof Node\Stmt\ClassConst) |
|
176 | + { |
|
170 | 177 | $class = $this->fqn(); |
171 | 178 | |
172 | - foreach ($this->parse($node->attrGroups) as $prototype) { |
|
173 | - foreach ($node->consts as $const) { |
|
179 | + foreach ($this->parse($node->attrGroups) as $prototype) |
|
180 | + { |
|
181 | + foreach ($node->consts as $const) |
|
182 | + { |
|
174 | 183 | $this->constants[$class][$this->name($const->name)][] = $prototype; |
175 | 184 | } |
176 | 185 | } |
@@ -178,11 +187,14 @@ discard block |
||
178 | 187 | return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; |
179 | 188 | } |
180 | 189 | |
181 | - if ($node instanceof Property) { |
|
190 | + if ($node instanceof Property) |
|
191 | + { |
|
182 | 192 | $class = $this->fqn(); |
183 | 193 | |
184 | - foreach ($this->parse($node->attrGroups) as $prototype) { |
|
185 | - foreach ($node->props as $property) { |
|
194 | + foreach ($this->parse($node->attrGroups) as $prototype) |
|
195 | + { |
|
196 | + foreach ($node->props as $property) |
|
197 | + { |
|
186 | 198 | $this->properties[$class][$this->name($property->name)][] = $prototype; |
187 | 199 | } |
188 | 200 | } |
@@ -195,27 +207,31 @@ discard block |
||
195 | 207 | |
196 | 208 | public function leaveNode(Node $node): void |
197 | 209 | { |
198 | - if ($node instanceof Node\Stmt\Namespace_) { |
|
210 | + if ($node instanceof Node\Stmt\Namespace_) |
|
211 | + { |
|
199 | 212 | $this->context[AttributeParser::CTX_NAMESPACE] = ''; |
200 | 213 | |
201 | 214 | return; |
202 | 215 | } |
203 | 216 | |
204 | - if ($node instanceof Node\Stmt\ClassLike) { |
|
217 | + if ($node instanceof Node\Stmt\ClassLike) |
|
218 | + { |
|
205 | 219 | $this->context[AttributeParser::CTX_CLASS] = ''; |
206 | 220 | $this->context[AttributeParser::CTX_TRAIT] = ''; |
207 | 221 | |
208 | 222 | return; |
209 | 223 | } |
210 | 224 | |
211 | - if ($node instanceof Node\FunctionLike) { |
|
225 | + if ($node instanceof Node\FunctionLike) |
|
226 | + { |
|
212 | 227 | $this->context[AttributeParser::CTX_FUNCTION] = ''; |
213 | 228 | } |
214 | 229 | } |
215 | 230 | |
216 | 231 | private function updateContext(Node $node): void |
217 | 232 | { |
218 | - switch (true) { |
|
233 | + switch (true) |
|
234 | + { |
|
219 | 235 | case $node instanceof Node\Stmt\Namespace_: |
220 | 236 | $this->context[AttributeParser::CTX_NAMESPACE] = $this->name($node->name); |
221 | 237 | break; |
@@ -240,7 +256,8 @@ discard block |
||
240 | 256 | */ |
241 | 257 | private function name($name): string |
242 | 258 | { |
243 | - if ($name === null) { |
|
259 | + if ($name === null) |
|
260 | + { |
|
244 | 261 | return ''; |
245 | 262 | } |
246 | 263 |
@@ -38,13 +38,13 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function leaveNode(Node $node) |
40 | 40 | { |
41 | - if (!$node instanceof Node\Stmt\Class_) { |
|
41 | + if (!$node instanceof Node\Stmt\Class_){ |
|
42 | 42 | return null; |
43 | 43 | } |
44 | 44 | |
45 | 45 | $constructor = $this->getConstructorAttribute($node); |
46 | 46 | $this->addDependencies($constructor); |
47 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
47 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams){ |
|
48 | 48 | $this->addParentConstructorCall($constructor); |
49 | 49 | } |
50 | 50 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | */ |
61 | 61 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
62 | 62 | { |
63 | - foreach ($this->definition->dependencies as $dependency) { |
|
63 | + foreach ($this->definition->dependencies as $dependency){ |
|
64 | 64 | array_unshift($constructor->params, $this->buildConstructorParam($dependency)); |
65 | 65 | array_unshift( |
66 | 66 | $constructor->stmts, |
@@ -83,34 +83,34 @@ discard block |
||
83 | 83 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
84 | 84 | { |
85 | 85 | $parentConstructorDependencies = []; |
86 | - foreach ($this->definition->constructorParams as $param) { |
|
86 | + foreach ($this->definition->constructorParams as $param){ |
|
87 | 87 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
88 | 88 | |
89 | 89 | $cp = new Param($param->name); |
90 | - if (!empty($param->type)) { |
|
90 | + if (!empty($param->type)){ |
|
91 | 91 | $type = $this->getParamType($param); |
92 | - if ($param->nullable) { |
|
92 | + if ($param->nullable){ |
|
93 | 93 | $type = "?$type"; |
94 | 94 | } |
95 | 95 | |
96 | 96 | $cp->setType(new Node\Name($type)); |
97 | 97 | } |
98 | 98 | |
99 | - if ($param->byRef) { |
|
99 | + if ($param->byRef){ |
|
100 | 100 | $cp->makeByRef(); |
101 | 101 | } |
102 | 102 | |
103 | - if ($param->isVariadic) { |
|
103 | + if ($param->isVariadic){ |
|
104 | 104 | $cp->makeVariadic(); |
105 | 105 | } |
106 | 106 | |
107 | - if ($param->hasDefault) { |
|
107 | + if ($param->hasDefault){ |
|
108 | 108 | $cp->setDefault($param->default); |
109 | 109 | } |
110 | 110 | $constructor->params[] = $cp->getNode(); |
111 | 111 | } |
112 | 112 | |
113 | - if ($parentConstructorDependencies) { |
|
113 | + if ($parentConstructorDependencies){ |
|
114 | 114 | array_unshift( |
115 | 115 | $constructor->stmts, |
116 | 116 | new Node\Stmt\Expression( |
@@ -140,18 +140,18 @@ discard block |
||
140 | 140 | |
141 | 141 | $params = []; |
142 | 142 | |
143 | - foreach ($this->definition->dependencies as $dependency) { |
|
143 | + foreach ($this->definition->dependencies as $dependency){ |
|
144 | 144 | $params[] = new Annotation\Line( |
145 | 145 | sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), |
146 | 146 | 'param' |
147 | 147 | ); |
148 | 148 | } |
149 | 149 | |
150 | - if (!$this->definition->hasConstructor) { |
|
151 | - foreach ($this->definition->constructorParams as $param) { |
|
152 | - if (!empty($param->type)) { |
|
150 | + if (!$this->definition->hasConstructor){ |
|
151 | + foreach ($this->definition->constructorParams as $param){ |
|
152 | + if (!empty($param->type)){ |
|
153 | 153 | $type = $this->getParamType($param); |
154 | - if ($param->nullable) { |
|
154 | + if ($param->nullable){ |
|
155 | 155 | $type = "$type|null"; |
156 | 156 | } |
157 | 157 | |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), |
160 | 160 | 'param' |
161 | 161 | ); |
162 | - } else { |
|
162 | + }else{ |
|
163 | 163 | $params[] = new Annotation\Line( |
164 | 164 | sprintf('$%s', $param->name), |
165 | 165 | 'param' |
@@ -170,12 +170,12 @@ discard block |
||
170 | 170 | |
171 | 171 | $placementID = 0; |
172 | 172 | $previous = null; |
173 | - foreach ($an->lines as $index => $line) { |
|
173 | + foreach ($an->lines as $index => $line){ |
|
174 | 174 | // always next node |
175 | 175 | $placementID = $index + 1; |
176 | 176 | |
177 | 177 | // inject before this parameters |
178 | - if ($line->is(['throws', 'return'])) { |
|
178 | + if ($line->is(['throws', 'return'])){ |
|
179 | 179 | // insert before given node |
180 | 180 | $placementID--; |
181 | 181 | break; |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $previous = $line; |
185 | 185 | } |
186 | 186 | |
187 | - if ($previous !== null && !$previous->isEmpty()) { |
|
187 | + if ($previous !== null && !$previous->isEmpty()){ |
|
188 | 188 | $placementID++; |
189 | 189 | } |
190 | 190 | |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | |
196 | 196 | private function getPropertyType(Dependency $dependency): string |
197 | 197 | { |
198 | - foreach ($this->definition->getStmts() as $stmt) { |
|
199 | - if ($stmt->name === $dependency->type->fullName) { |
|
200 | - if ($stmt->alias) { |
|
198 | + foreach ($this->definition->getStmts() as $stmt){ |
|
199 | + if ($stmt->name === $dependency->type->fullName){ |
|
200 | + if ($stmt->alias){ |
|
201 | 201 | return $stmt->alias; |
202 | 202 | } |
203 | 203 | } |
@@ -208,15 +208,15 @@ discard block |
||
208 | 208 | |
209 | 209 | private function getParamType(ClassNode\ConstructorParam $param): string |
210 | 210 | { |
211 | - foreach ($this->definition->getStmts() as $stmt) { |
|
212 | - if ($stmt->name === $param->type->fullName) { |
|
213 | - if ($stmt->alias) { |
|
211 | + foreach ($this->definition->getStmts() as $stmt){ |
|
212 | + if ($stmt->name === $param->type->fullName){ |
|
213 | + if ($stmt->alias){ |
|
214 | 214 | return $stmt->alias; |
215 | 215 | } |
216 | 216 | } |
217 | 217 | } |
218 | 218 | |
219 | - if ($param->type->alias) { |
|
219 | + if ($param->type->alias){ |
|
220 | 220 | return $param->type->alias; |
221 | 221 | } |
222 | 222 |
@@ -38,13 +38,15 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function leaveNode(Node $node) |
40 | 40 | { |
41 | - if (!$node instanceof Node\Stmt\Class_) { |
|
41 | + if (!$node instanceof Node\Stmt\Class_) |
|
42 | + { |
|
42 | 43 | return null; |
43 | 44 | } |
44 | 45 | |
45 | 46 | $constructor = $this->getConstructorAttribute($node); |
46 | 47 | $this->addDependencies($constructor); |
47 | - if (!$this->definition->hasConstructor && $this->definition->constructorParams) { |
|
48 | + if (!$this->definition->hasConstructor && $this->definition->constructorParams) |
|
49 | + { |
|
48 | 50 | $this->addParentConstructorCall($constructor); |
49 | 51 | } |
50 | 52 | |
@@ -60,7 +62,8 @@ discard block |
||
60 | 62 | */ |
61 | 63 | private function addDependencies(Node\Stmt\ClassMethod $constructor): void |
62 | 64 | { |
63 | - foreach ($this->definition->dependencies as $dependency) { |
|
65 | + foreach ($this->definition->dependencies as $dependency) |
|
66 | + { |
|
64 | 67 | array_unshift($constructor->params, $this->buildConstructorParam($dependency)); |
65 | 68 | array_unshift( |
66 | 69 | $constructor->stmts, |
@@ -83,34 +86,41 @@ discard block |
||
83 | 86 | private function addParentConstructorCall(Node\Stmt\ClassMethod $constructor): void |
84 | 87 | { |
85 | 88 | $parentConstructorDependencies = []; |
86 | - foreach ($this->definition->constructorParams as $param) { |
|
89 | + foreach ($this->definition->constructorParams as $param) |
|
90 | + { |
|
87 | 91 | $parentConstructorDependencies[] = new Node\Arg(new Node\Expr\Variable($param->name)); |
88 | 92 | |
89 | 93 | $cp = new Param($param->name); |
90 | - if (!empty($param->type)) { |
|
94 | + if (!empty($param->type)) |
|
95 | + { |
|
91 | 96 | $type = $this->getParamType($param); |
92 | - if ($param->nullable) { |
|
97 | + if ($param->nullable) |
|
98 | + { |
|
93 | 99 | $type = "?$type"; |
94 | 100 | } |
95 | 101 | |
96 | 102 | $cp->setType(new Node\Name($type)); |
97 | 103 | } |
98 | 104 | |
99 | - if ($param->byRef) { |
|
105 | + if ($param->byRef) |
|
106 | + { |
|
100 | 107 | $cp->makeByRef(); |
101 | 108 | } |
102 | 109 | |
103 | - if ($param->isVariadic) { |
|
110 | + if ($param->isVariadic) |
|
111 | + { |
|
104 | 112 | $cp->makeVariadic(); |
105 | 113 | } |
106 | 114 | |
107 | - if ($param->hasDefault) { |
|
115 | + if ($param->hasDefault) |
|
116 | + { |
|
108 | 117 | $cp->setDefault($param->default); |
109 | 118 | } |
110 | 119 | $constructor->params[] = $cp->getNode(); |
111 | 120 | } |
112 | 121 | |
113 | - if ($parentConstructorDependencies) { |
|
122 | + if ($parentConstructorDependencies) |
|
123 | + { |
|
114 | 124 | array_unshift( |
115 | 125 | $constructor->stmts, |
116 | 126 | new Node\Stmt\Expression( |
@@ -140,18 +150,23 @@ discard block |
||
140 | 150 | |
141 | 151 | $params = []; |
142 | 152 | |
143 | - foreach ($this->definition->dependencies as $dependency) { |
|
153 | + foreach ($this->definition->dependencies as $dependency) |
|
154 | + { |
|
144 | 155 | $params[] = new Annotation\Line( |
145 | 156 | sprintf('%s $%s', $this->getPropertyType($dependency), $dependency->var), |
146 | 157 | 'param' |
147 | 158 | ); |
148 | 159 | } |
149 | 160 | |
150 | - if (!$this->definition->hasConstructor) { |
|
151 | - foreach ($this->definition->constructorParams as $param) { |
|
152 | - if (!empty($param->type)) { |
|
161 | + if (!$this->definition->hasConstructor) |
|
162 | + { |
|
163 | + foreach ($this->definition->constructorParams as $param) |
|
164 | + { |
|
165 | + if (!empty($param->type)) |
|
166 | + { |
|
153 | 167 | $type = $this->getParamType($param); |
154 | - if ($param->nullable) { |
|
168 | + if ($param->nullable) |
|
169 | + { |
|
155 | 170 | $type = "$type|null"; |
156 | 171 | } |
157 | 172 | |
@@ -159,7 +174,9 @@ discard block |
||
159 | 174 | sprintf($param->isVariadic ? '%s ...$%s' : '%s $%s', $type, $param->name), |
160 | 175 | 'param' |
161 | 176 | ); |
162 | - } else { |
|
177 | + } |
|
178 | + else |
|
179 | + { |
|
163 | 180 | $params[] = new Annotation\Line( |
164 | 181 | sprintf('$%s', $param->name), |
165 | 182 | 'param' |
@@ -170,12 +187,14 @@ discard block |
||
170 | 187 | |
171 | 188 | $placementID = 0; |
172 | 189 | $previous = null; |
173 | - foreach ($an->lines as $index => $line) { |
|
190 | + foreach ($an->lines as $index => $line) |
|
191 | + { |
|
174 | 192 | // always next node |
175 | 193 | $placementID = $index + 1; |
176 | 194 | |
177 | 195 | // inject before this parameters |
178 | - if ($line->is(['throws', 'return'])) { |
|
196 | + if ($line->is(['throws', 'return'])) |
|
197 | + { |
|
179 | 198 | // insert before given node |
180 | 199 | $placementID--; |
181 | 200 | break; |
@@ -184,7 +203,8 @@ discard block |
||
184 | 203 | $previous = $line; |
185 | 204 | } |
186 | 205 | |
187 | - if ($previous !== null && !$previous->isEmpty()) { |
|
206 | + if ($previous !== null && !$previous->isEmpty()) |
|
207 | + { |
|
188 | 208 | $placementID++; |
189 | 209 | } |
190 | 210 | |
@@ -195,9 +215,12 @@ discard block |
||
195 | 215 | |
196 | 216 | private function getPropertyType(Dependency $dependency): string |
197 | 217 | { |
198 | - foreach ($this->definition->getStmts() as $stmt) { |
|
199 | - if ($stmt->name === $dependency->type->fullName) { |
|
200 | - if ($stmt->alias) { |
|
218 | + foreach ($this->definition->getStmts() as $stmt) |
|
219 | + { |
|
220 | + if ($stmt->name === $dependency->type->fullName) |
|
221 | + { |
|
222 | + if ($stmt->alias) |
|
223 | + { |
|
201 | 224 | return $stmt->alias; |
202 | 225 | } |
203 | 226 | } |
@@ -208,15 +231,19 @@ discard block |
||
208 | 231 | |
209 | 232 | private function getParamType(ClassNode\ConstructorParam $param): string |
210 | 233 | { |
211 | - foreach ($this->definition->getStmts() as $stmt) { |
|
212 | - if ($stmt->name === $param->type->fullName) { |
|
213 | - if ($stmt->alias) { |
|
234 | + foreach ($this->definition->getStmts() as $stmt) |
|
235 | + { |
|
236 | + if ($stmt->name === $param->type->fullName) |
|
237 | + { |
|
238 | + if ($stmt->alias) |
|
239 | + { |
|
214 | 240 | return $stmt->alias; |
215 | 241 | } |
216 | 242 | } |
217 | 243 | } |
218 | 244 | |
219 | - if ($param->type->alias) { |
|
245 | + if ($param->type->alias) |
|
246 | + { |
|
220 | 247 | return $param->type->alias; |
221 | 248 | } |
222 | 249 |