@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function populate(StateInterface $state): void |
41 | 41 | { |
42 | - if (!$this->request === null) { |
|
42 | + if (!$this->request === null){ |
|
43 | 43 | return; |
44 | 44 | } |
45 | 45 | |
@@ -48,11 +48,11 @@ discard block |
||
48 | 48 | |
49 | 49 | $state->setVariable('headers', $this->request->getHeaders()); |
50 | 50 | |
51 | - if ($this->request->getQueryParams() !== []) { |
|
51 | + if ($this->request->getQueryParams() !== []){ |
|
52 | 52 | $state->setVariable('query', $this->request->getQueryParams()); |
53 | 53 | } |
54 | 54 | |
55 | - if ($this->request->getParsedBody() !== null) { |
|
55 | + if ($this->request->getParsedBody() !== null){ |
|
56 | 56 | $state->setVariable('data', $this->request->getParsedBody()); |
57 | 57 | } |
58 | 58 | } |
@@ -39,7 +39,8 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function populate(StateInterface $state): void |
41 | 41 | { |
42 | - if (!$this->request === null) { |
|
42 | + if (!$this->request === null) |
|
43 | + { |
|
43 | 44 | return; |
44 | 45 | } |
45 | 46 | |
@@ -48,11 +49,13 @@ discard block |
||
48 | 49 | |
49 | 50 | $state->setVariable('headers', $this->request->getHeaders()); |
50 | 51 | |
51 | - if ($this->request->getQueryParams() !== []) { |
|
52 | + if ($this->request->getQueryParams() !== []) |
|
53 | + { |
|
52 | 54 | $state->setVariable('query', $this->request->getQueryParams()); |
53 | 55 | } |
54 | 56 | |
55 | - if ($this->request->getParsedBody() !== null) { |
|
57 | + if ($this->request->getParsedBody() !== null) |
|
58 | + { |
|
56 | 59 | $state->setVariable('data', $this->request->getParsedBody()); |
57 | 60 | } |
58 | 61 | } |
@@ -51,11 +51,11 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function __invoke(LogEvent $event): void |
53 | 53 | { |
54 | - if (empty($this->output)) { |
|
54 | + if (empty($this->output)){ |
|
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | - if ($this->output->getVerbosity() < OutputInterface::VERBOSITY_VERY_VERBOSE) { |
|
58 | + if ($this->output->getVerbosity() < OutputInterface::VERBOSITY_VERY_VERBOSE){ |
|
59 | 59 | return; |
60 | 60 | } |
61 | 61 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function enable(): self |
93 | 93 | { |
94 | - if (!empty($this->listenerRegistry)) { |
|
94 | + if (!empty($this->listenerRegistry)){ |
|
95 | 95 | $this->listenerRegistry->addListener($this); |
96 | 96 | } |
97 | 97 | |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function disable(): self |
107 | 107 | { |
108 | - if (!empty($this->listenerRegistry)) { |
|
108 | + if (!empty($this->listenerRegistry)){ |
|
109 | 109 | $this->listenerRegistry->removeListener($this); |
110 | 110 | } |
111 | 111 | |
@@ -128,13 +128,13 @@ discard block |
||
128 | 128 | */ |
129 | 129 | private function getChannel(string $channel): string |
130 | 130 | { |
131 | - if (!class_exists($channel, false)) { |
|
131 | + if (!class_exists($channel, false)){ |
|
132 | 132 | return "[{$channel}]"; |
133 | 133 | } |
134 | 134 | |
135 | - try { |
|
135 | + try{ |
|
136 | 136 | $reflection = new \ReflectionClass($channel); |
137 | - } catch (\ReflectionException $e) { |
|
137 | + }catch (\ReflectionException $e){ |
|
138 | 138 | return $channel; |
139 | 139 | } |
140 | 140 | |
@@ -150,10 +150,10 @@ discard block |
||
150 | 150 | */ |
151 | 151 | private function getMessage(bool $decorated, string $message) |
152 | 152 | { |
153 | - if (!$decorated) { |
|
153 | + if (!$decorated){ |
|
154 | 154 | return $message; |
155 | 155 | } |
156 | 156 | |
157 | - return Color::GRAY . $message . Color::RESET; |
|
157 | + return Color::GRAY.$message.Color::RESET; |
|
158 | 158 | } |
159 | 159 | } |
@@ -51,11 +51,13 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function __invoke(LogEvent $event): void |
53 | 53 | { |
54 | - if (empty($this->output)) { |
|
54 | + if (empty($this->output)) |
|
55 | + { |
|
55 | 56 | return; |
56 | 57 | } |
57 | 58 | |
58 | - if ($this->output->getVerbosity() < OutputInterface::VERBOSITY_VERY_VERBOSE) { |
|
59 | + if ($this->output->getVerbosity() < OutputInterface::VERBOSITY_VERY_VERBOSE) |
|
60 | + { |
|
59 | 61 | return; |
60 | 62 | } |
61 | 63 | |
@@ -91,7 +93,8 @@ discard block |
||
91 | 93 | */ |
92 | 94 | public function enable(): self |
93 | 95 | { |
94 | - if (!empty($this->listenerRegistry)) { |
|
96 | + if (!empty($this->listenerRegistry)) |
|
97 | + { |
|
95 | 98 | $this->listenerRegistry->addListener($this); |
96 | 99 | } |
97 | 100 | |
@@ -105,7 +108,8 @@ discard block |
||
105 | 108 | */ |
106 | 109 | public function disable(): self |
107 | 110 | { |
108 | - if (!empty($this->listenerRegistry)) { |
|
111 | + if (!empty($this->listenerRegistry)) |
|
112 | + { |
|
109 | 113 | $this->listenerRegistry->removeListener($this); |
110 | 114 | } |
111 | 115 | |
@@ -128,13 +132,17 @@ discard block |
||
128 | 132 | */ |
129 | 133 | private function getChannel(string $channel): string |
130 | 134 | { |
131 | - if (!class_exists($channel, false)) { |
|
135 | + if (!class_exists($channel, false)) |
|
136 | + { |
|
132 | 137 | return "[{$channel}]"; |
133 | 138 | } |
134 | 139 | |
135 | - try { |
|
140 | + try |
|
141 | + { |
|
136 | 142 | $reflection = new \ReflectionClass($channel); |
137 | - } catch (\ReflectionException $e) { |
|
143 | + } |
|
144 | + catch (\ReflectionException $e) |
|
145 | + { |
|
138 | 146 | return $channel; |
139 | 147 | } |
140 | 148 | |
@@ -150,7 +158,8 @@ discard block |
||
150 | 158 | */ |
151 | 159 | private function getMessage(bool $decorated, string $message) |
152 | 160 | { |
153 | - if (!$decorated) { |
|
161 | + if (!$decorated) |
|
162 | + { |
|
154 | 163 | return $message; |
155 | 164 | } |
156 | 165 |
@@ -70,16 +70,16 @@ |
||
70 | 70 | { |
71 | 71 | $state = new State(); |
72 | 72 | |
73 | - foreach ($this->collectors as $collector) { |
|
74 | - if (is_string($collector)) { |
|
73 | + foreach ($this->collectors as $collector){ |
|
74 | + if (is_string($collector)){ |
|
75 | 75 | $collector = $this->factory->make($collector); |
76 | 76 | } |
77 | 77 | |
78 | - if ($collector instanceof Autowire) { |
|
78 | + if ($collector instanceof Autowire){ |
|
79 | 79 | $collector = $collector->resolve($this->factory); |
80 | 80 | } |
81 | 81 | |
82 | - if (!$collector instanceof StateCollectorInterface) { |
|
82 | + if (!$collector instanceof StateCollectorInterface){ |
|
83 | 83 | throw new StateException(sprintf( |
84 | 84 | 'Unable to populate state, invalid state collector %s', |
85 | 85 | is_object($collector) ? get_class($collector) : gettype($collector) |
@@ -70,16 +70,20 @@ |
||
70 | 70 | { |
71 | 71 | $state = new State(); |
72 | 72 | |
73 | - foreach ($this->collectors as $collector) { |
|
74 | - if (is_string($collector)) { |
|
73 | + foreach ($this->collectors as $collector) |
|
74 | + { |
|
75 | + if (is_string($collector)) |
|
76 | + { |
|
75 | 77 | $collector = $this->factory->make($collector); |
76 | 78 | } |
77 | 79 | |
78 | - if ($collector instanceof Autowire) { |
|
80 | + if ($collector instanceof Autowire) |
|
81 | + { |
|
79 | 82 | $collector = $collector->resolve($this->factory); |
80 | 83 | } |
81 | 84 | |
82 | - if (!$collector instanceof StateCollectorInterface) { |
|
85 | + if (!$collector instanceof StateCollectorInterface) |
|
86 | + { |
|
83 | 87 | throw new StateException(sprintf( |
84 | 88 | 'Unable to populate state, invalid state collector %s', |
85 | 89 | is_object($collector) ? get_class($collector) : gettype($collector) |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | HandlerInterface $handler, |
54 | 54 | FilesInterface $files, |
55 | 55 | LoggerInterface $logger = null |
56 | - ) { |
|
56 | + ){ |
|
57 | 57 | $this->directory = $directory; |
58 | 58 | $this->maxFiles = $maxFiles; |
59 | 59 | $this->verbosity = $verbosity; |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | { |
70 | 70 | $snapshot = new Snapshot($this->getID($e), $e); |
71 | 71 | |
72 | - if ($this->logger !== null) { |
|
72 | + if ($this->logger !== null){ |
|
73 | 73 | $this->logger->error($snapshot->getMessage()); |
74 | 74 | } |
75 | 75 | |
@@ -101,17 +101,17 @@ discard block |
||
101 | 101 | protected function rotateSnapshots(): void |
102 | 102 | { |
103 | 103 | $finder = new Finder(); |
104 | - $finder->in($this->directory)->sort(function (SplFileInfo $a, SplFileInfo $b) { |
|
104 | + $finder->in($this->directory)->sort(function (SplFileInfo $a, SplFileInfo $b){ |
|
105 | 105 | return $b->getMTime() - $a->getMTime(); |
106 | 106 | }); |
107 | 107 | |
108 | 108 | $count = 0; |
109 | - foreach ($finder as $file) { |
|
109 | + foreach ($finder as $file){ |
|
110 | 110 | $count++; |
111 | - if ($count > $this->maxFiles) { |
|
112 | - try { |
|
111 | + if ($count > $this->maxFiles){ |
|
112 | + try{ |
|
113 | 113 | $this->files->delete($file->getRealPath()); |
114 | - } catch (FilesException $e) { |
|
114 | + }catch (FilesException $e){ |
|
115 | 115 | // ignore |
116 | 116 | } |
117 | 117 | } |
@@ -69,7 +69,8 @@ discard block |
||
69 | 69 | { |
70 | 70 | $snapshot = new Snapshot($this->getID($e), $e); |
71 | 71 | |
72 | - if ($this->logger !== null) { |
|
72 | + if ($this->logger !== null) |
|
73 | + { |
|
73 | 74 | $this->logger->error($snapshot->getMessage()); |
74 | 75 | } |
75 | 76 | |
@@ -101,17 +102,23 @@ discard block |
||
101 | 102 | protected function rotateSnapshots(): void |
102 | 103 | { |
103 | 104 | $finder = new Finder(); |
104 | - $finder->in($this->directory)->sort(function (SplFileInfo $a, SplFileInfo $b) { |
|
105 | + $finder->in($this->directory)->sort(function (SplFileInfo $a, SplFileInfo $b) |
|
106 | + { |
|
105 | 107 | return $b->getMTime() - $a->getMTime(); |
106 | 108 | }); |
107 | 109 | |
108 | 110 | $count = 0; |
109 | - foreach ($finder as $file) { |
|
111 | + foreach ($finder as $file) |
|
112 | + { |
|
110 | 113 | $count++; |
111 | - if ($count > $this->maxFiles) { |
|
112 | - try { |
|
114 | + if ($count > $this->maxFiles) |
|
115 | + { |
|
116 | + try |
|
117 | + { |
|
113 | 118 | $this->files->delete($file->getRealPath()); |
114 | - } catch (FilesException $e) { |
|
119 | + } |
|
120 | + catch (FilesException $e) |
|
121 | + { |
|
115 | 122 | // ignore |
116 | 123 | } |
117 | 124 | } |
@@ -46,9 +46,9 @@ |
||
46 | 46 | DirectoriesInterface $dirs, |
47 | 47 | FilesInterface $files, |
48 | 48 | LoggerInterface $logger = null |
49 | - ) { |
|
49 | + ){ |
|
50 | 50 | return new FileSnapshooter( |
51 | - $dirs->get('runtime') . '/snapshots/', |
|
51 | + $dirs->get('runtime').'/snapshots/', |
|
52 | 52 | $env->get('SNAPSHOT_MAX_FILES', self::MAX_SNAPSHOTS), |
53 | 53 | $env->get('SNAPSHOT_VERBOSITY', HandlerInterface::VERBOSITY_VERBOSE), |
54 | 54 | new PlainHandler(), |
@@ -40,22 +40,22 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function load(string $id): ?TokenInterface |
42 | 42 | { |
43 | - try { |
|
43 | + try{ |
|
44 | 44 | $tokenData = $this->session->getSection(self::SESSION_SECTION)->get('token'); |
45 | - if ($tokenData === null) { |
|
45 | + if ($tokenData === null){ |
|
46 | 46 | return null; |
47 | 47 | } |
48 | 48 | |
49 | 49 | $token = Token::unpack($tokenData); |
50 | - } catch (\Throwable $e) { |
|
50 | + }catch (\Throwable $e){ |
|
51 | 51 | throw new TokenStorageException('Unable to load session token', $e->getCode(), $e); |
52 | 52 | } |
53 | 53 | |
54 | - if (!hash_equals($token->getID(), $id)) { |
|
54 | + if (!hash_equals($token->getID(), $id)){ |
|
55 | 55 | return null; |
56 | 56 | } |
57 | 57 | |
58 | - if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) { |
|
58 | + if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()){ |
|
59 | 59 | $this->delete($token); |
60 | 60 | return null; |
61 | 61 | } |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface |
70 | 70 | { |
71 | - try { |
|
71 | + try{ |
|
72 | 72 | $token = new Token($this->randomHash(128), $payload, $expiresAt); |
73 | 73 | $this->session->getSection(self::SESSION_SECTION)->set('token', $token->pack()); |
74 | 74 | |
75 | 75 | return $token; |
76 | - } catch (\Throwable $e) { |
|
76 | + }catch (\Throwable $e){ |
|
77 | 77 | throw new TokenStorageException('Unable to create session token', $e->getCode(), $e); |
78 | 78 | } |
79 | 79 | } |
@@ -40,22 +40,28 @@ discard block |
||
40 | 40 | */ |
41 | 41 | public function load(string $id): ?TokenInterface |
42 | 42 | { |
43 | - try { |
|
43 | + try |
|
44 | + { |
|
44 | 45 | $tokenData = $this->session->getSection(self::SESSION_SECTION)->get('token'); |
45 | - if ($tokenData === null) { |
|
46 | + if ($tokenData === null) |
|
47 | + { |
|
46 | 48 | return null; |
47 | 49 | } |
48 | 50 | |
49 | 51 | $token = Token::unpack($tokenData); |
50 | - } catch (\Throwable $e) { |
|
52 | + } |
|
53 | + catch (\Throwable $e) |
|
54 | + { |
|
51 | 55 | throw new TokenStorageException('Unable to load session token', $e->getCode(), $e); |
52 | 56 | } |
53 | 57 | |
54 | - if (!hash_equals($token->getID(), $id)) { |
|
58 | + if (!hash_equals($token->getID(), $id)) |
|
59 | + { |
|
55 | 60 | return null; |
56 | 61 | } |
57 | 62 | |
58 | - if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) { |
|
63 | + if ($token->getExpiresAt() !== null && $token->getExpiresAt() < new \DateTime()) |
|
64 | + { |
|
59 | 65 | $this->delete($token); |
60 | 66 | return null; |
61 | 67 | } |
@@ -68,12 +74,15 @@ discard block |
||
68 | 74 | */ |
69 | 75 | public function create(array $payload, \DateTimeInterface $expiresAt = null): TokenInterface |
70 | 76 | { |
71 | - try { |
|
77 | + try |
|
78 | + { |
|
72 | 79 | $token = new Token($this->randomHash(128), $payload, $expiresAt); |
73 | 80 | $this->session->getSection(self::SESSION_SECTION)->set('token', $token->pack()); |
74 | 81 | |
75 | 82 | return $token; |
76 | - } catch (\Throwable $e) { |
|
83 | + } |
|
84 | + catch (\Throwable $e) |
|
85 | + { |
|
77 | 86 | throw new TokenStorageException('Unable to create session token', $e->getCode(), $e); |
78 | 87 | } |
79 | 88 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | RendererInterface $renderer, |
58 | 58 | ResponseFactoryInterface $responseFactory, |
59 | 59 | ContainerInterface $container |
60 | - ) { |
|
60 | + ){ |
|
61 | 61 | $this->suppressErrors = $suppressErrors; |
62 | 62 | $this->renderer = $renderer; |
63 | 63 | $this->responseFactory = $responseFactory; |
@@ -71,22 +71,22 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function process(Request $request, Handler $handler): Response |
73 | 73 | { |
74 | - try { |
|
74 | + try{ |
|
75 | 75 | return $handler->handle($request); |
76 | - } catch (ClientException | RouterException $e) { |
|
77 | - if ($e instanceof ClientException) { |
|
76 | + }catch (ClientException | RouterException $e){ |
|
77 | + if ($e instanceof ClientException){ |
|
78 | 78 | $code = $e->getCode(); |
79 | - } else { |
|
79 | + }else{ |
|
80 | 80 | $code = 404; |
81 | 81 | } |
82 | - } catch (\Throwable $e) { |
|
82 | + }catch (\Throwable $e){ |
|
83 | 83 | $snapshotter = $this->getOptional(SnapshotterInterface::class); |
84 | - if ($snapshotter !== null) { |
|
84 | + if ($snapshotter !== null){ |
|
85 | 85 | /** @var SnapshotterInterface $snapshotter */ |
86 | 86 | $snapshotter->register($e); |
87 | 87 | } |
88 | 88 | |
89 | - if (!$this->suppressErrors) { |
|
89 | + if (!$this->suppressErrors){ |
|
90 | 90 | return $this->renderError($request, $e); |
91 | 91 | } |
92 | 92 | |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | { |
110 | 110 | $response = $this->responseFactory->createResponse(500); |
111 | 111 | |
112 | - if ($request->getHeaderLine('Accept') == 'application/json') { |
|
112 | + if ($request->getHeaderLine('Accept') == 'application/json'){ |
|
113 | 113 | $response = $response->withHeader('Content-Type', 'application/json'); |
114 | 114 | $handler = new JsonHandler(); |
115 | 115 | $response->getBody()->write(json_encode( |
@@ -119,10 +119,10 @@ discard block |
||
119 | 119 | true |
120 | 120 | ) |
121 | 121 | )); |
122 | - } else { |
|
122 | + }else{ |
|
123 | 123 | $handler = new HtmlHandler(); |
124 | 124 | $state = $this->getOptional(StateInterface::class); |
125 | - if ($state !== null) { |
|
125 | + if ($state !== null){ |
|
126 | 126 | $handler = $handler->withState($state); |
127 | 127 | } |
128 | 128 | |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | */ |
157 | 157 | private function getOptional(string $class) |
158 | 158 | { |
159 | - try { |
|
159 | + try{ |
|
160 | 160 | return $this->container->get($class); |
161 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
161 | + }catch (\Throwable | ContainerExceptionInterface $se){ |
|
162 | 162 | return null; |
163 | 163 | } |
164 | 164 | } |
@@ -71,22 +71,32 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function process(Request $request, Handler $handler): Response |
73 | 73 | { |
74 | - try { |
|
74 | + try |
|
75 | + { |
|
75 | 76 | return $handler->handle($request); |
76 | - } catch (ClientException | RouterException $e) { |
|
77 | - if ($e instanceof ClientException) { |
|
77 | + } |
|
78 | + catch (ClientException | RouterException $e) |
|
79 | + { |
|
80 | + if ($e instanceof ClientException) |
|
81 | + { |
|
78 | 82 | $code = $e->getCode(); |
79 | - } else { |
|
83 | + } |
|
84 | + else |
|
85 | + { |
|
80 | 86 | $code = 404; |
81 | 87 | } |
82 | - } catch (\Throwable $e) { |
|
88 | + } |
|
89 | + catch (\Throwable $e) |
|
90 | + { |
|
83 | 91 | $snapshotter = $this->getOptional(SnapshotterInterface::class); |
84 | - if ($snapshotter !== null) { |
|
92 | + if ($snapshotter !== null) |
|
93 | + { |
|
85 | 94 | /** @var SnapshotterInterface $snapshotter */ |
86 | 95 | $snapshotter->register($e); |
87 | 96 | } |
88 | 97 | |
89 | - if (!$this->suppressErrors) { |
|
98 | + if (!$this->suppressErrors) |
|
99 | + { |
|
90 | 100 | return $this->renderError($request, $e); |
91 | 101 | } |
92 | 102 | |
@@ -109,7 +119,8 @@ discard block |
||
109 | 119 | { |
110 | 120 | $response = $this->responseFactory->createResponse(500); |
111 | 121 | |
112 | - if ($request->getHeaderLine('Accept') == 'application/json') { |
|
122 | + if ($request->getHeaderLine('Accept') == 'application/json') |
|
123 | + { |
|
113 | 124 | $response = $response->withHeader('Content-Type', 'application/json'); |
114 | 125 | $handler = new JsonHandler(); |
115 | 126 | $response->getBody()->write(json_encode( |
@@ -119,10 +130,13 @@ discard block |
||
119 | 130 | true |
120 | 131 | ) |
121 | 132 | )); |
122 | - } else { |
|
133 | + } |
|
134 | + else |
|
135 | + { |
|
123 | 136 | $handler = new HtmlHandler(); |
124 | 137 | $state = $this->getOptional(StateInterface::class); |
125 | - if ($state !== null) { |
|
138 | + if ($state !== null) |
|
139 | + { |
|
126 | 140 | $handler = $handler->withState($state); |
127 | 141 | } |
128 | 142 | |
@@ -156,9 +170,12 @@ discard block |
||
156 | 170 | */ |
157 | 171 | private function getOptional(string $class) |
158 | 172 | { |
159 | - try { |
|
173 | + try |
|
174 | + { |
|
160 | 175 | return $this->container->get($class); |
161 | - } catch (\Throwable | ContainerExceptionInterface $se) { |
|
176 | + } |
|
177 | + catch (\Throwable | ContainerExceptionInterface $se) |
|
178 | + { |
|
162 | 179 | return null; |
163 | 180 | } |
164 | 181 | } |
@@ -40,9 +40,9 @@ |
||
40 | 40 | public function renderException(Request $request, int $code, string $message): Response |
41 | 41 | { |
42 | 42 | $response = $this->responseFactory->createResponse($code); |
43 | - if ($request->getHeaderLine('Accept') == 'application/json') { |
|
43 | + if ($request->getHeaderLine('Accept') == 'application/json'){ |
|
44 | 44 | $response->getBody()->write(json_encode(['status' => $code, 'error' => $message])); |
45 | - } else { |
|
45 | + }else{ |
|
46 | 46 | $response->getBody()->write("Error code: {$code}"); |
47 | 47 | } |
48 | 48 |
@@ -40,9 +40,12 @@ |
||
40 | 40 | public function renderException(Request $request, int $code, string $message): Response |
41 | 41 | { |
42 | 42 | $response = $this->responseFactory->createResponse($code); |
43 | - if ($request->getHeaderLine('Accept') == 'application/json') { |
|
43 | + if ($request->getHeaderLine('Accept') == 'application/json') |
|
44 | + { |
|
44 | 45 | $response->getBody()->write(json_encode(['status' => $code, 'error' => $message])); |
45 | - } else { |
|
46 | + } |
|
47 | + else |
|
48 | + { |
|
46 | 49 | $response->getBody()->write("Error code: {$code}"); |
47 | 50 | } |
48 | 51 |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | public function setUp(): void |
24 | 24 | { |
25 | 25 | exec('protoc 2>&1', $out); |
26 | - if (strpos(join("\n", $out), '--php_out') === false) { |
|
26 | + if (strpos(join("\n", $out), '--php_out') === false){ |
|
27 | 27 | $this->markTestSkipped('Protoc binary is missing'); |
28 | 28 | } |
29 | 29 | |
30 | 30 | parent::setUp(); |
31 | 31 | |
32 | 32 | $fs = new Files(); |
33 | - $proto = $fs->normalizePath($this->app->dir('app') . 'proto/service.proto'); |
|
33 | + $proto = $fs->normalizePath($this->app->dir('app').'proto/service.proto'); |
|
34 | 34 | |
35 | 35 | // protoc can't figure relative paths |
36 | 36 | $proto = str_replace('Framework/../', '', $proto); |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | 'proto' => $proto |
40 | 40 | ]); |
41 | 41 | |
42 | - file_put_contents($this->app->dir('app') . 'src/Service/EchoService.php', GenerateTest::SERVICE); |
|
42 | + file_put_contents($this->app->dir('app').'src/Service/EchoService.php', GenerateTest::SERVICE); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | public function tearDown(): void |
@@ -48,12 +48,12 @@ discard block |
||
48 | 48 | |
49 | 49 | $fs = new Files(); |
50 | 50 | |
51 | - if ($fs->isDirectory($this->app->dir('app') . 'src/Service')) { |
|
52 | - $fs->deleteDirectory($this->app->dir('app') . 'src/Service'); |
|
51 | + if ($fs->isDirectory($this->app->dir('app').'src/Service')){ |
|
52 | + $fs->deleteDirectory($this->app->dir('app').'src/Service'); |
|
53 | 53 | } |
54 | 54 | |
55 | - if ($fs->isDirectory($this->app->dir('app') . 'src/GPBMetadata')) { |
|
56 | - $fs->deleteDirectory($this->app->dir('app') . 'src/GPBMetadata'); |
|
55 | + if ($fs->isDirectory($this->app->dir('app').'src/GPBMetadata')){ |
|
56 | + $fs->deleteDirectory($this->app->dir('app').'src/GPBMetadata'); |
|
57 | 57 | } |
58 | 58 | } |
59 | 59 | |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | $msg->setMsg('hello'); |
80 | 80 | |
81 | 81 | $w->shouldReceive('receive')->once()->with( |
82 | - \Mockery::on(function (&$context) { |
|
82 | + \Mockery::on(function (&$context){ |
|
83 | 83 | $context = '{ |
84 | 84 | "service": "service.Echo", |
85 | 85 | "method": "Ping", |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | )->andReturn($msg->serializeToString()); |
92 | 92 | |
93 | 93 | $w->shouldReceive('send')->once()->with( |
94 | - \Mockery::on(function ($out) { |
|
94 | + \Mockery::on(function ($out){ |
|
95 | 95 | $msg = new Message(); |
96 | 96 | $msg->mergeFromString($out); |
97 | 97 | $this->assertSame('hello', $msg->getMsg()); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | |
104 | 104 | // one command only |
105 | 105 | $w->shouldReceive('receive')->once()->with( |
106 | - \Mockery::on(function (&$context) { |
|
106 | + \Mockery::on(function (&$context){ |
|
107 | 107 | $context = null; |
108 | 108 | return true; |
109 | 109 | }) |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | $msg->setMsg('hello'); |
124 | 124 | |
125 | 125 | $w->shouldReceive('receive')->once()->with( |
126 | - \Mockery::on(function (&$context) { |
|
126 | + \Mockery::on(function (&$context){ |
|
127 | 127 | $context = '{ |
128 | 128 | "service": "service.Echo", |
129 | 129 | "method": "Invalid", |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | )->andReturn($msg->serializeToString()); |
136 | 136 | |
137 | 137 | $w->shouldReceive('error')->once()->with( |
138 | - \Mockery::on(function ($out) { |
|
138 | + \Mockery::on(function ($out){ |
|
139 | 139 | $this->assertContains('Method `Invalid` not found', $out); |
140 | 140 | return true; |
141 | 141 | }) |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | |
144 | 144 | // one command only |
145 | 145 | $w->shouldReceive('receive')->once()->with( |
146 | - \Mockery::on(function (&$context) { |
|
146 | + \Mockery::on(function (&$context){ |
|
147 | 147 | $context = null; |
148 | 148 | return true; |
149 | 149 | }) |
@@ -23,7 +23,8 @@ discard block |
||
23 | 23 | public function setUp(): void |
24 | 24 | { |
25 | 25 | exec('protoc 2>&1', $out); |
26 | - if (strpos(join("\n", $out), '--php_out') === false) { |
|
26 | + if (strpos(join("\n", $out), '--php_out') === false) |
|
27 | + { |
|
27 | 28 | $this->markTestSkipped('Protoc binary is missing'); |
28 | 29 | } |
29 | 30 | |
@@ -48,11 +49,13 @@ discard block |
||
48 | 49 | |
49 | 50 | $fs = new Files(); |
50 | 51 | |
51 | - if ($fs->isDirectory($this->app->dir('app') . 'src/Service')) { |
|
52 | + if ($fs->isDirectory($this->app->dir('app') . 'src/Service')) |
|
53 | + { |
|
52 | 54 | $fs->deleteDirectory($this->app->dir('app') . 'src/Service'); |
53 | 55 | } |
54 | 56 | |
55 | - if ($fs->isDirectory($this->app->dir('app') . 'src/GPBMetadata')) { |
|
57 | + if ($fs->isDirectory($this->app->dir('app') . 'src/GPBMetadata')) |
|
58 | + { |
|
56 | 59 | $fs->deleteDirectory($this->app->dir('app') . 'src/GPBMetadata'); |
57 | 60 | } |
58 | 61 | } |
@@ -79,7 +82,8 @@ discard block |
||
79 | 82 | $msg->setMsg('hello'); |
80 | 83 | |
81 | 84 | $w->shouldReceive('receive')->once()->with( |
82 | - \Mockery::on(function (&$context) { |
|
85 | + \Mockery::on(function (&$context) |
|
86 | + { |
|
83 | 87 | $context = '{ |
84 | 88 | "service": "service.Echo", |
85 | 89 | "method": "Ping", |
@@ -91,7 +95,8 @@ discard block |
||
91 | 95 | )->andReturn($msg->serializeToString()); |
92 | 96 | |
93 | 97 | $w->shouldReceive('send')->once()->with( |
94 | - \Mockery::on(function ($out) { |
|
98 | + \Mockery::on(function ($out) |
|
99 | + { |
|
95 | 100 | $msg = new Message(); |
96 | 101 | $msg->mergeFromString($out); |
97 | 102 | $this->assertSame('hello', $msg->getMsg()); |
@@ -103,7 +108,8 @@ discard block |
||
103 | 108 | |
104 | 109 | // one command only |
105 | 110 | $w->shouldReceive('receive')->once()->with( |
106 | - \Mockery::on(function (&$context) { |
|
111 | + \Mockery::on(function (&$context) |
|
112 | + { |
|
107 | 113 | $context = null; |
108 | 114 | return true; |
109 | 115 | }) |
@@ -123,7 +129,8 @@ discard block |
||
123 | 129 | $msg->setMsg('hello'); |
124 | 130 | |
125 | 131 | $w->shouldReceive('receive')->once()->with( |
126 | - \Mockery::on(function (&$context) { |
|
132 | + \Mockery::on(function (&$context) |
|
133 | + { |
|
127 | 134 | $context = '{ |
128 | 135 | "service": "service.Echo", |
129 | 136 | "method": "Invalid", |
@@ -135,7 +142,8 @@ discard block |
||
135 | 142 | )->andReturn($msg->serializeToString()); |
136 | 143 | |
137 | 144 | $w->shouldReceive('error')->once()->with( |
138 | - \Mockery::on(function ($out) { |
|
145 | + \Mockery::on(function ($out) |
|
146 | + { |
|
139 | 147 | $this->assertContains('Method `Invalid` not found', $out); |
140 | 148 | return true; |
141 | 149 | }) |
@@ -143,7 +151,8 @@ discard block |
||
143 | 151 | |
144 | 152 | // one command only |
145 | 153 | $w->shouldReceive('receive')->once()->with( |
146 | - \Mockery::on(function (&$context) { |
|
154 | + \Mockery::on(function (&$context) |
|
155 | + { |
|
147 | 156 | $context = null; |
148 | 157 | return true; |
149 | 158 | }) |