Completed
Pull Request — master (#210)
by ignace nyamagana
06:59
created

CallableAdapter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
* This file is part of the League.csv library
4
*
5
* @license http://opensource.org/licenses/MIT
6
* @link https://github.com/thephpleague/csv/
7
* @version 9.0.0
8
* @package League.csv
9
*
10
* For the full copyright and license information, please view the LICENSE
11
* file that was distributed with this source code.
12
*/
13
declare(strict_types=1);
14
15
namespace League\Csv\Plugin;
16
17
use League\Csv\RecordFormatterInterface;
18
use League\Csv\RecordValidatorInterface;
19
20
/**
21
 * An Adapter Class to convert a callable into
22
 * - an ValidatorInterface implementing object
23
 * - an FormatterInterface implementing object
24
 *
25
 * @package League.csv
26
 * @since   9.0.0
27
 * @author  Ignace Nyamagana Butera <[email protected]>
28
 */
29
class CallableAdapter implements RecordValidatorInterface, RecordFormatterInterface
30
{
31
    /**
32
     * @var callable
33
     */
34
    protected $callable;
35
36
    /**
37
     * New instance
38
     *
39
     * @param callable $callable
40
     */
41 4
    public function __construct(callable $callable)
42
    {
43 4
        $this->callable = $callable;
44 4
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49 2
    public function format(array $row): array
50
    {
51 2
        return ($this->callable)($row);
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57 2
    public function validate(array $row): bool
58
    {
59 2
        return ($this->callable)($row);
60
    }
61
}
62