Pair::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Seboettg\Collection\Map;
4
5
use function Seboettg\Collection\Assert\assertScalar;
6
7
final class Pair
8
{
9
    /**
10
     * @var bool|float|int|string
11
     */
12
    private $key;
0 ignored issues
show
Coding Style introduced by
Private member variable "key" must contain a leading underscore
Loading history...
13
14
    /**
15
     * @var mixed
16
     */
17
    private $value;
0 ignored issues
show
Coding Style introduced by
Private member variable "value" must contain a leading underscore
Loading history...
18
19
    /**
20
     * @param scalar $key
21
     * @param mixed $value
22
     */
23 55
    public static function factory($key, $value): Pair
24
    {
25 55
        assertScalar($key, "Key must be a scalar.");
26 54
        return new self($key, $value);
27
    }
28
29
    /**
30
     * @param scalar $key
31
     * @param mixed $value
32
     */
33 54
    private function __construct($key, $value)
34
    {
35 54
        $this->key = $key;
36 54
        $this->value = $value;
37 54
    }
38
39
    /**
40
     * @return scalar
41
     */
42 52
    public function getKey()
43
    {
44 52
        return $this->key;
45
    }
46
47
    /**
48
     * @return mixed
49
     */
50 52
    public function getValue()
51
    {
52 52
        return $this->value;
53
    }
54
55
    public function copy($key = null, $value = null): Pair
56
    {
57
        return self::factory(
58
            $key === null ? $this->getKey() : $key,
59
            $value === null ? $this->getValue() : $value
60
        );
61
    }
62
}
63
64