[Console] fall back to 0 when getCode() does not provide an integer

This commit is contained in:
Martin Komischke
2026-01-29 16:19:34 +01:00
committed by Nicolas Grekas
parent 852c1d7401
commit 8e26e05b43
2 changed files with 7 additions and 1 deletions

View File

@@ -46,7 +46,7 @@ class ExceptionDataCollector extends DataCollector
return $this->data['exception']->getMessage();
}
public function getCode(): int
public function getCode(): int|string
{
return $this->data['exception']->getCode();
}

View File

@@ -36,6 +36,12 @@ class ExceptionDataCollectorTest extends TestCase
$this->assertSame(500, $c->getCode());
$this->assertSame('exception', $c->getName());
$this->assertSame($trace, $c->getTrace());
$c->collect(new Request(), new Response(), new class() extends \Exception {
protected $code = 'non-integer-code';
});
$this->assertSame('non-integer-code', $c->getCode());
}
public function testCollectWithoutException()