1 | <?php |
||
3 | trait Misc { |
||
4 | |||
5 | /** |
||
6 | * Convert ISO 3166-1 alpha-2 code to (English) country name. |
||
7 | * |
||
8 | * @link https://gist.github.com/IngmarBoddington/5909709 Source |
||
9 | * |
||
10 | * @param string $key ISO 3166-1 alpha-2 code |
||
11 | * @return string Country name OR $key if no match. |
||
12 | */ |
||
13 | public static function iso3166ToName($key) { |
||
19 | |||
20 | /** |
||
21 | * Get client ip-address |
||
22 | * |
||
23 | * @return string User ip-address |
||
24 | */ |
||
25 | public static function getClientIpAddress() { |
||
42 | |||
43 | /** |
||
44 | * Tries to auto-correct parse_url()-output. |
||
45 | * |
||
46 | * @param string $url |
||
47 | * @return string[]|false |
||
48 | */ |
||
|
|||
49 | |||
50 | private static function autoCorrectParseUrl($url) { |
||
66 | |||
67 | /** |
||
68 | * parse url, try to correct errors and return valid url + display-url. |
||
69 | * |
||
70 | * @example http:/wwww.example.com/lorum.html => http://www.example.com/lorum.html |
||
71 | * @example gopher:/ww.example.com => gopher://www.example.com |
||
72 | * @example http:/www3.example.com/?q=asd&f=#asd =>http://www3.example.com/?q=asd&f=#asd |
||
73 | * @example asd://.example.com/folder/folder/ =>http://example.com/folder/folder/ |
||
74 | * @example .example.com/ => http://example.com/ |
||
75 | * @example example.com =>http://example.com |
||
76 | * @example subdomain.example.com => http://subdomain.example.com |
||
77 | * |
||
78 | * @param string $url Any somewhat valid url. |
||
79 | * @return string[] "url" contains an auto-corrected url. "url_display" host.tld or subdomain.host.tld |
||
80 | */ |
||
81 | public static function urlParser($url) { |
||
136 | |||
137 | /** |
||
138 | * Generate a password-suggestion. |
||
139 | * |
||
140 | * @param int $length Length of password |
||
141 | * @param string $passwordType "simple" limit character-set to first 33 characters. "long" uses 64 characters. |
||
142 | * @return string |
||
143 | */ |
||
144 | public static function generatePassword($length = 8, $passwordType = "long") { |
||
169 | |||
170 | } |
||
171 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.