Skip to content

Commit a70c020

Browse files
committed
refactor: clean up code style using pint
1 parent a059c52 commit a70c020

File tree

9 files changed

+34
-52
lines changed

9 files changed

+34
-52
lines changed

contexts/Authorization/Application/Coordinators/AuthenticationCoordinator.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,15 @@
44

55
namespace Contexts\Authorization\Application\Coordinators;
66

7-
use Carbon\CarbonImmutable;
8-
use Contexts\Authorization\Application\DTOs\User\CreateUserDTO;
9-
use Contexts\Authorization\Application\DTOs\User\GetUserListDTO;
10-
use Contexts\Authorization\Application\DTOs\User\UpdateUserDTO;
11-
use Contexts\Authorization\Domain\Factories\UserIdentityFactory;
7+
use Contexts\Authorization\Application\DTOs\Authentication\LoginDTO;
128
use Contexts\Authorization\Domain\Repositories\UserRepository;
13-
use Contexts\Authorization\Domain\Role\Models\RoleId;
14-
use Contexts\Authorization\Domain\UserIdentity\Models\Email;
15-
use Contexts\Authorization\Domain\UserIdentity\Models\Password;
16-
use Contexts\Authorization\Domain\UserIdentity\Models\RoleIdCollection;
17-
use Contexts\Authorization\Domain\UserIdentity\Models\UserId;
18-
use Contexts\Authorization\Domain\UserIdentity\Models\UserIdentity;
19-
use Contexts\Authorization\Domain\UserIdentity\Models\UserStatus;
209
use Contexts\Shared\Application\BaseCoordinator;
21-
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
22-
use Contexts\Authorization\Application\DTOs\Authentication\LoginDTO;
2310

2411
class AuthenticationCoordinator extends BaseCoordinator
2512
{
2613
public function __construct(
2714
private UserRepository $userRepository,
28-
private UserIdentityFactory $factory
29-
) {
30-
}
15+
) {}
3116

3217
public function login(LoginDTO $dto)
3318
{

contexts/Authorization/Application/DTOs/Authentication/LoginDTO.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ class LoginDTO
99
public function __construct(
1010
public readonly string $email,
1111
public readonly string $password,
12-
) {
13-
}
12+
) {}
1413

1514
public static function fromRequest(array $data): self
1615
{

contexts/Authorization/Domain/UserIdentity/Events/UserAuthenticatedEvent.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ class UserAuthenticatedEvent
1313

1414
public function __construct(
1515
private readonly UserId $userId,
16-
) {
17-
}
16+
) {}
1817

