MapStep::apply()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\X501\StringPrep;
6
7
/**
8
 * Implements 'Map' step of the Internationalized String Preparation
9
 * as specified by RFC 4518.
10
 *
11
 * @see https://tools.ietf.org/html/rfc4518#section-2.2
12
 */
13
class MapStep implements PrepareStep
14
{
15
    /**
16
     * Whether to apply case folding.
17
     *
18
     * @var bool
19
     */
20
    protected $_fold;
21
22
    /**
23
     * Constructor.
24
     *
25
     * @param bool $fold_case Whether to apply case folding
26
     */
27 38
    public function __construct(bool $fold_case = false)
28
    {
29 38
        $this->_fold = $fold_case;
30 38
    }
31
32
    /**
33
     * @param string $string UTF-8 encoded string
34
     *
35
     * @return string
36
     */
37 37
    public function apply(string $string): string
38
    {
39
        // @todo Implement character mappings
40 37
        if ($this->_fold) {
41 29
            $string = mb_convert_case($string, MB_CASE_LOWER, 'UTF-8');
42
        }
43 37
        return $string;
44
    }
45
}
46