IdColumn::cast()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
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