Skip to content

Commit b059ce0

Browse files
authored
Make sure $stack is null or Stack. Never boolean. (#164)
* Make sure $stack is null or Stack. Never boolean. * Make the code easier to read
1 parent 0513dde commit b059ce0

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

Collector/Collector.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,15 @@ public function getStacks()
6262
}
6363

6464
/**
65-
* @return Stack|bool false if no current stack.
65+
* @return Stack|null Return null there is no current stack.
6666
*/
6767
public function getCurrentStack()
6868
{
69-
return end($this->data['stacks']);
69+
if (false === $stack = end($this->data['stacks'])) {
70+
return null;
71+
}
72+
73+
return $stack;
7074
}
7175

7276
/**

Collector/ProfileClient.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function sendRequest(RequestInterface $request)
124124
*/
125125
private function collectRequestInformations(RequestInterface $request, Stack $stack = null)
126126
{
127-
if (!$stack) {
127+
if (null === $stack) {
128128
return;
129129
}
130130

@@ -143,7 +143,7 @@ private function collectRequestInformations(RequestInterface $request, Stack $st
143143
*/
144144
private function collectResponseInformations(ResponseInterface $response, StopwatchEvent $event, Stack $stack = null)
145145
{
146-
if (!$stack) {
146+
if (null === $stack) {
147147
return;
148148
}
149149

@@ -163,7 +163,7 @@ private function collectExceptionInformations(\Exception $exception, StopwatchEv
163163
$this->collectResponseInformations($exception->getResponse(), $event, $stack);
164164
}
165165

166-
if (!$stack) {
166+
if (null === $stack) {
167167
return;
168168
}
169169

Collector/ProfilePlugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public function handleRequest(RequestInterface $request, callable $next, callabl
5858
{
5959
$profile = new Profile($this->pluginName, $this->formatter->formatRequest($request));
6060

61-
if ($stack = $this->collector->getCurrentStack()) {
61+
$stack = $this->collector->getCurrentStack();
62+
if (null !== $stack) {
6263
$stack->addProfile($profile);
6364
}
6465

0 commit comments

Comments
 (0)