Skip to content
Merged
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
13 changes: 11 additions & 2 deletions Example/Order/Command/Authorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,22 @@
use Metabor\Statemachine\Command;
use Example\Order\Order;
use ArrayAccess;
use InvalidArgumentException;

class Authorize extends Command
{
/**
*/
public function __invoke(Order $order, ArrayAccess $context)
public function __invoke(mixed ...$args): void
{
[$order, $context] = $args + [null, null];

if (!$order instanceof Order) {
throw new InvalidArgumentException('Subject has to be an Order!');
}
if (!$context instanceof ArrayAccess) {
throw new InvalidArgumentException('Context has to be an ArrayAccess!');
}
if ($order->getNumber() != 'PREPAYMENT 2') {
$context['authorize result'] = 'successful';
} else {
Expand All @@ -22,7 +31,7 @@ public function __invoke(Order $order, ArrayAccess $context)
/**
* @return string
*/
public function __toString()
public function __toString(): string
{
return 'Authorize';
}
Expand Down
4 changes: 2 additions & 2 deletions Example/Order/Condition/AuthorizedSuccessful.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ class AuthorizedSuccessful implements ConditionInterface
/**
* @see MetaborStd\Statemachine.ConditionInterface::checkCondition()
*/
public function checkCondition($subject, ArrayAccess $context)
public function checkCondition(object $subject, ArrayAccess $context): bool
{
return ($context['authorize result'] == 'successful');
}

/**
* @see MetaborStd.NamedInterface::getName()
*/
public function getName()
public function getName(): string
{
return 'authorized successful';
}
Expand Down
4 changes: 2 additions & 2 deletions Example/Order/Condition/ShippingDateGreater14Days.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ShippingDateGreater14Days implements ConditionInterface
/**
* @see MetaborStd\Statemachine.ConditionInterface::checkCondition()
*/
public function checkCondition($subject, ArrayAccess $context)
public function checkCondition(object $subject, ArrayAccess $context): bool
{
if (!$subject instanceof Order) {
throw new InvalidArgumentException('Subject has to be an Order!');
Expand All @@ -26,7 +26,7 @@ public function checkCondition($subject, ArrayAccess $context)
/**
* @see MetaborStd.NamedInterface::getName()
*/
public function getName()
public function getName(): string
{
return 'shipping-date >= 14 days';
}
Expand Down
2 changes: 1 addition & 1 deletion Example/Order/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct($number, ProcessInterface $process)
* @param string $name
* @param ArrayAccess $context
*/
public function triggerEvent($name, ArrayAccess $context = null)
public function triggerEvent($name, ?ArrayAccess $context = null)
{
echo 'trigger event "'.$name.'" on '.$this.PHP_EOL;
$this->statemachine->triggerEvent($name, $context);
Expand Down