Completed
Push — master ( 8da5f1...2589ae )
by Viacheslav
8s
created

IdnHostname::validationError()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 3
nop 1
1
<?php
2
3
namespace Swaggest\JsonSchema\Constraint\Format;
4
5
use Swaggest\JsonSchema\Constraint\Format;
6
7
class IdnHostname
8
{
9
    /**
10
     * @see http://www.unicode.org/faq/idn.html
11
     * @see https://gist.github.com/rxu/0660eef7a2f9e7992db6
12
     * @param string $data
13
     * @return null|string
14
     */
15
    public static function validationError($data)
16
    {
17
        $error = Iri::unicodeValidationError($data, $sanitized);
18
        if ($error !== null) {
19
            return $error;
20
        }
21
        return preg_match(Format::HOSTNAME_REGEX, $sanitized) ? null : 'Invalid idn-hostname: ' . $data;
22
    }
23
}