Skip to content

Commit 7cccf4b

Browse files
HP-2824: Fix Failing Psalm Static Analysis in php-billing Composer Package Build (#111)
* AHN-131: Fix Failing Psalm Static Analysis in php-billing Composer Package Build * AHN-131: removed unused CannotReassignException::getField() method * AHN-131: removed unused CannotReassignException::$field property * HP-2824: added context to ChargeOverlappingException class and removed ChargeOverlappingException::getCharge() method * HP-2824: added context to ChargeStealingException class and removed ChargeStealingException::getCharge() method * HP-2824: The context key 'filed' is a typo for 'field', and will cause problems for code inspecting context by this key. * HP-2824: fixed template for PriceTypeCollection * HP-2824: Remove the unused $charge property.
1 parent 6015ba8 commit 7cccf4b

File tree

7 files changed

+30
-34
lines changed

7 files changed

+30
-34
lines changed

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
ensureArrayStringOffsetsExist="true"
1515
ensureArrayIntOffsetsExist="true"
1616
ignoreInternalFunctionFalseReturn="false"
17+
ensureOverrideAttribute="false"
1718
>
1819
<projectFiles>
1920
<directory name="src" />

src/Exception/ActionChargingException.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace hiqdev\php\billing\Exception;
55

6+
use hidev\exception\HasContext;
7+
use hidev\exception\HasContextInterface;
68
use hiqdev\php\billing\action\ActionInterface;
79
use Throwable;
810

@@ -12,9 +14,9 @@
1214
*
1315
* @author Dmytro Naumenko <d.naumenko.a@gmail.com>
1416
*/
15-
final class ActionChargingException extends RuntimeException
17+
final class ActionChargingException extends RuntimeException implements HasContextInterface
1618
{
17-
private readonly ActionInterface $action;
19+
use HasContext;
1820

1921
public static function forAction(ActionInterface $action, Throwable $previousException): self
2022
{
@@ -32,13 +34,8 @@ public static function forAction(ActionInterface $action, Throwable $previousExc
3234
}
3335

3436
$self = new self($message, 0, $previousException);
35-
$self->action = $action;
37+
$self->addContext(['action' => $action]);
3638

3739
return $self;
3840
}
39-
40-
public function getAction(): ActionInterface
41-
{
42-
return $this->action;
43-
}
4441
}

src/Exception/CannotReassignException.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,22 @@
1111
namespace hiqdev\php\billing\Exception;
1212

1313
use Exception;
14+
use hidev\exception\HasContext;
15+
use hidev\exception\HasContextInterface;
1416
use hiqdev\php\billing\ExceptionInterface;
1517
use Throwable;
1618

1719
/**
1820
* @author Andrii Vasyliev <sol@hiqdev.com>
1921
*/
20-
class CannotReassignException extends Exception implements ExceptionInterface
22+
class CannotReassignException extends Exception implements ExceptionInterface, HasContextInterface
2123
{
22-
private $field;
24+
use HasContext;
2325

24-
public function __construct(string $message, int $code = 0, Throwable $previous = null)
26+
public function __construct(string $message, int $code = 0, ?Throwable $previous = null)
2527
{
26-
$this->field = $message;
27-
parent::__construct("cannot reassign $message", $code, $previous);
28-
}
28+
$this->addContext(['field' => $message]);
2929

30-
public function getField()
31-
{
32-
return $this->field;
30+
parent::__construct("cannot reassign $message", $code, $previous);
3331
}
3432
}

src/Exception/ChargeOverlappingException.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010

1111
namespace hiqdev\php\billing\Exception;
1212

13+
use hidev\exception\HasContext;
14+
use hidev\exception\HasContextInterface;
1315
use hiqdev\php\billing\charge\ChargeInterface;
1416
use hiqdev\php\billing\ExceptionInterface;
1517
use Exception;
1618

17-
final class ChargeOverlappingException extends Exception implements ExceptionInterface
19+
final class ChargeOverlappingException extends Exception implements ExceptionInterface, HasContextInterface
1820
{
19-
private ChargeInterface $charge;
21+
use HasContext;
2022

2123
public static function forCharge(ChargeInterface $charge): self
2224
{
@@ -25,13 +27,11 @@ public static function forCharge(ChargeInterface $charge): self
2527
$charge->getId(),
2628
$charge->getUniqueString()
2729
));
28-
$self->charge = $charge;
30+
$self->addContext([
31+
'chargeTypeName' => $charge->getType()->getName(),
32+
'chargeActionTime' => $charge->getAction()->getTime()->format(DATE_ATOM),
33+
]);
2934

3035
return $self;
3136
}
32-
33-
public function getCharge(): ChargeInterface
34-
{
35-
return $this->charge;
36-
}
3737
}

src/Exception/ChargeStealingException.php

Lines changed: 5 additions & 8 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,17 +23,17 @@
2123
*
2224
* @author Dmytro Naumenko <d.naumenko.a@gmail.com>
2325
*/
24-
final class ChargeStealingException extends Exception implements ExceptionInterface
26+
final class ChargeStealingException extends Exception implements ExceptionInterface, HasContextInterface
2527
{
26-
private ChargeInterface $charge;
28+
use HasContext;
2729

2830
public static function fromPdoException(ChargeInterface $charge, Exception $exception): self
2931
{
3032
$self = new self(sprintf(
3133
'Charge being saved tries to steal an existing charge from another bill: %s',
3234
self::trimExceptionMessage($exception->getMessage())
3335
));
34-
$self->charge = $charge;
36+
$self->addContext(['charge' => $charge]);
3537

3638
return $self;
3739
}
@@ -40,9 +42,4 @@ private static function trimExceptionMessage(string $message): string
4042
{
4143
return preg_replace('/^.+ERROR:\s+([^\n]+).+$/s', '$1', $message);
4244
}
43-
44-
public function getCharge(): ChargeInterface
45-
{
46-
return $this->charge;
47-
}
4845
}

src/formula/FormulaEngine.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ private function getOnce(): ChargeModifier
232232
return $this->once;
233233
}
234234

235-
public function __clone(): void
235+
public function __clone()
236236
{
237237
if ($this->context !== null) {
238238
$this->context = clone $this->context;

src/product/Domain/Model/Price/PriceTypeCollection.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
use IteratorAggregate;
1010
use Traversable;
1111

12+
/**
13+
* @template-implements IteratorAggregate<int, PriceTypeInterface>
14+
*/
1215
class PriceTypeCollection implements IteratorAggregate, Countable
1316
{
1417
/**

0 commit comments

Comments
 (0)