Completed
Pull Request — master (#210)
by ignace nyamagana
02:08
created

CallableFormatterAdapter::format()   A

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 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
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 as RecordFormatter;
18
19
/**
20
 * An Adapter Class to convert a callable
21
 * into a FormatterInterface implementing object
22
 *
23
 * @package League.csv
24
 * @since   9.0.0
25
 * @author  Ignace Nyamagana Butera <[email protected]>
26
 */
27
class CallableFormatterAdapter implements RecordFormatter
28
{
29
    /**
30
     * @var callable
31
     */
32
    protected $callable;
33
34
    /**
35
     * New instance
36
     *
37
     * @param callable $callable
38
     */
39 2
    public function __construct(callable $callable)
40
    {
41 2
        $this->callable = $callable;
42 2
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47 2
    public function format(array $record): array
48
    {
49 2
        return ($this->callable)($record);
50
    }
51
}
52