diff --git a/pint.json b/pint.json index b59230b..19f1ab5 100644 --- a/pint.json +++ b/pint.json @@ -84,6 +84,7 @@ "property": "none", "trait_import": "none" } - } + }, + "new_with_parentheses": true } } diff --git a/src/Actor/Machine.php b/src/Actor/Machine.php index 4a18b24..ca69194 100644 --- a/src/Actor/Machine.php +++ b/src/Actor/Machine.php @@ -488,7 +488,7 @@ public function result(): mixed [$resultBehavior, $arguments] = explode(':', $resultBehavior); } - $resultBehavior = new $resultBehavior; + $resultBehavior = new $resultBehavior(); } /* @var callable $resultBehavior */ diff --git a/src/Actor/State.php b/src/Actor/State.php index a3ccc53..14690e8 100644 --- a/src/Actor/State.php +++ b/src/Actor/State.php @@ -44,7 +44,7 @@ public function __construct( public ?EventBehavior $currentEventBehavior = null, public ?EventCollection $history = null, ) { - $this->history ??= new EventCollection; + $this->history ??= new EventCollection(); $this->updateMachineValueFromState(); } diff --git a/src/Behavior/ActionBehavior.php b/src/Behavior/ActionBehavior.php index c29d05c..086181f 100644 --- a/src/Behavior/ActionBehavior.php +++ b/src/Behavior/ActionBehavior.php @@ -10,4 +10,6 @@ * This abstract class extends the InvokableBehavior class. It provides a way to define action behaviors * that can be invoked within a specific context. */ -abstract class ActionBehavior extends InvokableBehavior {} +abstract class ActionBehavior extends InvokableBehavior +{ +} diff --git a/src/Behavior/GuardBehavior.php b/src/Behavior/GuardBehavior.php index f64bdc0..015f5f6 100644 --- a/src/Behavior/GuardBehavior.php +++ b/src/Behavior/GuardBehavior.php @@ -10,4 +10,6 @@ * This is an abstract class that extends InvokableBehavior and provides the base structure for guard behavior classes. * Guards are used in event-driven systems to determine whether an event should be allowed to proceed or not. */ -abstract class GuardBehavior extends InvokableBehavior {} +abstract class GuardBehavior extends InvokableBehavior +{ +} diff --git a/src/Behavior/InvokableBehavior.php b/src/Behavior/InvokableBehavior.php index de983e3..9c2197e 100644 --- a/src/Behavior/InvokableBehavior.php +++ b/src/Behavior/InvokableBehavior.php @@ -37,7 +37,7 @@ abstract class InvokableBehavior public function __construct(protected ?Collection $eventQueue = null) { if ($this->eventQueue === null) { - $this->eventQueue = new Collection; + $this->eventQueue = new Collection(); } } diff --git a/src/Behavior/ResultBehavior.php b/src/Behavior/ResultBehavior.php index 3188ed1..2551a83 100644 --- a/src/Behavior/ResultBehavior.php +++ b/src/Behavior/ResultBehavior.php @@ -4,4 +4,6 @@ namespace Tarfinlabs\EventMachine\Behavior; -abstract class ResultBehavior extends InvokableBehavior {} +abstract class ResultBehavior extends InvokableBehavior +{ +} diff --git a/src/ContextManager.php b/src/ContextManager.php index b323fcd..1d65972 100644 --- a/src/ContextManager.php +++ b/src/ContextManager.php @@ -28,7 +28,8 @@ class ContextManager extends Data public function __construct( #[ArrayType] public array|Optional $data = [], - ) {} + ) { + } /** * Get a value from the context by its key. diff --git a/src/Definition/MachineDefinition.php b/src/Definition/MachineDefinition.php index b84bfbb..bb88c09 100644 --- a/src/Definition/MachineDefinition.php +++ b/src/Definition/MachineDefinition.php @@ -102,7 +102,7 @@ private function __construct( $this->checkFinalStatesForTransitions(); - $this->eventQueue = new Collection; + $this->eventQueue = new Collection(); $this->initialStateDefinition = $this->root->initialStateDefinition; diff --git a/src/EventCollection.php b/src/EventCollection.php index 4ddd2f4..23d178e 100644 --- a/src/EventCollection.php +++ b/src/EventCollection.php @@ -6,4 +6,6 @@ use Illuminate\Database\Eloquent\Collection; -class EventCollection extends Collection {} +class EventCollection extends Collection +{ +} diff --git a/src/Exceptions/MachineContextValidationException.php b/src/Exceptions/MachineContextValidationException.php index d3b9cef..7cabc48 100644 --- a/src/Exceptions/MachineContextValidationException.php +++ b/src/Exceptions/MachineContextValidationException.php @@ -9,4 +9,6 @@ /** * Represents an exception thrown when the validation of the machine context fails. */ -class MachineContextValidationException extends ValidationException {} +class MachineContextValidationException extends ValidationException +{ +} diff --git a/src/Exceptions/MachineEventValidationException.php b/src/Exceptions/MachineEventValidationException.php index 83ca2d8..01fe142 100644 --- a/src/Exceptions/MachineEventValidationException.php +++ b/src/Exceptions/MachineEventValidationException.php @@ -11,4 +11,6 @@ * * This class represents an exception that is thrown when a validation error occurs while processing a machine event. */ -class MachineEventValidationException extends ValidationException {} +class MachineEventValidationException extends ValidationException +{ +} diff --git a/src/Exceptions/MachineValidationException.php b/src/Exceptions/MachineValidationException.php index cbfc376..c417d76 100644 --- a/src/Exceptions/MachineValidationException.php +++ b/src/Exceptions/MachineValidationException.php @@ -12,4 +12,6 @@ * This exception is used to handle validation errors specific to the Machine class. * It extends the ValidationException class to provide more specific functionality. */ -class MachineValidationException extends ValidationException {} +class MachineValidationException extends ValidationException +{ +} diff --git a/tests/ActionTest.php b/tests/ActionTest.php index 82655e0..0719124 100644 --- a/tests/ActionTest.php +++ b/tests/ActionTest.php @@ -91,7 +91,7 @@ // 1. Arrange $value = random_int(10, 20); - $multipleWithItselfAction = new class extends ResultBehavior { + $multipleWithItselfAction = new class() extends ResultBehavior { public function __invoke(EventBehavior $event): int { return $event->payload['value'] * $event->payload['value']; diff --git a/tests/ActorTest.php b/tests/ActorTest.php index ce92220..0951a04 100644 --- a/tests/ActorTest.php +++ b/tests/ActorTest.php @@ -14,11 +14,11 @@ Log::shouldReceive('debug')->with('Q Event Even Actor')->once(); Log::shouldReceive('debug')->with('Q Event Odd Actor')->once(); - $machine->send(event: new QEvent); + $machine->send(event: new QEvent()); Log::shouldReceive('debug')->with(null)->once(); - $machine->send(event: new EEvent); + $machine->send(event: new EEvent()); Log::shouldReceive('debug')->with('R Actor')->times(3); - $machine->send(event: new REvent); + $machine->send(event: new REvent()); }); diff --git a/tests/ContextManagerTest.php b/tests/ContextManagerTest.php index 53adca3..851e19f 100644 --- a/tests/ContextManagerTest.php +++ b/tests/ContextManagerTest.php @@ -10,13 +10,13 @@ use Tarfinlabs\EventMachine\Tests\Stubs\Machines\TrafficLights\TrafficLightsMachine; it('can initialize an empty context manager', function (): void { - $context = new ContextManager; + $context = new ContextManager(); expect($context)->toBeInstanceOf(ContextManager::class); }); it('can set and get context manager data', function (): void { - $context = new ContextManager; + $context = new ContextManager(); $key1 = 'key1'; $value1 = 'value1'; @@ -49,13 +49,13 @@ }); it('returns null for non-existent keys', function (): void { - $context = new ContextManager; + $context = new ContextManager(); expect($context->get(key: 'non_existent_key'))->toBeNull(); }); it('can check if a key exists', function (): void { - $context = new ContextManager; + $context = new ContextManager(); $context->set(key: 'key1', value: 'value1'); expect($context->has(key: 'key1'))->toBeTrue(); @@ -72,7 +72,7 @@ }); it('can remove a key from context data', function (): void { - $context = new ContextManager; + $context = new ContextManager(); $context->set(key: 'key1', value: 'value1'); $context->set(key: 'key2', value: 'value2'); @@ -103,7 +103,7 @@ }); it('can handle edge cases with empty keys and values', function (): void { - $context = new ContextManager; + $context = new ContextManager(); $context->set(key: '', value: 'empty_key_value'); $context->set(key: 'empty_value_key', value: ''); @@ -161,6 +161,6 @@ $machine->state->context->set('arrayKey', []); expect($machine->state->context->has(key: 'arrayKey', type: 'array'))->toBe(true); - $machine->state->context->set('objectKey', new MachineEvent); + $machine->state->context->set('objectKey', new MachineEvent()); expect($machine->state->context->has(key: 'objectKey', type: MachineEvent::class))->toBe(true); }); diff --git a/tests/EventMachineTest.php b/tests/EventMachineTest.php index 0ccc350..cc4d290 100644 --- a/tests/EventMachineTest.php +++ b/tests/EventMachineTest.php @@ -56,7 +56,7 @@ test('TrafficLightsMachine transitions between states using an IncreaseEvent implementing EventBehavior', function (): void { $machineDefinition = TrafficLightsMachine::definition(); - $increaseEvent = new IncreaseEvent; + $increaseEvent = new IncreaseEvent(); expect($increaseEvent)->toBeInstanceOf(EventBehavior::class); $newState = $machineDefinition->transition(event: $increaseEvent); diff --git a/tests/EventTest.php b/tests/EventTest.php index 568ab91..fc7a3da 100644 --- a/tests/EventTest.php +++ b/tests/EventTest.php @@ -5,7 +5,7 @@ use Tarfinlabs\EventMachine\Behavior\EventBehavior; test('an event has a version', function (): void { - $eventWithoutExplicitVersionDefinition = new class extends EventBehavior { + $eventWithoutExplicitVersionDefinition = new class() extends EventBehavior { public static function getType(): string { return 'TEST_EVENT'; diff --git a/tests/MachineActorSerializationTest.php b/tests/MachineActorSerializationTest.php index 55edb43..92d2aed 100644 --- a/tests/MachineActorSerializationTest.php +++ b/tests/MachineActorSerializationTest.php @@ -6,7 +6,7 @@ use Tarfinlabs\EventMachine\Tests\Stubs\Models\ModelA; test('a machine as a model attribute can serialize as root_event_id', function (): void { - $modelA = new ModelA; + $modelA = new ModelA(); expect($modelA->abc_mre)->toBeInstanceOf(Machine::class); expect($modelA->traffic_mre)->toBeInstanceOf(Machine::class); diff --git a/tests/MachineTransitionTest.php b/tests/MachineTransitionTest.php index 1f0e1a7..605bcf5 100644 --- a/tests/MachineTransitionTest.php +++ b/tests/MachineTransitionTest.php @@ -102,7 +102,7 @@ it('If the event is transactional, it rolls back the data', function (): void { $machine = AsdMachine::create(); - expect(fn () => $machine->send(new SEvent)) + expect(fn () => $machine->send(new SEvent())) ->toThrow(new Exception('error')); $models = ModelA::all(); @@ -127,5 +127,5 @@ ->withAnyArgs() ->andReturn(false); - $machine->send(new EEvent); + $machine->send(new EEvent()); })->throws(MachineAlreadyRunningException::class); diff --git a/tests/Stubs/Machines/TrafficLights/Actions/DoNothingInsideClassAction.php b/tests/Stubs/Machines/TrafficLights/Actions/DoNothingInsideClassAction.php index 179f2df..bc2efed 100644 --- a/tests/Stubs/Machines/TrafficLights/Actions/DoNothingInsideClassAction.php +++ b/tests/Stubs/Machines/TrafficLights/Actions/DoNothingInsideClassAction.php @@ -8,5 +8,7 @@ class DoNothingInsideClassAction extends ActionBehavior { - public function __invoke(): void {} + public function __invoke(): void + { + } } diff --git a/tests/Stubs/Machines/TrafficLights/TrafficLightsMachine.php b/tests/Stubs/Machines/TrafficLights/TrafficLightsMachine.php index ff33129..11ad772 100644 --- a/tests/Stubs/Machines/TrafficLights/TrafficLightsMachine.php +++ b/tests/Stubs/Machines/TrafficLights/TrafficLightsMachine.php @@ -58,8 +58,10 @@ public static function definition(): MachineDefinition 'DEX' => DecreaseEvent::class, ], 'actions' => [ - 'doNothingAction' => function (): void {}, - 'doNothingAction2' => function (ContextManager $context, EventBehavior $eventBehavior): void {}, + 'doNothingAction' => function (): void { + }, + 'doNothingAction2' => function (ContextManager $context, EventBehavior $eventBehavior): void { + }, 'doNothingInsideClassAction' => DoNothingInsideClassAction::class, ], ], diff --git a/tests/Stubs/Machines/Xyz/Actions/YAction.php b/tests/Stubs/Machines/Xyz/Actions/YAction.php index 340e1dc..2dec6e9 100644 --- a/tests/Stubs/Machines/Xyz/Actions/YAction.php +++ b/tests/Stubs/Machines/Xyz/Actions/YAction.php @@ -14,6 +14,6 @@ public function __invoke(ContextManager $context): void { $context->value .= 'y'; - $this->raise(new YEvent); + $this->raise(new YEvent()); } }