refactor(employees): replace native assert with Webmozart\Assert
Updated assertions in FindEmployee, FindAllEmployees, and Output classes to use Webmozart\Assert for better type safety and consistency.
This commit is contained in:
parent
63d4ae17f3
commit
43a568ef5a
4 changed files with 12 additions and 5 deletions
|
|
@ -8,6 +8,7 @@ use Domain\Exceptions\NotFoundException;
|
|||
use Domain\Ports\Directories\EmployeeDirectory;
|
||||
use Shared\DDD\Usecase\Input as BaseInput;
|
||||
use Shared\DDD\Usecase\Usecase;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/** @implements Usecase<\Shared\DDD\Usecase\Input, \Shared\DDD\Usecase\Output> */
|
||||
final readonly class FindEmployee implements Usecase
|
||||
|
|
@ -20,7 +21,7 @@ final readonly class FindEmployee implements Usecase
|
|||
#[\Override]
|
||||
public function execute(BaseInput $input): Output
|
||||
{
|
||||
assert($input instanceof Input);
|
||||
Assert::isInstanceOf($input, Input::class);
|
||||
|
||||
$employee = $this->directory->find($input->id);
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ use Domain\Ports\Directories\EmployeeDirectory;
|
|||
use Shared\DDD\Usecase\Input as BaseInput;
|
||||
use Shared\DDD\Usecase\Usecase;
|
||||
use Shared\Paginated;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
/** @implements Usecase<\Shared\DDD\Usecase\Input, \Shared\DDD\Usecase\Output> */
|
||||
final readonly class FindAllEmployees implements Usecase
|
||||
|
|
@ -21,7 +22,7 @@ final readonly class FindAllEmployees implements Usecase
|
|||
#[\Override]
|
||||
public function execute(BaseInput $input): Output
|
||||
{
|
||||
assert($input instanceof Input);
|
||||
Assert::isInstanceOf($input, Input::class);
|
||||
|
||||
$page = $this->directory->findAll(
|
||||
$input->pagination,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||
namespace Application\Usecase\Employees\FindAll;
|
||||
|
||||
use Shared\DDD\Usecase\Output as UsecaseOutput;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final readonly class Output implements UsecaseOutput
|
||||
{
|
||||
|
|
@ -16,7 +17,7 @@ final readonly class Output implements UsecaseOutput
|
|||
public int $perPage = 10,
|
||||
) {
|
||||
foreach ($this->employees as $employee) {
|
||||
assert($employee instanceof PaginatedEmployee);
|
||||
Assert::isInstanceOf($employee, PaginatedEmployee::class);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,12 @@ declare(strict_types=1);
|
|||
|
||||
describe('Coding Standards & Project Rules', function (): void {
|
||||
arch()->preset()->php();
|
||||
// assert(bool) est intentionnel pour le type narrowing PHPStan, seul assert(string) est dangereux (deprecated PHP 8.3)
|
||||
arch()->preset()->security()->ignoring('assert');
|
||||
// Le helper assert natif est interdit en faveur de Webmozart\Assert
|
||||
arch()->preset()->security();
|
||||
|
||||
arch('assert is not used in src (use Webmozart\Assert instead)')
|
||||
->expect('assert')
|
||||
->not->toBeUsed();
|
||||
|
||||
arch('config() helper is not used in src (use Config facade instead)')
|
||||
->expect('config')
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue