Skip to content

Commit

Permalink
WB-291: Add parentheses to object instantiations
Browse files Browse the repository at this point in the history
Ensured consistent usage of parentheses during object instantiation across multiple files. This change improves code readability and aligns with best coding practices.
  • Loading branch information
deligoez committed Aug 13, 2024
1 parent 6d16398 commit de6bb8a
Show file tree
Hide file tree
Showing 23 changed files with 53 additions and 33 deletions.
3 changes: 2 additions & 1 deletion pint.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
"property": "none",
"trait_import": "none"
}
}
},
"new_with_parentheses": true
}
}
2 changes: 1 addition & 1 deletion src/Actor/Machine.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ public function result(): mixed
[$resultBehavior, $arguments] = explode(':', $resultBehavior);
}

$resultBehavior = new $resultBehavior;
$resultBehavior = new $resultBehavior();
}

/* @var callable $resultBehavior */
Expand Down
2 changes: 1 addition & 1 deletion src/Actor/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion src/Behavior/ActionBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
4 changes: 3 additions & 1 deletion src/Behavior/GuardBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
2 changes: 1 addition & 1 deletion src/Behavior/InvokableBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/Behavior/ResultBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

namespace Tarfinlabs\EventMachine\Behavior;

abstract class ResultBehavior extends InvokableBehavior {}
abstract class ResultBehavior extends InvokableBehavior
{
}
3 changes: 2 additions & 1 deletion src/ContextManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/Definition/MachineDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private function __construct(

$this->checkFinalStatesForTransitions();

$this->eventQueue = new Collection;
$this->eventQueue = new Collection();

$this->initialStateDefinition = $this->root->initialStateDefinition;

Expand Down
4 changes: 3 additions & 1 deletion src/EventCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@

use Illuminate\Database\Eloquent\Collection;

class EventCollection extends Collection {}
class EventCollection extends Collection
{
}
4 changes: 3 additions & 1 deletion src/Exceptions/MachineContextValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@
/**
* Represents an exception thrown when the validation of the machine context fails.
*/
class MachineContextValidationException extends ValidationException {}
class MachineContextValidationException extends ValidationException
{
}
4 changes: 3 additions & 1 deletion src/Exceptions/MachineEventValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
4 changes: 3 additions & 1 deletion src/Exceptions/MachineValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
2 changes: 1 addition & 1 deletion tests/ActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
6 changes: 3 additions & 3 deletions tests/ActorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
14 changes: 7 additions & 7 deletions tests/ContextManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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();
Expand All @@ -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');
Expand Down Expand Up @@ -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: '');
Expand Down Expand Up @@ -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);
});
2 changes: 1 addition & 1 deletion tests/EventMachineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/EventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion tests/MachineActorSerializationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions tests/MachineTransitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -127,5 +127,5 @@
->withAnyArgs()
->andReturn(false);

$machine->send(new EEvent);
$machine->send(new EEvent());
})->throws(MachineAlreadyRunningException::class);
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@

class DoNothingInsideClassAction extends ActionBehavior
{
public function __invoke(): void {}
public function __invoke(): void
{
}
}
6 changes: 4 additions & 2 deletions tests/Stubs/Machines/TrafficLights/TrafficLightsMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
],
Expand Down
2 changes: 1 addition & 1 deletion tests/Stubs/Machines/Xyz/Actions/YAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public function __invoke(ContextManager $context): void
{
$context->value .= 'y';

$this->raise(new YEvent);
$this->raise(new YEvent());
}
}

0 comments on commit de6bb8a

Please sign in to comment.