Passed
Push — master ( 8e347d...41a5a8 )
by Christopher
02:18
created

src/Validator.php (1 issue)

Labels
Severity
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
     *
12
     * @return bool
13
     */
14
    public static function isTld($value)
15
    {
16
        $value = ltrim($value, '.');
17
        $value = idn_to_ascii($value, 0, INTL_IDNA_VARIANT_UTS46);
0 ignored issues
show
The call to idn_to_ascii() has too few arguments starting with idna_info. ( Ignorable by Annotation )

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

17
        $value = /** @scrutinizer ignore-call */ idn_to_ascii($value, 0, INTL_IDNA_VARIANT_UTS46);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

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