Passed
Push — main ( 2bc5a4...5ffc2f )
by Vasil
16:31 queued 13:09
created

Payer::isValid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VasilDakov\Speedy\Service\Shipment;
6
7
use JMS\Serializer\Annotation as Serializer;
8
9
/**
10
 * Class Payer.
11
 *
12
 * @Serializer\AccessType("public_method")
13
 *
14
 * @author Valentin Valkanov <[email protected]>
15
 * @copyright
16
 *
17
 * @version
18
 */
19
class Payer
20
{
21
    /**
22
     * array.
23
     */
24
    public const OPTIONS = [
25
        'SENDER',
26
        'RECIPIENT',
27
        'THIRD_PARTY',
28
    ];
29
30
    /**
31
     * @Serializer\Type("string")
32
     */
33
    private string $value;
34
35 3
    public function __construct(string $value)
36
    {
37 3
        if (! $this->isValid($value)) {
38 1
            throw new \InvalidArgumentException();
39
        }
40 2
        $this->value = $value;
41
    }
42
43 3
    private function isValid(string $value): bool
44
    {
45 3
        if (! \in_array($value, self::OPTIONS, true)) {
46 1
            return false;
47
        }
48 2
        return true;
49
    }
50
51 1
    public function getValue(): string
52
    {
53 1
        return $this->value;
54
    }
55
56 1
    public function __toString(): string
57
    {
58 1
        return $this->getValue();
59
    }
60
}
61