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
|
|||
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 |
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.