Completed
Pull Request — master (#36)
by Jindun
03:06
created

ServiceException::jsonSchemaNotFound()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TheAentMachine\Service\Exception;
4
5
use Opis\JsonSchema\ValidationError;
6
use TheAentMachine\Service\Enum\EnvVariableTypeEnum;
7
use TheAentMachine\Service\Enum\VolumeTypeEnum;
8
9
class ServiceException extends \Exception
10
{
11
    public static function invalidServiceData(ValidationError $vError): ServiceException
12
    {
13
        $message = 'Invalid service data' . PHP_EOL
14
            . 'Error of type ' . $vError->keyword() . ' at ' . implode('->', $vError->dataPointer()) . PHP_EOL
15
            . \GuzzleHttp\json_encode($vError->keywordArgs(), JSON_PRETTY_PRINT);
16
        return new self($message);
17
    }
18
19
    public static function jsonSchemaNotFound(string $pathname): ServiceException
20
    {
21
        return new self("The Json Schema used for validate the Service is not found (at $pathname).");
22
    }
23
24
    public static function unknownVolumeType(string $volumeType): ServiceException
25
    {
26
        $message = 'Unknown service volume type: ' . $volumeType . PHP_EOL
27
            . 'Expected: ' . \GuzzleHttp\json_encode(VolumeTypeEnum::getVolumeTypes());
28
        return new self($message);
29
    }
30
31
    public static function unknownEnvVariableType(string $type): ServiceException
32
    {
33
        $message = 'Unknown environment variable type: ' . $type . PHP_EOL
34
            . 'Expected: ' . \GuzzleHttp\json_encode(EnvVariableTypeEnum::getEnvVariableTypes());
35
        return new self($message);
36
    }
37
}
38