Passed
Push — master ( 850720...c3cb09 )
by Andy
01:17
created

Immutable::cloneCall()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Palmtree\Chrono\Traits;
4
5
trait Immutable
6
{
7
    abstract public function createClone();
8
9
    /**
10
     * @param int    $value
11
     * @param string $period
12
     *
13
     * @return self
14
     */
15 1
    public function add(int $value, string $period)
16
    {
17 1
        return $this->cloneCall(__FUNCTION__, \func_get_args());
18
    }
19
20
    /**
21
     * @param int    $value
22
     * @param string $period
23
     *
24
     * @return self
25
     */
26 1
    public function subtract(int $value, string $period)
27
    {
28 1
        return $this->cloneCall(__FUNCTION__, \func_get_args());
29
    }
30
31 3
    protected function cloneCall($method, $params = [])
32
    {
33 3
        $clone = $this->createClone();
34
35
        $closure = function () use ($method, $params) {
36 3
            return parent::$method(...$params);
37 3
        };
38
39 3
        $closure->bindTo($clone)();
40
41 3
        return $clone;
42
    }
43
}
44