CallbackValueParser::parseValue()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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