Files
my-projects-website/app/application/app/ServiceResults/ServiceResultError.php
Leonid Nikitin b7d0a2453e Moved from "app/src" to "app/application".
Otherwise phpstorm doesn't understand the paths correctly. He thinks that this is not a complete application, but a package. And when creating a class, the namespace indicates “app” with a small letter, but should be “App”.
2024-04-11 19:52:37 +05:00

50 lines
1008 B
PHP

<?php
declare(strict_types=1);
namespace App\ServiceResults;
use App\Contracts\ServiceResultError as ServiceResultErrorContract;
final class ServiceResultError extends ServiceResult implements ServiceResultErrorContract
{
public function __construct(
private readonly string $message,
private readonly array $errors = [],
private readonly ?int $code = null,
) {
}
public function getMessage(): string
{
return $this->message;
}
public function getCode(): ?int
{
return $this->code;
}
public function getErrors(): array
{
return $this->errors;
}
public function getErrorsOrMessage(): array|string
{
if (!empty($this->getErrors())) {
return $this->getErrors();
}
return $this->getMessage();
}
public function getData(): array
{
return [
'message' => $this->getMessage(),
'errors' => $this->errors
];
}
}