Test Failed
Push — master ( c7e2fa...ce0f3f )
by Chris
33:47
created

CallbackDataFormatter::passThrough()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebTheory\Saveyour\Formatting;
4
5
use WebTheory\Saveyour\Contracts\Formatting\DataFormatterInterface;
6
7
class CallbackDataFormatter implements DataFormatterInterface
8
{
9
    /**
10
     * @var callable
11
     */
12
    protected $dataCallback;
13
14
    /**
15
     * @var callable
16
     */
17
    protected $inputCallback;
18
19
    public function __construct(callable $dataCallback = null, callable $inputCallback = null)
20
    {
21
        $this->dataCallback = $dataCallback ?? [$this, 'passThrough'];
22
        $this->inputCallback = $inputCallback ?? [$this, 'passThrough'];
23
    }
24
25
    public function formatData($value)
26
    {
27
        return ($this->dataCallback)($value);
28
    }
29
30
    public function formatInput($value)
31
    {
32
        return ($this->dataCallback)($value);
33
    }
34
35
    protected function passThrough($value)
36
    {
37
        return $value;
38
    }
39
}
40