IpConverter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
c 2
b 1
f 0
lcom 0
cbo 0
dl 0
loc 22
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromIpToHex() 0 9 2
A fromHexToIp() 0 9 2
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2015 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace SpomkyLabs\IpFilterBundle\Tool;
13
14
class IpConverter
15
{
16
    public static function fromIpToHex($ip)
17
    {
18
        $hex = bin2hex(inet_pton($ip));
19
        if (8 === strlen($hex)) {
20
            $hex = str_pad($hex, 32, '0', STR_PAD_LEFT);
21
        }
22
23
        return $hex;
24
    }
25
26
    public static function fromHexToIp($ip)
27
    {
28
        $hex = pack('H*', $ip);
29
        if (str_repeat('0', 24) === substr($hex, 0, 24)) {
30
            $hex = substr($hex, 24);
31
        }
32
33
        return inet_ntop($hex);
34
    }
35
}
36