1918
public function getUserId(): UserId
2019
{

contexts/Authorization/Domain/UserIdentity/Models/UserIdentity.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use Contexts\Authorization\Domain\UserIdentity\Events\PasswordChangedEvent;
1010
use Contexts\Authorization\Domain\UserIdentity\Events\RoleAssignedEvent;
1111
use Contexts\Authorization\Domain\UserIdentity\Events\RoleRemovedEvent;
12-
use Contexts\Shared\Domain\BaseDomainModel;
1312
use Contexts\Authorization\Domain\UserIdentity\Events\UserAuthenticatedEvent;
1413
use Contexts\Authorization\Domain\UserIdentity\Exceptions\AuthenticationFailureException;
14+
use Contexts\Shared\Domain\BaseDomainModel;
1515

1616
class UserIdentity extends BaseDomainModel
1717
{
@@ -27,7 +27,7 @@ private function __construct(
2727
private ?CarbonImmutable $updated_at = null
2828
) {
2929
$this->created_at = $created_at ?? CarbonImmutable::now();
30-
$this->roleIdCollection = new RoleIdCollection();
30+
$this->roleIdCollection = new RoleIdCollection;
3131
}
3232

3333
public function hasAnyRole(RoleIdCollection $roleIds): bool
@@ -113,7 +113,7 @@ public static function reconstitute(
113113
array $events = []
114114
): self {
115115
$user = new self($id, $email, $password, $display_name, $status, $created_at, $updated_at);
116-
$user->roleIdCollection = $roleIdCollection ?? new RoleIdCollection();
116+
$user->roleIdCollection = $roleIdCollection ?? new RoleIdCollection;
117117

118118
foreach ($events as $event) {
119119
$user->recordEvent($event);

contexts/Authorization/Infrastructure/Persistence/UserPersistence.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Contexts\Authorization\Infrastructure\Persistence;
66

77
use Contexts\Authorization\Domain\Repositories\UserRepository;
8+
use Contexts\Authorization\Domain\UserIdentity\Exceptions\AuthenticationFailureException;
89
use Contexts\Authorization\Domain\UserIdentity\Exceptions\UserNotFoundException;
910
use Contexts\Authorization\Domain\UserIdentity\Models\RoleIdCollection;
1011
use Contexts\Authorization\Domain\UserIdentity\Models\UserId;
@@ -13,7 +14,6 @@
1314
use Contexts\Authorization\Infrastructure\Records\UserRecord;
1415
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
1516
use Illuminate\Database\Eloquent\ModelNotFoundException;
16-
use Contexts\Authorization\Domain\UserIdentity\Exceptions\AuthenticationFailureException;
1717

1818
class UserPersistence implements UserRepository
1919
{

contexts/Authorization/Infrastructure/Records/UserRecord.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
use Illuminate\Database\Eloquent\Factories\Factory;
1818
use Illuminate\Database\Eloquent\Factories\HasFactory;
1919
use Illuminate\Foundation\Auth\User as Authenticatable;
20+
use Illuminate\Notifications\Notifiable;
2021
use Illuminate\Support\Carbon;
2122
use Laravel\Sanctum\HasApiTokens;
22-
use Illuminate\Notifications\Notifiable;
2323

2424
/**
2525
* @property int $id
@@ -32,8 +32,8 @@
3232
*/
3333
class UserRecord extends Authenticatable
3434
{
35-
use HasFactory;
3635
use HasApiTokens;
36+
use HasFactory;
3737
use Notifiable;
3838

3939
protected $table = 'users';

contexts/Authorization/Presentation/Controllers/AuthenticationController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace Contexts\Authorization\Presentation\Controllers;
66

7-
use Contexts\Shared\Presentation\BaseController;
8-
use Contexts\Authorization\Presentation\Requests\Authentication\LoginRequest;
97
use Contexts\Authorization\Application\Coordinators\AuthenticationCoordinator;
108
use Contexts\Authorization\Application\DTOs\Authentication\LoginDTO;
9+
use Contexts\Authorization\Presentation\Requests\Authentication\LoginRequest;
10+
use Contexts\Shared\Presentation\BaseController;
1111

1212
class AuthenticationController extends BaseController
1313
{

contexts/Authorization/Tests/Feature/Infrastructure/Persistence/UserPersistenceTest.php

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Contexts\Authorization\Domain\Factories\UserIdentityFactory;
66
use Contexts\Authorization\Domain\Role\Models\RoleId;
77
use Contexts\Authorization\Domain\Services\UserEmailUniquenessService;
8+
use Contexts\Authorization\Domain\UserIdentity\Exceptions\AuthenticationFailureException;
89
use Contexts\Authorization\Domain\UserIdentity\Exceptions\UserNotFoundException;
910
use Contexts\Authorization\Domain\UserIdentity\Models\Email;
1011
use Contexts\Authorization\Domain\UserIdentity\Models\Password;
@@ -15,8 +16,6 @@
1516
use Contexts\Authorization\Infrastructure\Persistence\UserPersistence;
1617
use Contexts\Authorization\Infrastructure\Records\RoleRecord;
1718
use Contexts\Authorization\Infrastructure\Records\UserRecord;
18-
use Illuminate\Database\Eloquent\ModelNotFoundException;
19-
use Contexts\Authorization\Domain\UserIdentity\Exceptions\AuthenticationFailureException;
2019

2120
beforeEach(function () {
2221
$this->userLabelUniquenessService = mock(UserEmailUniquenessService::class);
@@ -27,7 +26,7 @@
2726
$email = new Email('test@example.com');
2827
$password = Password::createFromPlainText('password123');
2928
$user = $this->userFactory->create(UserId::null(), $email, $password, 'My User');
30-
$userPersistence = new UserPersistence();
29+
$userPersistence = new UserPersistence;
3130

3231
$userPersistence->create($user);
3332

@@ -43,7 +42,7 @@
4342
$email = new Email('retrieve@example.com');
4443
$password = Password::createFromPlainText('password123');
4544
$createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Test User');
46-
$userPersistence = new UserPersistence();
45+
$userPersistence = new UserPersistence;
4746
$savedUser = $userPersistence->create($createdUser);
4847

4948
// Retrieve the user using getById
@@ -58,7 +57,7 @@
5857
});
5958

6059
it('throws an exception when retrieving a non-existent user', function () {
61-
$userPersistence = new UserPersistence();
60+
$userPersistence = new UserPersistence;
6261

6362
// Attempt to retrieve a non-existent user
6463
$userPersistence->getById(UserId::fromInt(999));
@@ -69,7 +68,7 @@
6968
$email = new Email('original@example.com');
7069
$password = Password::createFromPlainText('password123');
7170
$createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Original DisplayName');
72-
$userPersistence = new UserPersistence();
71+
$userPersistence = new UserPersistence;
7372
$savedUser = $userPersistence->create($createdUser);
7473

7574
// Create an updated version of the user with new email
@@ -102,7 +101,7 @@
102101
});
103102

104103
it('throws an exception when updating a non-existent user', function () {
105-
$userPersistence = new UserPersistence();
104+
$userPersistence = new UserPersistence;
106105
$email = new Email('nonexistent@example.com');
107106
$password = Password::createFromPlainText('password123');
108107

@@ -112,7 +111,7 @@
112111

113112
it('can paginate users', function () {
114113
// Create multiple test users
115-
$userPersistence = new UserPersistence();
114+
$userPersistence = new UserPersistence;
116115

117116
// Create 5 users
118117
for ($i = 1; $i <= 5; $i++) {
@@ -148,7 +147,7 @@
148147
});
149148

150149
it('can filter users with search criteria', function () {
151-
$userPersistence = new UserPersistence();
150+
$userPersistence = new UserPersistence;
152151
$password = Password::createFromPlainText('password123');
153152

154153
// Create users with specific display_names and emails
@@ -223,7 +222,7 @@
223222
$email = new Email('delete@example.com');
224223
$password = Password::createFromPlainText('password123');
225224
$createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Test User');
226-
$userPersistence = new UserPersistence();
225+
$userPersistence = new UserPersistence;
227226
$savedUser = $userPersistence->create($createdUser);
228227

229228
// Delete the user
@@ -237,7 +236,7 @@
237236
});
238237

239238
it('throws an exception when deleting a non-existent user', function () {
240-
$userPersistence = new UserPersistence();
239+
$userPersistence = new UserPersistence;
241240
$email = new Email('nonexistent@example.com');
242241
$password = Password::createFromPlainText('password123');
243242

@@ -250,7 +249,7 @@
250249
$email = new Email('password@example.com');
251250
$password = Password::createFromPlainText('oldpassword123');
252251
$createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Password User');
253-
$userPersistence = new UserPersistence();
252+
$userPersistence = new UserPersistence;
254253
$savedUser = $userPersistence->create($createdUser);
255254

256255
// Change password
@@ -269,7 +268,7 @@
269268
$email = new Email('role-test@example.com');
270269
$password = Password::createFromPlainText('password123');
271270
$createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Role Test User');
272-
$userPersistence = new UserPersistence();
271+
$userPersistence = new UserPersistence;
273272
$savedUser = $userPersistence->create($createdUser);
274273

275274
// Create test roles
@@ -324,7 +323,7 @@
324323
$email = new Email('empty-roles@example.com');
325324
$password = Password::createFromPlainText('password123');
326325
$createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'No Roles User');
327-
$userPersistence = new UserPersistence();
326+
$userPersistence = new UserPersistence;
328327
$savedUser = $userPersistence->create($createdUser);
329328

330329
// Create roles and assign them
@@ -364,7 +363,7 @@
364363
$email = new Email('preserve-roles@example.com');
365364
$password = Password::createFromPlainText('password123');
366365
$createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Preserve Roles User');
367-
$userPersistence = new UserPersistence();
366+
$userPersistence = new UserPersistence;
368367
$savedUser = $userPersistence->create($createdUser);
369368

370369
// Create roles and assign them
@@ -406,7 +405,7 @@
406405
$email = new Email('no-roles@example.com');
407406
$password = Password::createFromPlainText('password123');
408407
$createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'No Initial Roles');
409-
$userPersistence = new UserPersistence();
408+
$userPersistence = new UserPersistence;
410409
$savedUser = $userPersistence->create($createdUser);
411410

412411
// Create a role to assign
@@ -435,7 +434,7 @@
435434
$email = new Email('exists@example.com');
436435
$password = Password::createFromPlainText('password123');
437436
$createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Existing User');
438-
$userPersistence = new UserPersistence();
437+
$userPersistence = new UserPersistence;
439438
$userPersistence->create($createdUser);
440439

441440
// Check if the email exists
@@ -446,7 +445,7 @@
446445
});
447446

448447
it('returns false when no user exists with the given email', function () {
449-
$userPersistence = new UserPersistence();
448+
$userPersistence = new UserPersistence;
450449

451450
// Check for a non-existent email
452451
$result = $userPersistence->existsByEmail('nonexistent@example.com');
@@ -460,7 +459,7 @@
460459
$email = new Email('retrieve-by-email@example.com');
461460
$password = Password::createFromPlainText('password123');
462461
$createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Email User');
463-
$userPersistence = new UserPersistence();
462+
$userPersistence = new UserPersistence;
464463
$savedUser = $userPersistence->create($createdUser);
465464

466465
// Retrieve the user using getByEmail
@@ -474,7 +473,7 @@
474473
});
475474

476475
it('throws an auth failure exception when retrieving a user with non-existent email', function () {
477-
$userPersistence = new UserPersistence();
476+
$userPersistence = new UserPersistence;
478477

479478
// Attempt to retrieve a non-existent user by email
480479
$userPersistence->getByEmailOrThrowAuthFailure('nonexistent-email@example.com');
@@ -485,7 +484,7 @@
485484
$email = new Email('token-user@example.com');
486485
$password = Password::createFromPlainText('password123');
487486
$createdUser = $this->userFactory->create(UserId::null(), $email, $password, 'Token User');
488-
$userPersistence = new UserPersistence();
487+
$userPersistence = new UserPersistence;
489488
$savedUser = $userPersistence->create($createdUser);
490489

491490
// Generate a login token for the user
@@ -505,7 +504,7 @@
505504
});
506505

507506
it('throws an exception when generating a token for a non-existent user', function () {
508-
$userPersistence = new UserPersistence();
507+
$userPersistence = new UserPersistence;
509508
$email = new Email('nonexistent-token@example.com');
510509
$password = Password::createFromPlainText('password123');
511510
$nonExistentUser = $this->userFactory->create(UserId::fromInt(999), $email, $password, 'NonExistent User');

contexts/Authorization/Tests/Unit/Domain/UserIdentity/Models/UserIdentityTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
use Contexts\Authorization\Domain\UserIdentity\Events\PasswordChangedEvent;
1111
use Contexts\Authorization\Domain\UserIdentity\Events\RoleAssignedEvent;
1212
use Contexts\Authorization\Domain\UserIdentity\Events\RoleRemovedEvent;
13+
use Contexts\Authorization\Domain\UserIdentity\Exceptions\AuthenticationFailureException;
1314
use Contexts\Authorization\Domain\UserIdentity\Models\Email;
1415
use Contexts\Authorization\Domain\UserIdentity\Models\Password;
1516
use Contexts\Authorization\Domain\UserIdentity\Models\RoleIdCollection;
1617
use Contexts\Authorization\Domain\UserIdentity\Models\UserId;
1718
use Contexts\Authorization\Domain\UserIdentity\Models\UserIdentity;
1819
use Contexts\Authorization\Domain\UserIdentity\Models\UserStatus;
19-
use Contexts\Authorization\Domain\UserIdentity\Exceptions\AuthenticationFailureException;
2020

2121
beforeEach(function () {
2222
$this->email = new Email('test@example.com');

0 commit comments

Comments
 (0)