Completed
Pull Request — develop_3.0 (#427)
by Adrien
02:28
created

WorkbookManager   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 56
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMaxRowsPerWorksheet() 0 4 1
A getWorksheetFilePath() 0 5 1
A writeAllFilesToDiskAndZipThem() 0 11 1
1
<?php
2
3
namespace Box\Spout\Writer\ODS\Manager;
4
5
use Box\Spout\Writer\Common\Sheet;
6
use Box\Spout\Writer\Manager\WorkbookManagerAbstract;
7
use Box\Spout\Writer\ODS\Helper\FileSystemHelper;
8
use Box\Spout\Writer\ODS\Helper\StyleHelper;
9
10
/**
11
 * Class WorkbookManager
12
 * ODS workbook manager, providing the interfaces to work with workbook.
13
 *
14
 * @package Box\Spout\Writer\ODS\Manager
15
 */
16
class WorkbookManager extends WorkbookManagerAbstract
17
{
18
    /**
19
     * Maximum number of rows a ODS sheet can contain
20
     * @see https://ask.libreoffice.org/en/question/8631/upper-limit-to-number-of-rows-in-calc/
21
     */
22
    protected static $maxRowsPerWorksheet = 1048576;
23
24
    /** @var WorksheetManager Object used to manage worksheets */
25
    protected $worksheetManager;
26
27
    /** @var FileSystemHelper Helper to perform file system operations */
28
    protected $fileSystemHelper;
29
30
    /** @var StyleHelper Helper to apply styles */
31
    protected $styleHelper;
32
33
    /** @var int Maximum number of columns among all the written rows */
34
    protected $maxNumColumns = 1;
35
36
    /**
37
     * @return int Maximum number of rows/columns a sheet can contain
38
     */
39 31
    protected function getMaxRowsPerWorksheet()
40
    {
41 31
        return self::$maxRowsPerWorksheet;
42
    }
43
44
    /**
45
     * @param Sheet $sheet
46
     * @return string The file path where the data for the given sheet will be stored
47
     */
48 43
    public function getWorksheetFilePath(Sheet $sheet)
49
    {
50 43
        $sheetsContentTempFolder = $this->fileSystemHelper->getSheetsContentTempFolder();
51 43
        return $sheetsContentTempFolder . '/sheet' . $sheet->getIndex() . '.xml';
52
    }
53
54
    /**
55
     * Writes all the necessary files to disk and zip them together to create the final file.
56
     *
57
     * @param resource $finalFilePointer Pointer to the spreadsheet that will be created
58
     * @return void
59
     */
60 34
    protected function writeAllFilesToDiskAndZipThem($finalFilePointer)
61
    {
62 34
        $worksheets = $this->getWorksheets();
63 34
        $numWorksheets = count($worksheets);
64
65 34
        $this->fileSystemHelper
66 34
            ->createContentFile($this->worksheetManager, $worksheets, $this->styleHelper)
67 34
            ->deleteWorksheetTempFolder()
68 34
            ->createStylesFile($this->styleHelper, $numWorksheets)
69 34
            ->zipRootFolderAndCopyToStream($finalFilePointer);
70
    }
71
}