IpValidator::validateIpInput()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 10
ccs 7
cts 7
cp 1
crap 4
rs 10
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