IdColumn   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A cast() 0 11 2
1
<?php
2
3
namespace FForattini\Btrieve\Column;
4
5
use FForattini\Btrieve\Bin;
6
7
class IdColumn extends ColumnRule implements ColumnInterface
8
{
9
    const DEFAULT_LENGTH = 1;
10
11
    public function __construct($title, $length = self::DEFAULT_LENGTH)
12
    {
13
        $this->setTitle($title);
14
        $this->setType(self::TYPE_ID);
15
        $this->setLength($length);
16
    }
17
18
    public static function cast($content)
19
    {
20
        $content = str_split(Bin::toHex($content), 2);
21
22
        $id = 0;
23
        foreach ($content as $power => $value) {
24
            $id += hexdec($value) * pow(256, $power);
25
        }
26
27
        return intval($id);
28
    }
29
}
30