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

CallbackDataFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 31
ccs 0
cts 6
cp 0
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A formatData() 0 3 1
A passThrough() 0 3 1
A __construct() 0 4 1
A formatInput() 0 3 1
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