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

ServiceException   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A invalidServiceData() 0 6 1
A unknownVolumeType() 0 5 1
1
<?php
2
3
namespace TheAentMachine\Service\Exception;
4
5
use Opis\JsonSchema\ValidationError;
6
use TheAentMachine\Service\Enum\VolumeTypeEnum;
7
8
class ServiceException extends \Exception
9
{
10
    /**
11
     * @param ValidationError $vError
12
     * @return ServiceException
13
     */
14
    public static function invalidServiceData(ValidationError $vError): ServiceException
15
    {
16
        $message = 'Invalid service data' . PHP_EOL
17
            . 'Error of type ' . $vError->keyword() . ' at ' . implode('->', $vError->dataPointer()) . PHP_EOL
18
            . json_encode($vError->keywordArgs(), JSON_PRETTY_PRINT);
19
        return new self($message);
20
    }
21
22
    /**
23
     * @param string $volumeType
24
     * @return ServiceException
25
     */
26
    public static function unknownVolumeType(string $volumeType): ServiceException
27
    {
28
        $message = 'Unknown service volume type: ' . $volumeType . PHP_EOL
29
            . 'Expected: ' . json_encode(VolumeTypeEnum::getVolumeTypes());
30
        return new self($message);
31
    }
32
}
33