Passed
Push — master ( cdf6da...080a74 )
by Christopher
02:01
created

Validator::endsWithTld()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Arubacao\TldChecker;
4
5
class Validator
6
{
7
    /**
8
     * Checks if value is valid tld.
9
     *
10
     * @param  mixed $value
11
     * @return bool
12
     */
13
    public static function isTld($value)
14
    {
15
        $value = ltrim($value, '.');
16
        $value = idn_to_ascii($value);
0 ignored issues
show
Bug introduced by
The function idn_to_ascii was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

16
        $value = /** @scrutinizer ignore-call */ idn_to_ascii($value);
Loading history...
17
        $value = strtoupper($value);
18
19
        if (in_array($value, RootZoneDatabase::TLDS)) {
20
            return true;
21
        }
22
23
        return false;
24
    }
25
26
    /**
27
     * Checks if value is valid tld.
28
     *
29
     * @param  mixed $value
30
     * @return bool
31
     */
32
    public static function endsWithTld($value)
33
    {
34
        $parts = explode('.', $value);
35
        $end = end($parts);
36
37
        return self::isTld($end);
38
    }
39
}
40