| Total Complexity | 10 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class EthereumValidator |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Checks if the given string is an address. |
||
| 9 | * |
||
| 10 | * @method isAddress |
||
| 11 | * |
||
| 12 | * @param {String} $address the given HEX adress |
||
|
|
|||
| 13 | * |
||
| 14 | * @return {Boolean} |
||
| 15 | */ |
||
| 16 | public static function isAddress($address) |
||
| 17 | { |
||
| 18 | if (!preg_match('/^(0x)?[0-9a-f]{40}$/i', $address)) { |
||
| 19 | // check if it has the basic requirements of an address |
||
| 20 | return false; |
||
| 21 | } elseif (!preg_match('/^(0x)?[0-9a-f]{40}$/', $address) || preg_match('/^(0x)?[0-9A-F]{40}$/', $address)) { |
||
| 22 | // If it's all small caps or all all caps, return true |
||
| 23 | return true; |
||
| 24 | } else { |
||
| 25 | // Otherwise check each case |
||
| 26 | return self::isChecksumAddress($address); |
||
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Checks if the given string is a checksummed address. |
||
| 32 | * |
||
| 33 | * @method isChecksumAddress |
||
| 34 | * |
||
| 35 | * @param {String} $address the given HEX adress |
||
| 36 | * |
||
| 37 | * @return {Boolean} |
||
| 38 | */ |
||
| 39 | public static function isChecksumAddress($address) |
||
| 55 | } |
||
| 56 | } |
||
| 57 |