Completed
Push — master ( d8c435...68b237 )
by Artem
01:14
created

Canonicalizer::canonicalize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
/*
3
 * This file is part of the StfalconApiBundle.
4
 *
5
 * (c) Stfalcon LLC <stfalcon.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types=1);
12
13
namespace StfalconStudio\ApiBundle\Util\Canonical;
14
15
/**
16
 * Canonicalizer.
17
 */
18
class Canonicalizer
19
{
20
    /** @var EncodingDetector */
21
    private $encodingDetector;
22
23
    /**
24
     * @param EncodingDetector $encodingDetector
25
     */
26
    public function __construct(EncodingDetector $encodingDetector)
27
    {
28
        $this->encodingDetector = $encodingDetector;
29
    }
30
31
    /**
32
     * @param string $string
33
     *
34
     * @return string
35
     */
36
    public function canonicalize(string $string): string
37
    {
38
        $encoding = $this->encodingDetector->detectEncoding($string);
39
40
        if (\is_string($encoding)) {
41
            $result = \mb_convert_case($string, MB_CASE_LOWER, $encoding);
42
        } else {
43
            $result = \mb_convert_case($string, MB_CASE_LOWER);
44
        }
45
46
        return $result;
47
    }
48
}
49