Completed
Pull Request — master (#16)
by Viacheslav
05:56
created

IdnHostname   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A validationError() 0 8 3
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
}