Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 69be8e6

Browse files
committed
[MonologBridge] Return empty list for unknonwn requests
1 parent b178266 commit 69be8e6

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public function __invoke(array $record)
6060
*/
6161
public function getLogs(/* Request $request = null */)
6262
{
63-
if (1 <= \func_num_args() && null !== ($request = \func_get_arg(0)) && isset($this->records[$hash = spl_object_hash($request)])) {
64-
return $this->records[$hash];
63+
if (1 <= \func_num_args() && null !== $request = \func_get_arg(0)) {
64+
return $this->records[spl_object_hash($request)] ?? array();
6565
}
6666

6767
if (0 === \count($this->records)) {
@@ -76,8 +76,8 @@ public function getLogs(/* Request $request = null */)
7676
*/
7777
public function countErrors(/* Request $request = null */)
7878
{
79-
if (1 <= \func_num_args() && null !== ($request = \func_get_arg(0)) && isset($this->errorCount[$hash = spl_object_hash($request)])) {
80-
return $this->errorCount[$hash];
79+
if (1 <= \func_num_args() && null !== $request = \func_get_arg(0)) {
80+
return $this->errorCount[spl_object_hash($request)] ?? 0;
8181
}
8282

8383
return array_sum($this->errorCount);

src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ public function testWithRequestStack()
5858

5959
$this->assertCount(2, $processor->getLogs($request));
6060
$this->assertSame(1, $processor->countErrors($request));
61+
62+
$this->assertCount(0, $processor->getLogs(new Request()));
63+
$this->assertSame(0, $processor->countErrors(new Request()));
6164
}
6265

6366
private function getRecord($level = Logger::WARNING, $message = 'test')

0 commit comments

Comments
 (0)