Passed
Push — master ( 99d0e8...9e7049 )
by Ondra
03:35
created

PayMethods::getValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
/**
4
 * This file is part of the Pixidos package.
5
 *
6
 *  (c) Ondra Votava <[email protected]>
7
 *
8
 *  For the full copyright and license information, please view the LICENSE
9
 *  file that was distributed with this source code.
10
 *
11
 */
12
13
declare(strict_types=1);
14
15
namespace Pixidos\GPWebPay\Param;
16
17
use Pixidos\GPWebPay\Enum\Param;
18
use Pixidos\GPWebPay\Enum\PayMethod as PayMethodEnum;
19
20
class PayMethods implements IParam
21
{
22
    /**
23
     * @var array<PayMethodEnum>
24
     */
25
    private array $methods;
26
    /**
27
     * @var string
28
     */
29
    private string $string;
30
31
32
    /**
33
     * PayMethods constructor.
34
     *
35
     * @param PayMethodEnum ...$methods
36
     */
37 8
    public function __construct(PayMethodEnum ...$methods)
38
    {
39 8
        $this->methods = array_unique($methods);
40 8
        $this->createString();
41
    }
42
43
    /**
44
     * @return string
45
     */
46 8
    public function __toString(): string
47
    {
48 8
        return $this->string;
49
    }
50
51
    /**
52
     * @return string
53
     */
54 6
    public function getParamName(): string
55
    {
56 6
        return Param::PAYMETHODS;
57
    }
58
59
    /**
60
     * @return array<PayMethodEnum>
61
     */
62 3
    public function getValue(): array
63
    {
64 3
        return $this->methods;
65
    }
66
67
    /**
68
     * @param PayMethodEnum $method
69
     */
70 1
    public function addMethod(PayMethodEnum $method): void
71
    {
72 1
        $this->methods[] = $method;
73 1
        $this->methods = array_unique($this->methods);
74 1
        $this->createString();
75
    }
76
77 8
    private function createString(): void
78
    {
79 8
        $string = implode(',', $this->methods);
80 8
        $this->string = $string;
81
    }
82
}
83