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

PayMethods   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 61
ccs 16
cts 16
cp 1
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createString() 0 4 1
A getValue() 0 3 1
A __construct() 0 4 1
A addMethod() 0 5 1
A __toString() 0 3 1
A getParamName() 0 3 1
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