From de6bb8a05a04eba9eae6131dfda6b2dea0611a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yunus=20Emre=20Delig=C3=B6z?= Date: Tue, 13 Aug 2024 14:01:20 +0300 Subject: [PATCH] WB-291: Add parentheses to object instantiations Ensured consistent usage of parentheses during object instantiation across multiple files. This change improves code readability and aligns with best coding practices. --- pint.json | 3 ++- src/Actor/Machine.php | 2 +- src/Actor/State.php | 2 +- src/Behavior/ActionBehavior.php | 4 +++- src/Behavior/GuardBehavior.php | 4 +++- src/Behavior/InvokableBehavior.php | 2 +- src/Behavior/ResultBehavior.php | 4 +++- src/ContextManager.php | 3 ++- src/Definition/MachineDefinition.php | 2 +- src/EventCollection.php | 4 +++- .../MachineContextValidationException.php | 4 +++- src/Exceptions/MachineEventValidationException.php | 4 +++- src/Exceptions/MachineValidationException.php | 4 +++- tests/ActionTest.php | 2 +- tests/ActorTest.php | 6 +++--- tests/ContextManagerTest.php | 14 +++++++------- tests/EventMachineTest.php | 2 +- tests/EventTest.php | 2 +- tests/MachineActorSerializationTest.php | 2 +- tests/MachineTransitionTest.php | 4 ++-- .../Actions/DoNothingInsideClassAction.php | 4 +++- .../TrafficLights/TrafficLightsMachine.php | 6 ++++-- tests/Stubs/Machines/Xyz/Actions/YAction.php | 2 +- 23 files changed, 53 insertions(+), 33 deletions(-) diff --git a/pint.json b/pint.json index b59230b0..19f1ab5e 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 4a18b24d..ca69194e 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 a3ccc536..14690e87 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 c29d05ce..086181f9 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 f64bdc03..015f5f63 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 de983e39..9c2197e1 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 3188ed14..2551a83c 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 b323fcda..1d659724 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 b84bfbb8..bb88c096 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 4ddd2f4f..23d178ec 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 d3b9cefa..7cabc48d 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 83ca2d82..01fe142f 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 cbfc376f..c417d76e 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 82655e01..0719124e 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 ce922209..0951a040 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 53adca3a..851e19ff 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 0ccc3504..cc4d2902 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 568ab910..fc7a3da4 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 55edb434..92d2aedb 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 1f0e1a77..605bcf55 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 179f2dfa..bc2efed6 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 ff33129e..11ad772b 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 340e1dcb..2dec6e90 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()); } }