Completed
Push — master ( 29e67b...7f2aa4 )
by David
14s
created

ServiceException::unknownEnvVariableType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
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
    /**
12
     * @param ValidationError $vError
13
     * @return ServiceException
14
     */
15
    public static function invalidServiceData(ValidationError $vError): ServiceException
16
    {
17
        $message = 'Invalid service data' . PHP_EOL
18
            . 'Error of type ' . $vError->keyword() . ' at ' . implode('->', $vError->dataPointer()) . PHP_EOL
19
            . json_encode($vError->keywordArgs(), JSON_PRETTY_PRINT);
20
        return new self($message);
21
    }
22
23
    /**
24
     * @param string $volumeType
25
     * @return ServiceException
26
     */
27
    public static function unknownVolumeType(string $volumeType): ServiceException
28
    {
29
        $message = 'Unknown service volume type: ' . $volumeType . PHP_EOL
30
            . 'Expected: ' . json_encode(VolumeTypeEnum::getVolumeTypes());
31
        return new self($message);
32
    }
33
34
    /**
35
     * @param string $type
36
     * @return ServiceException
37
     */
38
    public static function unknownEnvVariableType(string $type): ServiceException
39
    {
40
        $message = 'Unknown environment variable type: ' . $type . PHP_EOL
41
            . 'Expected: ' . json_encode(EnvVariableTypeEnum::getEnvVariableTypes());
42
        return new self($message);
43
    }
44
}
45