format backend code

This commit is contained in:
Yisroel Baum 2026-05-25 20:24:59 +03:00
parent 9577367622
commit 67dd376a2f
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
40 changed files with 146 additions and 71 deletions

View file

@ -12,5 +12,6 @@ class CreateSessionDto
public User $user,
public DateTimeImmutable $createdAt,
public DateTimeImmutable $expiresAt,
) {}
) {
}
}

View file

@ -8,7 +8,9 @@ use DateTimeZone;
class EloquentSessionRepository implements SessionRepository
{
public function __construct(private UserRepository $userRepo) {}
public function __construct(private UserRepository $userRepo)
{
}
public function create(CreateSessionDto $dto): Session
{

View file

@ -12,7 +12,8 @@ class Session
private User $user,
private DateTimeImmutable $createdAt,
private DateTimeImmutable $expiresAt,
) {}
) {
}
public function getToken(): string
{

View file

@ -14,7 +14,8 @@ class AuthenticateUser
public function __construct(
private UserRepository $userRepo,
private PasswordHasher $hasher,
) {}
) {
}
/**
* @throws BadRequestException

View file

@ -7,5 +7,6 @@ class AuthenticateUserRequest
public function __construct(
public ?string $email,
public ?string $password,
) {}
) {
}
}

View file

@ -17,7 +17,8 @@ class CreateSession
private SessionRepository $sessionRepo,
private TokenGenerator $tokenGenerator,
private Clock $clock,
) {}
) {
}
public function execute(User $user): Session
{

View file

@ -8,7 +8,8 @@ class Logout
{
public function __construct(
private SessionRepository $sessionRepo,
) {}
) {
}
public function execute(string $token): void
{

View file

@ -20,7 +20,8 @@ class AuthController
private AuthenticateUser $authenticateUser,
private CreateSession $createSession,
private Logout $logout,
) {}
) {
}
public function login(Request $request): JsonResponse
{
@ -33,11 +34,13 @@ class AuthController
);
} catch (BadRequestException $exception) {
return new JsonResponse(
['error' => $exception->getMessage()], 400
['error' => $exception->getMessage()],
400
);
} catch (UnauthorizedException $exception) {
return new JsonResponse(
['error' => $exception->getMessage()], 401
['error' => $exception->getMessage()],
401
);
}
@ -71,7 +74,7 @@ class AuthController
}
/**
* @return array{id: int, email: string, firstname: string, lastname: string}
* @return array{id: int, email: string}
*/
private function buildUserPayload(User $user): array
{

View file

@ -8,7 +8,9 @@ use Illuminate\Http\JsonResponse;
class SetController
{
public function __construct(private SetRepository $setRepository) {}
public function __construct(private SetRepository $setRepository)
{
}
public function index(): JsonResponse
{

View file

@ -10,5 +10,6 @@ class CreateElementDto
public Set $set,
public string $title,
public ?Element $parentElement,
) {}
) {
}
}

View file

@ -11,7 +11,8 @@ class Element
private string $title,
private Set $set,
private ?Element $parentElement,
) {}
) {
}
public function getId(): int
{

View file

@ -8,7 +8,9 @@ use DomainException;
class EloquentElementRepository implements ElementRepository
{
public function __construct(private SetRepository $setRepo) {}
public function __construct(private SetRepository $setRepo)
{
}
public function create(CreateElementDto $dto): Element
{

View file

@ -15,7 +15,8 @@ class CreateElement
public function __construct(
private ElementRepository $elementRepo,
private SetRepository $setRepo,
) {}
) {
}
/**
* @throws BadRequestException

View file

@ -8,5 +8,6 @@ class CreateElementRequest
public ?int $setId,
public ?string $title,
public ?int $parentElementId,
) {}
) {
}
}

View file

@ -4,4 +4,6 @@ namespace App\Exceptions;
use DomainException;
class BadRequestException extends DomainException {}
class BadRequestException extends DomainException
{
}

View file

@ -4,4 +4,6 @@ namespace App\Exceptions;
use DomainException;
class UnauthorizedException extends DomainException {}
class UnauthorizedException extends DomainException
{
}

View file

@ -16,7 +16,8 @@ class AuthMiddleware
public function __construct(
private SessionRepository $sessionRepo,
private Clock $clock,
) {}
) {
}
/**
* @param Closure(Request): Response $next

View file

@ -6,5 +6,6 @@ class CreateSetDto
{
public function __construct(
public string $name,
) {}
) {
}
}

View file

@ -7,7 +7,8 @@ class Set
public function __construct(
private int $id,
private string $name,
) {}
) {
}
public function getId(): int
{

View file

@ -18,15 +18,15 @@ final readonly class EmailAddress
$trimmed = trim($email);
if ($trimmed === '' || ! str_contains($trimmed, '@')) {
throw new InvalidArgumentException(self::ERROR_MESSAGE." $email");
throw new InvalidArgumentException(self::ERROR_MESSAGE . " $email");
}
[$local, $domain] = explode('@', $trimmed, 2);
$this->domain = mb_strtolower($domain);
$normalized = $local.'@'.$this->domain;
$normalized = $local . '@' . $this->domain;
if (filter_var($normalized, FILTER_VALIDATE_EMAIL) === false) {
throw new InvalidArgumentException(self::ERROR_MESSAGE." $email");
throw new InvalidArgumentException(self::ERROR_MESSAGE . " $email");
}
$this->normalized = $normalized;

View file

@ -9,5 +9,6 @@ class CreateUserDto
public function __construct(
public EmailAddress $email,
public string $passwordHash,
) {}
) {
}
}

View file

@ -25,7 +25,7 @@ class EloquentUserRepository implements UserRepository
public function findByEmailDomain(string $domain): array
{
$models = UserModel::where('email', 'like', '%@'.$domain)->get();
$models = UserModel::where('email', 'like', '%@' . $domain)->get();
$users = [];
foreach ($models as $model) {
$users[] = $this->toDomain($model);

View file

@ -10,7 +10,8 @@ class User
private int $id,
private EmailAddress $email,
private string $passwordHash,
) {}
) {
}
public function getId(): int
{

View file

@ -9,12 +9,6 @@ use Illuminate\Database\Eloquent\Model;
* @property string $email
* @property string $password_hash
*
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserModel newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserModel newQuery()
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserModel query()
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserModel whereEmail($value)
* @method static \Illuminate\Database\Eloquent\Builder<static>|UserModel whereId($value)
*
* @mixin \Eloquent
*/
class UserModel extends Model