Skip to content

Commit 2ee383a

Browse files
carlbennettclaude
andcommitted
Fix implicit-nullable deprecation that 500'd every "not found" page
All twelve *NotFoundException classes declared their optional $previous parameter as `\Throwable $previous = null` instead of `?\Throwable $previous = null`. Implicitly marking a parameter nullable this way has been deprecated since PHP 8.4, and production (PHP 8.5) raises E_DEPRECATED the instant any of these constructors runs - which is on every "not found" code path (Document, User, Packet, Server, News Post/Category, Comment, Product, Event, User Profile, and the Controller/Template lookup failures). Combined with this app's error handler treating any raised error as fatal, that meant e.g. GET /document/999999 500'd instead of rendering a 404. Confirmed live before this fix: `curl -o /dev/null -w '%{http_code}' https://bnetdocs.org/document/999999/x` returned 500. Add tests/Exceptions/NotFoundExceptionsTest.php, which had no prior coverage at all, asserting each class's constructor raises no PHP error and still behaves correctly (throwable, preserves $previous). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent 8e26e92 commit 2ee383a

13 files changed

Lines changed: 139 additions & 12 deletions

‎src/Exceptions/CommentNotFoundException.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class CommentNotFoundException extends DatabaseObjectNotFoundException
66
{
7-
public function __construct(\BNETDocs\Libraries\Comment|int $value, \Throwable $previous = null)
7+
public function __construct(\BNETDocs\Libraries\Comment|int $value, ?\Throwable $previous = null)
88
{
99
$v = is_int($value) ? $value : $value->getId();
1010
parent::__construct(\sprintf('Comment not found: %d', $v), 0, $previous);

‎src/Exceptions/ControllerNotFoundException.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ControllerNotFoundException extends \InvalidArgumentException
66
{
7-
public function __construct(string $value, \Throwable $previous = null)
7+
public function __construct(string $value, ?\Throwable $previous = null)
88
{
99
parent::__construct(\sprintf('Controller not found: %s', $value), 0, $previous);
1010
}

‎src/Exceptions/DocumentNotFoundException.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class DocumentNotFoundException extends DatabaseObjectNotFoundException
66
{
7-
public function __construct(\BNETDocs\Libraries\Document|int $value, \Throwable $previous = null)
7+
public function __construct(\BNETDocs\Libraries\Document|int $value, ?\Throwable $previous = null)
88
{
99
$v = is_int($value) ? $value : $value->getId();
1010
parent::__construct(\sprintf('Document not found: %d', $v), 0, $previous);

‎src/Exceptions/EventNotFoundException.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class EventNotFoundException extends DatabaseObjectNotFoundException
66
{
7-
public function __construct(\BNETDocs\Libraries\EventLog\Event|int $value, \Throwable $previous = null)
7+
public function __construct(\BNETDocs\Libraries\EventLog\Event|int $value, ?\Throwable $previous = null)
88
{
99
$v = is_int($value) ? $value : $value->getId();
1010
parent::__construct(\sprintf('Event log id not found: %d', $v), 0, $previous);

‎src/Exceptions/NewsCategoryNotFoundException.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class NewsCategoryNotFoundException extends DatabaseObjectNotFoundException
66
{
7-
public function __construct(\BNETDocs\Libraries\News\Category|int $value, \Throwable $previous = null)
7+
public function __construct(\BNETDocs\Libraries\News\Category|int $value, ?\Throwable $previous = null)
88
{
99
$v = is_int($value) ? $value : $value->getId();
1010
parent::__construct(\sprintf('News Category not found: %d', $v), 0, $previous);

‎src/Exceptions/NewsPostNotFoundException.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class NewsPostNotFoundException extends DatabaseObjectNotFoundException
66
{
7-
public function __construct(\BNETDocs\Libraries\News\Post|int $value, \Throwable $previous = null)
7+
public function __construct(\BNETDocs\Libraries\News\Post|int $value, ?\Throwable $previous = null)
88
{
99
$v = is_int($value) ? $value : $value->getId();
1010
parent::__construct(\sprintf('News Post not found: %d', $v), 0, $previous);

‎src/Exceptions/PacketNotFoundException.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class PacketNotFoundException extends DatabaseObjectNotFoundException
66
{
7-
public function __construct(\BNETDocs\Libraries\Packet\Packet|int $value, \Throwable $previous = null)
7+
public function __construct(\BNETDocs\Libraries\Packet\Packet|int $value, ?\Throwable $previous = null)
88
{
99
$v = is_int($value) ? $value : $value->getId();
1010
parent::__construct(\sprintf('Packet not found: %d', $v), 0, $previous);

‎src/Exceptions/ProductNotFoundException.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ProductNotFoundException extends DatabaseObjectNotFoundException
66
{
7-
public function __construct(\BNETDocs\Libraries\Product|int $value, \Throwable $previous = null)
7+
public function __construct(\BNETDocs\Libraries\Product|int $value, ?\Throwable $previous = null)
88
{
99
$v = is_int($value) ? $value : $value->getBnetProductId();
1010
parent::__construct(\sprintf('Product not found: %d', $v), 0, $previous);

‎src/Exceptions/ServerNotFoundException.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ServerNotFoundException extends DatabaseObjectNotFoundException
66
{
7-
public function __construct(\BNETDocs\Libraries\Server\Server|int $value, \Throwable $previous = null)
7+
public function __construct(\BNETDocs\Libraries\Server\Server|int $value, ?\Throwable $previous = null)
88
{
99
$v = is_int($value) ? $value : $value->getId();
1010
parent::__construct(\sprintf('Server not found: %d', $v), 0, $previous);

‎src/Exceptions/TemplateNotFoundException.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class TemplateNotFoundException extends \InvalidArgumentException
66
{
7-
public function __construct(\BNETDocs\Libraries\Core\Template|string $value, \Throwable $previous = null)
7+
public function __construct(\BNETDocs\Libraries\Core\Template|string $value, ?\Throwable $previous = null)
88
{
99
$v = is_string($value) ? $value : $value->getTemplateFile();
1010
parent::__construct(\sprintf('Template not found: %s', $v), 0, $previous);

0 commit comments

Comments
 (0)