Tuple   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 8
Bugs 3 Features 1
Metric Value
wmc 8
c 8
b 3
f 1
lcom 0
cbo 3
dl 0
loc 47
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 3
A binary() 0 17 4
A parse() 0 3 1
1
<?php
2
namespace Cassandra\Type;
3
4
class Tuple extends Base{
5
6
    /**
7
     * @param array $value
8
     * @param array $definition
9
     * @throws Exception
10
     */
11
    public function __construct($value, array $definition){
12
        $this->_definition = $definition;
13
        
14
        if ($value === null)
15
            return;
16
        
17
        if (!is_array($value))
18
            throw new Exception('Incoming value must be type of array.');
19
20
        $this->_value = $value;
21
    }
22
23
    public static function binary($value, array $definition){
24
        $binary = '';
25
        foreach ($definition as $key => $type) {
26
            if ($value[$key] === null) {
27
                $binary .= "\xff\xff\xff\xff";
28
            }
29
            else {
30
                $valueBinary = $value[$key] instanceof Base
31
                    ? $value[$key]->getBinary()
32
                    : Base::getBinaryByType($type, $value[$key]);
33
                
34
                $binary .= pack('N', strlen($valueBinary)) . $valueBinary;
35
            }
36
        }
37
        
38
        return $binary;
39
    }
40
    
41
    /**
42
     * 
43
     * @param string $binary
44
     * @param array $definition
45
     * @return array
46
     */
47
    public static function parse($binary, array $definition){
48
        return (new \Cassandra\Response\StreamReader($binary))->readTuple($definition);
49
    }
50
}
51