Completed
Pull Request — master (#8)
by Alexander
06:21 queued 03:56
created

polyfill.php ➔ idn_to_utf8()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * TLDExtract: Library for extraction of domain parts e.g. TLD. Domain parser that uses Public Suffix List.
4
 *
5
 * @link      https://github.com/layershifter/TLDExtract
6
 *
7
 * @copyright Copyright (c) 2016, Alexander Fedyashov
8
 * @license   https://raw.githubusercontent.com/layershifter/TLDExtract/master/LICENSE Apache 2.0 License
9
 */
10
11
namespace
12
{
13
    use TrueBV\Punycode;
14
15
    if (!function_exists('idn_to_utf8')) {
16
17
        /**
18
         * Polyfill for idn_to_utf8.
19
         *
20
         * @link http://php.net/manual/de/function.idn-to-utf8.php
21
         *
22
         * @param $domain
23
         *
24
         * @return string
25
         */
26
        function idn_to_utf8($domain)
27
        {
28
            $punyCode = new Punycode();
29
30
            return $punyCode->encode($domain);
31
        }
32
    }
33
34
    if (!function_exists('idn_to_ascii')) {
35
36
        /**
37
         * Polyfill for idn_to_ascii.
38
         *
39
         * @link http://php.net/manual/de/function.idn-to-ascii.php
40
         *
41
         * @param string $domain
42
         *
43
         * @return string
44
         */
45
        function idn_to_ascii($domain)
46
        {
47
            $punyCode = new Punycode();
48
49
            return $punyCode->decode($domain);
50
        }
51
    }
52
}
53