Completed
Push — master ( a6c946...0fff30 )
by Dmytro
02:08
created

JsonApiExceptionThrower::operatorIsNotDefined()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Paymaxi\Component\Query\Exception\Adapter;
6
7
use Neomerx\JsonApi\Document\Error;
8
use Neomerx\JsonApi\Exceptions\JsonApiException;
9
use Paymaxi\Component\Query\Exception\QueryExceptionThrowerInterface;
10
use Ramsey\Uuid\Uuid;
11
12
/**
13
 * Class JsonApiExceptionThrower
14
 *
15
 * @package Paymaxi\Component\Query\Exception
16
 */
17
final class JsonApiExceptionThrower implements QueryExceptionThrowerInterface
18
{
19
20
    /**
21
     * @param string $key
22
     *
23
     * @throws \Exception
24
     */
25 16
    public function invalidValueForKey(string $key): void
26
    {
27 16
        $this->throwException(sprintf('Invalid value provided for key `%s`.', $key));
28
    }
29
30
    /**
31
     * @param string $message
32
     *
33
     * @throws \Exception
34
     */
35 16
    private function throwException(string $message): void
36
    {
37 16
        $uuid = Uuid::getFactory()->uuid4()->toString();
38
39 16
        $error = new Error(
40 16
            $uuid,
41 16
            null,
42 16
            'error',
43 16
            '400',
44 16
            $message
45
        );
46
47 16
        throw new JsonApiException($error);
48
    }
49
50
    /**
51
     * @param string $operator
52
     *
53
     * @throws \Exception
54
     */
55
    public function operatorIsNotDefined(string $operator): void
56
    {
57
        $this->throwException(sprintf('Operator `%s` does not defined.', $operator));
58
    }
59
60
    /**
61
     * @param string $operator
62
     *
63
     * @throws \Exception
64
     */
65
    public function invalidValueForOperator(string $operator): void
66
    {
67
        $this->throwException(sprintf('Invalid value provided for operator `%s`.', $operator));
68
    }
69
70
    /**
71
     * @param string $field
72
     * @param string $expectedType
73
     *
74
     * @throws \Throwable
75
     */
76
    public function invalidValueForField(string $field, string $expectedType): void
77
    {
78
        $this->throwException(
79
            sprintf('Invalid value provided for field `%s`. Expected %s type.', $field, $expectedType)
80
        );
81
    }
82
}
83