CallbackValueParser   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 2
cbo 0
dl 0
loc 39
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A parseValue() 0 4 1
A canParseValue() 0 4 1
1
<?php
2
/**
3
 * This file is part of graze/csv-token
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/csv-token/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/csv-token
12
 */
13
14
namespace Graze\CsvToken\ValueParser;
15
16
class CallbackValueParser implements ValueParserInterface
17
{
18
    /** @var callable */
19
    private $canParse;
20
    /** @var callable */
21
    private $parse;
22
23
    /**
24
     * CallbackValueParser constructor.
25
     *
26
     * @param callable $canParse
27
     * @param callable $parse
28
     */
29 2
    public function __construct(callable $canParse, callable $parse)
30
    {
31 2
        $this->canParse = $canParse;
32 2
        $this->parse = $parse;
33 2
    }
34
35
    /**
36
     * @param string $string
37
     *
38
     * @return mixed
39
     */
40 1
    public function parseValue($string)
41
    {
42 1
        return call_user_func($this->parse, $string);
43
    }
44
45
    /**
46
     * @param string $string
47
     *
48
     * @return bool
49
     */
50 1
    public function canParseValue($string)
51
    {
52 1
        return call_user_func($this->canParse, $string);
53
    }
54
}
55