IpValidator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 19
ccs 7
cts 7
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A validateIpInput() 0 10 4
1
<?php
2
3
namespace Bashar\WeatherModel;
4
5
use Anax\Commons\ContainerInjectableInterface;
6
use Anax\Commons\ContainerInjectableTrait;
7
8
/**
9
 * A sample controller to show how a controller class can be implemented.
10
 * The controller will be injected with $di if implementing the interface
11
 * ContainerInjectableInterface, like this sample class does.
12
 * The controller is mounted on a particular route and can then handle all
13
 * requests for that mount point.
14
 *
15
 * @SuppressWarnings(PHPMD.TooManyPublicMethods)
16
 */
17
class IpValidator implements ContainerInjectableInterface
18
{
19
    use ContainerInjectableTrait;
20
21
    /**
22
     * Check if IP is valid or not.
23
     * GET  domain
24
     *
25
     */
26 5
    public function validateIpInput($enteredIp)
27
    {
28 5
        if (filter_var($enteredIp, FILTER_VALIDATE_IP)) {
29 1
            if (filter_var($enteredIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
30 1
                return true;
31 1
            } elseif (filter_var($enteredIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6)) {
32 1
                return false;
33
            }
34
        }
35 4
        return false;
36
    }
37
}
38