2022-07-29 10:51:20 +00:00
|
|
|
<?php
|
|
|
|
|
2023-08-20 15:24:56 +00:00
|
|
|
namespace App\Values;
|
2022-07-29 10:51:20 +00:00
|
|
|
|
2024-04-18 12:01:21 +00:00
|
|
|
use App\Enums\ScanResultType;
|
2022-07-29 10:51:20 +00:00
|
|
|
|
2024-01-04 21:51:32 +00:00
|
|
|
final class ScanResult
|
2022-07-29 10:51:20 +00:00
|
|
|
{
|
2024-04-18 12:01:21 +00:00
|
|
|
private function __construct(
|
|
|
|
public string $path,
|
2024-04-18 14:36:28 +00:00
|
|
|
public ScanResultType $type,
|
2024-04-18 12:01:21 +00:00
|
|
|
public ?string $error = null
|
|
|
|
) {
|
2022-07-29 10:51:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function success(string $path): self
|
|
|
|
{
|
2024-04-18 12:01:21 +00:00
|
|
|
return new self($path, ScanResultType::SUCCESS, null);
|
2022-07-29 10:51:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function skipped(string $path): self
|
|
|
|
{
|
2024-04-18 12:01:21 +00:00
|
|
|
return new self($path, ScanResultType::SKIPPED, null);
|
2022-07-29 10:51:20 +00:00
|
|
|
}
|
|
|
|
|
2023-12-25 17:15:49 +00:00
|
|
|
public static function error(string $path, ?string $error = null): self
|
2022-07-29 10:51:20 +00:00
|
|
|
{
|
2024-04-18 12:01:21 +00:00
|
|
|
return new self($path, ScanResultType::ERROR, $error);
|
2022-07-29 10:51:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isSuccess(): bool
|
|
|
|
{
|
2024-04-18 12:01:21 +00:00
|
|
|
return $this->type === ScanResultType::SUCCESS;
|
2022-07-29 10:51:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isSkipped(): bool
|
|
|
|
{
|
2024-04-18 12:01:21 +00:00
|
|
|
return $this->type === ScanResultType::SKIPPED;
|
2022-07-29 10:51:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isError(): bool
|
|
|
|
{
|
2024-04-18 12:01:21 +00:00
|
|
|
return $this->type === ScanResultType::ERROR;
|
2022-07-29 10:51:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function isValid(): bool
|
|
|
|
{
|
|
|
|
return $this->isSuccess() || $this->isSkipped();
|
|
|
|
}
|
2023-12-25 17:15:49 +00:00
|
|
|
|
|
|
|
public function __toString(): string
|
|
|
|
{
|
2024-04-18 12:01:21 +00:00
|
|
|
$name = $this->type->value . ': ' . $this->path;
|
2023-12-25 17:15:49 +00:00
|
|
|
|
2024-04-18 12:01:21 +00:00
|
|
|
return $this->isError() ? $name . ' - ' . $this->error : $name;
|
2023-12-25 17:15:49 +00:00
|
|
|
}
|
2022-07-29 10:51:20 +00:00
|
|
|
}
|