Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
4 / 4
IpRule
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
4 / 4
 validateIp
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
4 / 4
1<?php
2
3namespace Qmp\Laravel\Geolocation\Services\Validations\Rules;
4
5class IpRule extends AbstractRule
6{
7
8    protected $methods = ['ip'];
9
10
11    /**
12     *  Check if ip is valid
13     *
14     * @param $ip
15     */
16    protected function validateIp($ip)
17    {
18        if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)
19            && !filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE)
20        ) {
21            $this->errors[] = 'Invalid ip format : ' . $ip . '.';
22        }
23    }
24
25}