Completed
Push — master ( a3add9...6ca7fe )
by ignace nyamagana
02:56
created

CsvControlTrait::filterControl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 3
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
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;
16
17
use League\Csv\Exception\LengthException;
18
19
/**
20
 *  A trait to validate csv control characters
21
 *
22
 * @package  League.csv
23
 * @since    9.0.0
24
 * @author   Ignace Nyamagana Butera <[email protected]>
25
 * @internal Use to validate incoming data
26
 */
27
trait CsvControlTrait
28
{
29
    /**
30
     * Filter Csv control character
31
     *
32
     * @param string $char   Csv control character
33
     * @param string $type   Csv control character type
34
     * @param string $caller public API method calling the method
35
     *
36
     * @throws LengthException If the Csv control character is not one character only.
37
     *
38
     * @return string
39
     */
40 12
    protected function filterControl(string $char, string $type, string $caller): string
41
    {
42 12
        if (1 == strlen($char)) {
43 12
            return $char;
44
        }
45
46 2
        throw new LengthException(sprintf('%s() expects %s to be a single character %s given', $caller, $type, $char));
47
    }
48
}
49