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

ServiceException   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A unknownEnvVariableType() 0 5 1
A invalidServiceData() 0 6 1
A unknownVolumeType() 0 5 1
A jsonSchemaNotFound() 0 3 1
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