Completed
Branch FET/asset-manager (433489)
by
unknown
32:42 queued 18:11
created

Windows1252::format()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 15
nc 3
nop 1
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
2
3
namespace EventEspresso\core\services\formatters;
4
5
use EventEspresso\core\exceptions\InvalidDataTypeException;
6
7
/**
8
 * Class Windows1252
9
 * Converts from utf8 encoding to windows 1252 (aka cp1252, aka ISO-8859-1,
10
 * see https://en.wikipedia.org/wiki/Windows-1252).
11
 * This is useful if you need to send a string to a site using windows 1252 character encoding
12
 *
13
 * @package        Event Espresso
14
 * @author         Mike Nelson
15
 * @since          4.9.31.p
16
 */
17
class Windows1252 extends FormatterBase
18
{
19
20
    /**
21
     * Converts the string to windows-1252 encoding.
22
     *
23
     * @param string|int|float $input anything easily cast into a string
24
     * @return string
25
     */
26
    public function format($input)
27
    {
28
        // in case an int or float etc was passed in
29
        $input = (string) $input;
30
        if (function_exists('iconv')) {
31
            $input = iconv('utf-8', 'cp1252//TRANSLIT', $input);
32
        } elseif (WP_DEBUG) {
33
            trigger_error(
34
                sprintf(
35
                // @codingStandardsIgnoreStart
36
                    esc_html__(
37
                        '%1$s could not format the string "%2$s" because the function "%3$s" does not exist. Please verify PHP is installed with this function, see %4$s',
38
                        'event_espresso'
39
                    ),
40
                    // @codingStandardsIgnoreEnd
41
                    get_class($this),
42
                    $input,
43
                    'iconv',
44
                    '<a href="http://php.net/manual/en/iconv.installation.php">http://php.net/manual/en/iconv.installation.php</a>'
45
                )
46
            );
47
        }
48
        return $input;
49
    }
50
}
51