Colinfo   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B getData() 0 30 3
1
<?php
2
3
namespace Xls\Record;
4
5
class Colinfo extends AbstractRecord
6
{
7
    const NAME = 'COLINFO';
8
    const ID = 0x7D;
9
10
    /**
11
     * Generate the COLINFO biff record to define column widths
12
     *
13
     * @param array $colInfo This is the only parameter received and is composed of the following:
14
     *                0 => First formatted column,
15
     *                1 => Last formatted column,
16
     *                2 => Col width (8.43 is Excel default),
17
     *                3 => The optional XF format of the column,
18
     *                4 => Option flags.
19
     *                5 => Optional outline level
20
     *
21
     * @return string
22
     */
23
    public function getData($colInfo)
24
    {
25
        $colFirst = (isset($colInfo['col'])) ? $colInfo['col'] : 0;
26
        $colLast = (isset($colInfo['col2'])) ? $colInfo['col2'] : 0;
27
28
        $format = $colInfo['format'];
29
        $grbit = $colInfo['hidden'];
30
        $level = $colInfo['level'];
31
32
        $coldx = $colInfo['width'];
33
        $coldx += 0.72; // Fudge. Excel subtracts 0.72 !?
34
        $coldx *= 256; // Convert to units of 1/256 of a char
35
36
        $reserved = 0x00; // Reserved
37
38
        $level = max(0, min($level, 7));
39
        $grbit |= $level << 8;
40
41
        $data = pack(
42
            "vvvvvC",
43
            $colFirst,
44
            $colLast,
45
            $coldx,
46
            $this->xf($format),
47
            $grbit,
48
            $reserved
49
        );
50
51
        return $this->getFullRecord($data);
52
    }
53
}
54