SharedStringsTable::getData()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 12
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
1
<?php
2
3
namespace Xls\Record;
4
5
use Xls\SharedStringsTable as SST;
6
7
class SharedStringsTable extends AbstractRecord
8
{
9
    const NAME = 'SST';
10
    const ID = 0x00fc;
11
12
    /**
13
     * Write all of the workbooks strings into an indexed array.
14
     *
15
     * The Excel documentation says that the SST record should be followed by an
16
     * EXTSST record. The EXTSST record is a hash table that is used to optimise
17
     * access to SST. However, despite the documentation it doesn't seem to be
18
     * required so we will ignore it.
19
     *
20
     * @param SST $sst
21
     * @return string
22
     */
23
    public function getData(SST $sst)
24
    {
25
        $data = pack("VV", $sst->getTotalCount(), $sst->getUniqueCount());
26
27
        $length = strlen($data);
28
        $blockSizes = $sst->getBlocksSizes();
29
        if (!empty($blockSizes)) {
30
            $length += array_shift($blockSizes);
31
        }
32
33
        return $this->getHeader($length) . $data;
34
    }
35
}
36