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

CallableAdapter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 33
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A format() 0 4 1
A validate() 0 4 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