MapStep   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 31
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A apply() 0 7 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