Passed
Pull Request — v3 (#729)
by
unknown
38:39 queued 03:37
created

WithStringHelpers::utf8ToIso()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace GameQ\Concerns;
4
5
/**
6
 * This Trait provides simple helpers concerned with handling strings.
7
 */
8
trait WithStringHelpers
9
{
10
    /**
11
     * This helper method re-encodes an ISO 8859-1 string to UTF-8.
12
     *
13
     * @see https://en.wikipedia.org/wiki/ISO/IEC_8859-1
14
     * @see https://en.wikipedia.org/wiki/UTF-8
15
     *
16
     * @param string $value The ISO 8859-1 encoded string.
17
     * @return string The UTF-8 encoded string.
18
     */
19
    protected static function isoToUtf8(string $value)
20
    {
21
        return iconv('ISO-8859-1', 'UTF-8', $value);
22
    }
23
24
    /**
25
     * This helper method re-encodes an UTF-8 string to ISO 8859-1.
26
     *
27
     * @see https://en.wikipedia.org/wiki/ISO/IEC_8859-1
28
     * @see https://en.wikipedia.org/wiki/UTF-8
29
     *
30
     * @param string $value The UTF-8 encoded string.
31
     * @return string  The ISO 8859-1 encoded string.
32
     */
33
    protected static function utf8ToIso(string $value)
34
    {
35
        return iconv('UTF-8', 'ISO-8859-1', $value);
36
    }
37
}
38