Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Common/Exception/BadMethodCallException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Atournayre\Common\Exception;

use Atournayre\Contracts\Exception\ThrowableInterface;
use Atournayre\Contracts\Log\LoggableInterface;

class BadMethodCallException extends \BadMethodCallException implements ThrowableInterface
class BadMethodCallException extends \BadMethodCallException implements ThrowableInterface, LoggableInterface
{
use ThrowableTrait;
use LoggableThrowableTrait;
}
5 changes: 3 additions & 2 deletions src/Common/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Atournayre\Common\Exception;

use Atournayre\Contracts\Exception\ThrowableInterface;
use Atournayre\Contracts\Log\LoggableInterface;

class InvalidArgumentException extends \InvalidArgumentException implements ThrowableInterface
class InvalidArgumentException extends \InvalidArgumentException implements ThrowableInterface, LoggableInterface
{
use ThrowableTrait;
use LoggableThrowableTrait;
}
39 changes: 39 additions & 0 deletions src/Common/Exception/LoggableThrowableTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace Atournayre\Common\Exception;

/**
* Trait combining ThrowableTrait with LoggableInterface implementation.
*
* This trait provides both exception functionality (via ThrowableTrait)
* and loggability (via toLog method). Use this trait when an exception
* needs to implement both ThrowableInterface and LoggableInterface.
*
* @example
* class MyException extends \Exception implements ThrowableInterface, LoggableInterface
* {
* use LoggableThrowableTrait;
* }
*/
trait LoggableThrowableTrait
{
use ThrowableTrait;

/**
* Converts the exception to a loggable array format.
*
* @return array<string, mixed>
*/
public function toLog(): array
{
return [
'message' => $this->getMessage(),
'code' => $this->getCode(),
'file' => $this->getFile(),
'line' => $this->getLine(),
'trace' => $this->getTraceAsString(),
];
}
}
5 changes: 3 additions & 2 deletions src/Common/Exception/MutableException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace Atournayre\Common\Exception;

use Atournayre\Contracts\Exception\ThrowableInterface;
use Atournayre\Contracts\Log\LoggableInterface;

class MutableException extends \RuntimeException implements ThrowableInterface
class MutableException extends \RuntimeException implements ThrowableInterface, LoggableInterface
{
use ThrowableTrait;
use LoggableThrowableTrait;

public static function becauseMustBeImmutable(): self
{
Expand Down
5 changes: 3 additions & 2 deletions src/Common/Exception/NullException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
namespace Atournayre\Common\Exception;

use Atournayre\Contracts\Exception\ThrowableInterface;
use Atournayre\Contracts\Log\LoggableInterface;

class NullException extends \Exception implements ThrowableInterface
class NullException extends \Exception implements ThrowableInterface, LoggableInterface
{
use ThrowableTrait;
use LoggableThrowableTrait;

/**
* @api
Expand Down
5 changes: 3 additions & 2 deletions src/Common/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Atournayre\Common\Exception;

use Atournayre\Contracts\Exception\ThrowableInterface;
use Atournayre\Contracts\Log\LoggableInterface;

class RuntimeException extends \RuntimeException implements ThrowableInterface
class RuntimeException extends \RuntimeException implements ThrowableInterface, LoggableInterface
{
use ThrowableTrait;
use LoggableThrowableTrait;
}
5 changes: 3 additions & 2 deletions src/Common/Exception/UnexpectedValueException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
namespace Atournayre\Common\Exception;

use Atournayre\Contracts\Exception\ThrowableInterface;
use Atournayre\Contracts\Log\LoggableInterface;

class UnexpectedValueException extends \UnexpectedValueException implements ThrowableInterface
class UnexpectedValueException extends \UnexpectedValueException implements ThrowableInterface, LoggableInterface
{
use ThrowableTrait;
use LoggableThrowableTrait;
}
2 changes: 1 addition & 1 deletion src/Contracts/Collection/UnshiftInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ interface UnshiftInterface
*
* @api
*/
public function unshift(mixed $value, $key = null): self;
public function unshift(mixed $value, int|string|null $key = null): self;
}
Loading