Skip to content

Commit c882c4e

Browse files
HP-2824: added context to ChargeStealingException class and removed ChargeStealingException::getCharge() method
1 parent 7e537b4 commit c882c4e

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/Exception/ChargeStealingException.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace hiqdev\php\billing\Exception;
1313

14+
use hidev\exception\HasContext;
15+
use hidev\exception\HasContextInterface;
1416
use hiqdev\php\billing\charge\ChargeInterface;
1517
use hiqdev\php\billing\ExceptionInterface;
1618
use Exception;
@@ -21,8 +23,10 @@
2123
*
2224
* @author Dmytro Naumenko <[email protected]>
2325
*/
24-
final class ChargeStealingException extends Exception implements ExceptionInterface
26+
final class ChargeStealingException extends Exception implements ExceptionInterface, HasContextInterface
2527
{
28+
use HasContext;
29+
2630
private ChargeInterface $charge;
2731

2832
public static function fromPdoException(ChargeInterface $charge, Exception $exception): self
@@ -31,7 +35,7 @@ public static function fromPdoException(ChargeInterface $charge, Exception $exce
3135
'Charge being saved tries to steal an existing charge from another bill: %s',
3236
self::trimExceptionMessage($exception->getMessage())
3337
));
34-
$self->charge = $charge;
38+
$self->addContext(['charge' => $charge]);
3539

3640
return $self;
3741
}
@@ -40,9 +44,4 @@ private static function trimExceptionMessage(string $message): string
4044
{
4145
return preg_replace('/^.+ERROR:\s+([^\n]+).+$/s', '$1', $message);
4246
}
43-
44-
public function getCharge(): ChargeInterface
45-
{
46-
return $this->charge;
47-
}
4847
}

0 commit comments

Comments
 (0)