Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| Ip | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| __construct | n/a |
0 / 0 |
n/a |
0 / 0 |
1 | |||||
| isValid | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isValidIpv6 | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isValidIpv4 | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Jingga |
| 4 | * |
| 5 | * PHP Version 8.1 |
| 6 | * |
| 7 | * @package phpOMS\Validation\Network |
| 8 | * @copyright Dennis Eichhorn |
| 9 | * @license OMS License 2.0 |
| 10 | * @version 1.0.0 |
| 11 | * @link https://jingga.app |
| 12 | */ |
| 13 | declare(strict_types=1); |
| 14 | |
| 15 | namespace phpOMS\Validation\Network; |
| 16 | |
| 17 | use phpOMS\Validation\ValidatorAbstract; |
| 18 | |
| 19 | /** |
| 20 | * Validate IP. |
| 21 | * |
| 22 | * @package phpOMS\Validation\Network |
| 23 | * @license OMS License 2.0 |
| 24 | * @link https://jingga.app |
| 25 | * @since 1.0.0 |
| 26 | */ |
| 27 | abstract class Ip extends ValidatorAbstract |
| 28 | { |
| 29 | /** |
| 30 | * Constructor. |
| 31 | * |
| 32 | * @since 1.0.0 |
| 33 | * @codeCoverageIgnore |
| 34 | */ |
| 35 | private function __construct() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * {@inheritdoc} |
| 41 | */ |
| 42 | public static function isValid(mixed $value, array $constraints = null) : bool |
| 43 | { |
| 44 | return \filter_var($value, \FILTER_VALIDATE_IP) !== false; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Validate IPv6 |
| 49 | * |
| 50 | * @param mixed $value to validate |
| 51 | * |
| 52 | * @return bool Returns true if value is valid ip6 otherwise false |
| 53 | * |
| 54 | * @since 1.0.0 |
| 55 | */ |
| 56 | public static function isValidIpv6(mixed $value) : bool |
| 57 | { |
| 58 | return \filter_var($value, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6) !== false; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Validate IPv4 |
| 63 | * |
| 64 | * @param mixed $value to validate |
| 65 | * |
| 66 | * @return bool eturns true if value is valid ip4 otherwise false |
| 67 | * |
| 68 | * @since 1.0.0 |
| 69 | */ |
| 70 | public static function isValidIpv4(mixed $value) : bool |
| 71 | { |
| 72 | return \filter_var($value, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4) !== false; |
| 73 | } |
| 74 | } |