Skip to content

Commit

Permalink
bug #29310 [MonologBridge] Return empty list for unknown requests (ro…
Browse files Browse the repository at this point in the history
…0NL)

This PR was merged into the 4.1 branch.

Discussion
----------

[MonologBridge] Return empty list for unknown requests

| Q             | A
| ------------- | ---
| Branch?       | 4.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #...   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!-- required for new features -->

Small continuation of #23659. Currently if the specified request is unknown, you'll get all available requests merged. This fixes it.

Commits
-------

69be8e6 [MonologBridge] Return empty list for unknonwn requests
  • Loading branch information
fabpot committed Nov 26, 2018
2 parents b178266 + 69be8e6 commit d788976
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php
Expand Up @@ -60,8 +60,8 @@ public function __invoke(array $record)
*/
public function getLogs(/* Request $request = null */)
{
if (1 <= \func_num_args() && null !== ($request = \func_get_arg(0)) && isset($this->records[$hash = spl_object_hash($request)])) {
return $this->records[$hash];
if (1 <= \func_num_args() && null !== $request = \func_get_arg(0)) {
return $this->records[spl_object_hash($request)] ?? array();
}

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

return array_sum($this->errorCount);
Expand Down
Expand Up @@ -58,6 +58,9 @@ public function testWithRequestStack()

$this->assertCount(2, $processor->getLogs($request));
$this->assertSame(1, $processor->countErrors($request));

$this->assertCount(0, $processor->getLogs(new Request()));
$this->assertSame(0, $processor->countErrors(new Request()));
}

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

0 comments on commit d788976

Please sign in to comment.