@@ -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 | } |
@@ -45,22 +45,22 @@ discard block |
||
45 | 45 | { |
46 | 46 | $entities = $this->getDeclaredEntities($controller, $action); |
47 | 47 | |
48 | - foreach ($entities as $parameter => $role) { |
|
48 | + foreach ($entities as $parameter => $role){ |
|
49 | 49 | $value = $this->getParameter($parameter, $parameters, count($entities) === 1); |
50 | - if ($value === null) { |
|
50 | + if ($value === null){ |
|
51 | 51 | throw new ControllerException( |
52 | 52 | "Entity `{$parameter}` can not be found", |
53 | 53 | ControllerException::NOT_FOUND |
54 | 54 | ); |
55 | 55 | } |
56 | 56 | |
57 | - if (is_object($value)) { |
|
57 | + if (is_object($value)){ |
|
58 | 58 | // pre-filled |
59 | 59 | continue; |
60 | 60 | } |
61 | 61 | |
62 | 62 | $entity = $this->resolveEntity($role, $value); |
63 | - if ($entity === null) { |
|
63 | + if ($entity === null){ |
|
64 | 64 | throw new ControllerException( |
65 | 65 | "Entity `{$parameter}` can not be found", |
66 | 66 | ControllerException::NOT_FOUND |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | */ |
82 | 82 | protected function getParameter(string $role, array $parameters, bool $useDefault = false) |
83 | 83 | { |
84 | - if (!$useDefault) { |
|
84 | + if (!$useDefault){ |
|
85 | 85 | return $parameters[$role] ?? null; |
86 | 86 | } |
87 | 87 | |
@@ -106,23 +106,23 @@ discard block |
||
106 | 106 | private function getDeclaredEntities(string $controller, string $action): array |
107 | 107 | { |
108 | 108 | $key = sprintf('%s:%s', $controller, $action); |
109 | - if (array_key_exists($key, $this->cache)) { |
|
109 | + if (array_key_exists($key, $this->cache)){ |
|
110 | 110 | return $this->cache[$key]; |
111 | 111 | } |
112 | 112 | |
113 | 113 | $this->cache[$key] = []; |
114 | - try { |
|
114 | + try{ |
|
115 | 115 | $method = new \ReflectionMethod($controller, $action); |
116 | - } catch (\ReflectionException $e) { |
|
116 | + }catch (\ReflectionException $e){ |
|
117 | 117 | return []; |
118 | 118 | } |
119 | 119 | |
120 | - foreach ($method->getParameters() as $parameter) { |
|
121 | - if ($parameter->getClass() === null) { |
|
120 | + foreach ($method->getParameters() as $parameter){ |
|
121 | + if ($parameter->getClass() === null){ |
|
122 | 122 | continue; |
123 | 123 | } |
124 | 124 | |
125 | - if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) { |
|
125 | + if ($this->orm->getSchema()->defines($parameter->getClass()->getName())){ |
|
126 | 126 | $this->cache[$key][$parameter->getName()] = $this->orm->resolveRole($parameter->getClass()->getName()); |
127 | 127 | } |
128 | 128 | } |
@@ -45,22 +45,26 @@ discard block |
||
45 | 45 | { |
46 | 46 | $entities = $this->getDeclaredEntities($controller, $action); |
47 | 47 | |
48 | - foreach ($entities as $parameter => $role) { |
|
48 | + foreach ($entities as $parameter => $role) |
|
49 | + { |
|
49 | 50 | $value = $this->getParameter($parameter, $parameters, count($entities) === 1); |
50 | - if ($value === null) { |
|
51 | + if ($value === null) |
|
52 | + { |
|
51 | 53 | throw new ControllerException( |
52 | 54 | "Entity `{$parameter}` can not be found", |
53 | 55 | ControllerException::NOT_FOUND |
54 | 56 | ); |
55 | 57 | } |
56 | 58 | |
57 | - if (is_object($value)) { |
|
59 | + if (is_object($value)) |
|
60 | + { |
|
58 | 61 | // pre-filled |
59 | 62 | continue; |
60 | 63 | } |
61 | 64 | |
62 | 65 | $entity = $this->resolveEntity($role, $value); |
63 | - if ($entity === null) { |
|
66 | + if ($entity === null) |
|
67 | + { |
|
64 | 68 | throw new ControllerException( |
65 | 69 | "Entity `{$parameter}` can not be found", |
66 | 70 | ControllerException::NOT_FOUND |
@@ -81,7 +85,8 @@ discard block |
||
81 | 85 | */ |
82 | 86 | protected function getParameter(string $role, array $parameters, bool $useDefault = false) |
83 | 87 | { |
84 | - if (!$useDefault) { |
|
88 | + if (!$useDefault) |
|
89 | + { |
|
85 | 90 | return $parameters[$role] ?? null; |
86 | 91 | } |
87 | 92 | |
@@ -106,23 +111,30 @@ discard block |
||
106 | 111 | private function getDeclaredEntities(string $controller, string $action): array |
107 | 112 | { |
108 | 113 | $key = sprintf('%s:%s', $controller, $action); |
109 | - if (array_key_exists($key, $this->cache)) { |
|
114 | + if (array_key_exists($key, $this->cache)) |
|
115 | + { |
|
110 | 116 | return $this->cache[$key]; |
111 | 117 | } |
112 | 118 | |
113 | 119 | $this->cache[$key] = []; |
114 | - try { |
|
120 | + try |
|
121 | + { |
|
115 | 122 | $method = new \ReflectionMethod($controller, $action); |
116 | - } catch (\ReflectionException $e) { |
|
123 | + } |
|
124 | + catch (\ReflectionException $e) |
|
125 | + { |
|
117 | 126 | return []; |
118 | 127 | } |
119 | 128 | |
120 | - foreach ($method->getParameters() as $parameter) { |
|
121 | - if ($parameter->getClass() === null) { |
|
129 | + foreach ($method->getParameters() as $parameter) |
|
130 | + { |
|
131 | + if ($parameter->getClass() === null) |
|
132 | + { |
|
122 | 133 | continue; |
123 | 134 | } |
124 | 135 | |
125 | - if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) { |
|
136 | + if ($this->orm->getSchema()->defines($parameter->getClass()->getName())) |
|
137 | + { |
|
126 | 138 | $this->cache[$key][$parameter->getName()] = $this->orm->resolveRole($parameter->getClass()->getName()); |
127 | 139 | } |
128 | 140 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | { |
53 | 53 | $permission = $this->getPermissions($controller, $action); |
54 | 54 | |
55 | - if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) { |
|
55 | + if ($permission !== null && !$this->guard->allows($permission[0], $parameters)){ |
|
56 | 56 | throw new ControllerException( |
57 | 57 | sprintf( |
58 | 58 | 'Unauthorized permission `%s` for action `%s`->`%s`', |
@@ -79,14 +79,14 @@ discard block |
||
79 | 79 | private function getPermissions(string $controller, string $action): ?array |
80 | 80 | { |
81 | 81 | $key = sprintf('%s:%s', $controller, $action); |
82 | - if (array_key_exists($key, $this->cache)) { |
|
82 | + if (array_key_exists($key, $this->cache)){ |
|
83 | 83 | return $this->cache[$key]; |
84 | 84 | } |
85 | 85 | |
86 | 86 | $this->cache[$key] = null; |
87 | - try { |
|
87 | + try{ |
|
88 | 88 | $method = new \ReflectionMethod($controller, $action); |
89 | - } catch (\ReflectionException $e) { |
|
89 | + }catch (\ReflectionException $e){ |
|
90 | 90 | return null; |
91 | 91 | } |
92 | 92 | |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | Guarded::class |
105 | 105 | ); |
106 | 106 | |
107 | - if ($action === null) { |
|
107 | + if ($action === null){ |
|
108 | 108 | return null; |
109 | 109 | } |
110 | 110 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | ControllerException::FORBIDDEN |
127 | 127 | ]; |
128 | 128 | |
129 | - if ($guarded->permission === null && $ns === null) { |
|
129 | + if ($guarded->permission === null && $ns === null){ |
|
130 | 130 | throw new InterceptorException(sprintf( |
131 | 131 | 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`', |
132 | 132 | $method->getDeclaringClass()->getName(), |
@@ -134,16 +134,16 @@ discard block |
||
134 | 134 | )); |
135 | 135 | } |
136 | 136 | |
137 | - if ($ns !== null) { |
|
137 | + if ($ns !== null){ |
|
138 | 138 | $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]); |
139 | 139 | } |
140 | 140 | |
141 | - if ($this->namespace !== null) { |
|
141 | + if ($this->namespace !== null){ |
|
142 | 142 | // global namespace |
143 | 143 | $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]); |
144 | 144 | } |
145 | 145 | |
146 | - switch ($guarded->else) { |
|
146 | + switch ($guarded->else){ |
|
147 | 147 | case 'badAction': |
148 | 148 | $permission[1] = ControllerException::BAD_ACTION; |
149 | 149 | break; |
@@ -52,7 +52,8 @@ discard block |
||
52 | 52 | { |
53 | 53 | $permission = $this->getPermissions($controller, $action); |
54 | 54 | |
55 | - if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) { |
|
55 | + if ($permission !== null && !$this->guard->allows($permission[0], $parameters)) |
|
56 | + { |
|
56 | 57 | throw new ControllerException( |
57 | 58 | sprintf( |
58 | 59 | 'Unauthorized permission `%s` for action `%s`->`%s`', |
@@ -79,14 +80,18 @@ discard block |
||
79 | 80 | private function getPermissions(string $controller, string $action): ?array |
80 | 81 | { |
81 | 82 | $key = sprintf('%s:%s', $controller, $action); |
82 | - if (array_key_exists($key, $this->cache)) { |
|
83 | + if (array_key_exists($key, $this->cache)) |
|
84 | + { |
|
83 | 85 | return $this->cache[$key]; |
84 | 86 | } |
85 | 87 | |
86 | 88 | $this->cache[$key] = null; |
87 | - try { |
|
89 | + try |
|
90 | + { |
|
88 | 91 | $method = new \ReflectionMethod($controller, $action); |
89 | - } catch (\ReflectionException $e) { |
|
92 | + } |
|
93 | + catch (\ReflectionException $e) |
|
94 | + { |
|
90 | 95 | return null; |
91 | 96 | } |
92 | 97 | |
@@ -104,7 +109,8 @@ discard block |
||
104 | 109 | Guarded::class |
105 | 110 | ); |
106 | 111 | |
107 | - if ($action === null) { |
|
112 | + if ($action === null) |
|
113 | + { |
|
108 | 114 | return null; |
109 | 115 | } |
110 | 116 | |
@@ -126,7 +132,8 @@ discard block |
||
126 | 132 | ControllerException::FORBIDDEN |
127 | 133 | ]; |
128 | 134 | |
129 | - if ($guarded->permission === null && $ns === null) { |
|
135 | + if ($guarded->permission === null && $ns === null) |
|
136 | + { |
|
130 | 137 | throw new InterceptorException(sprintf( |
131 | 138 | 'Unable to apply @Guarded without name or @GuardNamespace on `%s`->`%s`', |
132 | 139 | $method->getDeclaringClass()->getName(), |
@@ -134,16 +141,19 @@ discard block |
||
134 | 141 | )); |
135 | 142 | } |
136 | 143 | |
137 | - if ($ns !== null) { |
|
144 | + if ($ns !== null) |
|
145 | + { |
|
138 | 146 | $permission[0] = sprintf('%s.%s', $ns->namespace, $permission[0]); |
139 | 147 | } |
140 | 148 | |
141 | - if ($this->namespace !== null) { |
|
149 | + if ($this->namespace !== null) |
|
150 | + { |
|
142 | 151 | // global namespace |
143 | 152 | $permission[0] = sprintf('%s.%s', $this->namespace, $permission[0]); |
144 | 153 | } |
145 | 154 | |
146 | - switch ($guarded->else) { |
|
155 | + switch ($guarded->else) |
|
156 | + { |
|
147 | 157 | case 'badAction': |
148 | 158 | $permission[1] = ControllerException::BAD_ACTION; |
149 | 159 | break; |
@@ -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 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | ); |
44 | 44 | |
45 | 45 | $psr->shouldReceive('respond')->once()->with( |
46 | - \Mockery::on(function ($r) { |
|
46 | + \Mockery::on(function ($r){ |
|
47 | 47 | $this->assertSame('Hello, dave.', (string)$r->getBody()); |
48 | 48 | return true; |
49 | 49 | }) |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | ); |
66 | 66 | |
67 | 67 | $psr->shouldReceive('respond')->once()->with( |
68 | - \Mockery::on(function ($r) { |
|
68 | + \Mockery::on(function ($r){ |
|
69 | 69 | $this->assertContains('500', (string)$r->getBody()); |
70 | 70 | return true; |
71 | 71 | }) |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | $psr->shouldReceive('acceptRequest')->once()->andReturn(null); |
75 | 75 | |
76 | 76 | $files = $this->app->get(FilesInterface::class)->getFiles( |
77 | - $this->app->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/' |
|
77 | + $this->app->get(DirectoriesInterface::class)->get('runtime').'/snapshots/' |
|
78 | 78 | ); |
79 | 79 | |
80 | 80 | $this->assertCount(0, $files); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | $this->app->get(RrDispacher::class)->serve($psr); |
83 | 83 | |
84 | 84 | $files = $this->app->get(FilesInterface::class)->getFiles( |
85 | - $this->app->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/' |
|
85 | + $this->app->get(DirectoriesInterface::class)->get('runtime').'/snapshots/' |
|
86 | 86 | ); |
87 | 87 | |
88 | 88 | $this->assertCount(1, $files); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | ); |
104 | 104 | |
105 | 105 | $psr->shouldReceive('respond')->once()->with( |
106 | - \Mockery::on(function ($r) { |
|
106 | + \Mockery::on(function ($r){ |
|
107 | 107 | $this->assertContains('undefined', (string)$r->getBody()); |
108 | 108 | return true; |
109 | 109 | }) |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | $psr->shouldReceive('acceptRequest')->once()->andReturn(null); |
113 | 113 | |
114 | 114 | $files = $this->app->get(FilesInterface::class)->getFiles( |
115 | - $this->app->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/' |
|
115 | + $this->app->get(DirectoriesInterface::class)->get('runtime').'/snapshots/' |
|
116 | 116 | ); |
117 | 117 | |
118 | 118 | $this->assertCount(0, $files); |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $this->app->get(RrDispacher::class)->serve($psr); |
121 | 121 | |
122 | 122 | $files = $this->app->get(FilesInterface::class)->getFiles( |
123 | - $this->app->get(DirectoriesInterface::class)->get('runtime') . '/snapshots/' |
|
123 | + $this->app->get(DirectoriesInterface::class)->get('runtime').'/snapshots/' |
|
124 | 124 | ); |
125 | 125 | |
126 | 126 | $this->assertCount(1, $files); |
@@ -43,7 +43,8 @@ discard block |
||
43 | 43 | ); |
44 | 44 | |
45 | 45 | $psr->shouldReceive('respond')->once()->with( |
46 | - \Mockery::on(function ($r) { |
|
46 | + \Mockery::on(function ($r) |
|
47 | + { |
|
47 | 48 | $this->assertSame('Hello, dave.', (string)$r->getBody()); |
48 | 49 | return true; |
49 | 50 | }) |
@@ -65,7 +66,8 @@ discard block |
||
65 | 66 | ); |
66 | 67 | |
67 | 68 | $psr->shouldReceive('respond')->once()->with( |
68 | - \Mockery::on(function ($r) { |
|
69 | + \Mockery::on(function ($r) |
|
70 | + { |
|
69 | 71 | $this->assertContains('500', (string)$r->getBody()); |
70 | 72 | return true; |
71 | 73 | }) |
@@ -103,7 +105,8 @@ discard block |
||
103 | 105 | ); |
104 | 106 | |
105 | 107 | $psr->shouldReceive('respond')->once()->with( |
106 | - \Mockery::on(function ($r) { |
|
108 | + \Mockery::on(function ($r) |
|
109 | + { |
|
107 | 110 | $this->assertContains('undefined', (string)$r->getBody()); |
108 | 111 | return true; |
109 | 112 | }) |
@@ -46,9 +46,9 @@ |
||
46 | 46 | DirectoriesInterface $dirs, |
47 | 47 | FilesInterface $files, |
48 | 48 | LoggerInterface $logger = null |
49 | - ) { |
|
49 | + ){ |
|
50 | 50 | return new FileSnapshotter( |
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(), |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | RendererInterface $renderer, |
55 | 55 | ResponseFactoryInterface $responseFactory, |
56 | 56 | SnapshotterInterface $snapshots = null |
57 | - ) { |
|
57 | + ){ |
|
58 | 58 | $this->suppressErrors = $suppressErrors; |
59 | 59 | $this->renderer = $renderer; |
60 | 60 | $this->responseFactory = $responseFactory; |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function process(Request $request, Handler $handler): Response |
70 | 70 | { |
71 | - try { |
|
71 | + try{ |
|
72 | 72 | return $handler->handle($request); |
73 | - } catch (ClientException | RouterException $e) { |
|
74 | - if ($e instanceof ClientException) { |
|
73 | + }catch (ClientException | RouterException $e){ |
|
74 | + if ($e instanceof ClientException){ |
|
75 | 75 | $code = $e->getCode(); |
76 | - } else { |
|
76 | + }else{ |
|
77 | 77 | $code = 404; |
78 | 78 | } |
79 | - } catch (\Throwable $e) { |
|
80 | - if ($this->snapshots !== null) { |
|
79 | + }catch (\Throwable $e){ |
|
80 | + if ($this->snapshots !== null){ |
|
81 | 81 | $this->snapshots->register($e); |
82 | 82 | } |
83 | 83 | |
84 | 84 | $code = 500; |
85 | 85 | |
86 | - if (!$this->suppressErrors) { |
|
86 | + if (!$this->suppressErrors){ |
|
87 | 87 | return $this->renderException($request, $e); |
88 | 88 | } |
89 | 89 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | { |
105 | 105 | $response = $this->responseFactory->createResponse(500); |
106 | 106 | |
107 | - if ($request->getHeaderLine('Accept') == 'application/json') { |
|
107 | + if ($request->getHeaderLine('Accept') == 'application/json'){ |
|
108 | 108 | $response = $response->withHeader('Content-Type', 'application/json'); |
109 | 109 | $handler = new JsonHandler(); |
110 | 110 | $response->getBody()->write(json_encode( |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | true |
115 | 115 | ) |
116 | 116 | )); |
117 | - } else { |
|
117 | + }else{ |
|
118 | 118 | $handler = new HtmlHandler(); |
119 | 119 | $response->getBody()->write($handler->renderException($e, HtmlHandler::VERBOSITY_VERBOSE)); |
120 | 120 | } |
@@ -68,22 +68,32 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function process(Request $request, Handler $handler): Response |
70 | 70 | { |
71 | - try { |
|
71 | + try |
|
72 | + { |
|
72 | 73 | return $handler->handle($request); |
73 | - } catch (ClientException | RouterException $e) { |
|
74 | - if ($e instanceof ClientException) { |
|
74 | + } |
|
75 | + catch (ClientException | RouterException $e) |
|
76 | + { |
|
77 | + if ($e instanceof ClientException) |
|
78 | + { |
|
75 | 79 | $code = $e->getCode(); |
76 | - } else { |
|
80 | + } |
|
81 | + else |
|
82 | + { |
|
77 | 83 | $code = 404; |
78 | 84 | } |
79 | - } catch (\Throwable $e) { |
|
80 | - if ($this->snapshots !== null) { |
|
85 | + } |
|
86 | + catch (\Throwable $e) |
|
87 | + { |
|
88 | + if ($this->snapshots !== null) |
|
89 | + { |
|
81 | 90 | $this->snapshots->register($e); |
82 | 91 | } |
83 | 92 | |
84 | 93 | $code = 500; |
85 | 94 | |
86 | - if (!$this->suppressErrors) { |
|
95 | + if (!$this->suppressErrors) |
|
96 | + { |
|
87 | 97 | return $this->renderException($request, $e); |
88 | 98 | } |
89 | 99 | } |
@@ -104,7 +114,8 @@ discard block |
||
104 | 114 | { |
105 | 115 | $response = $this->responseFactory->createResponse(500); |
106 | 116 | |
107 | - if ($request->getHeaderLine('Accept') == 'application/json') { |
|
117 | + if ($request->getHeaderLine('Accept') == 'application/json') |
|
118 | + { |
|
108 | 119 | $response = $response->withHeader('Content-Type', 'application/json'); |
109 | 120 | $handler = new JsonHandler(); |
110 | 121 | $response->getBody()->write(json_encode( |
@@ -114,7 +125,9 @@ discard block |
||
114 | 125 | true |
115 | 126 | ) |
116 | 127 | )); |
117 | - } else { |
|
128 | + } |
|
129 | + else |
|
130 | + { |
|
118 | 131 | $handler = new HtmlHandler(); |
119 | 132 | $response->getBody()->write($handler->renderException($e, HtmlHandler::VERBOSITY_VERBOSE)); |
120 | 133 | } |