BasicGenerator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 28
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A generate() 0 11 3
1
<?php
2
declare(strict_types=1);
3
4
namespace MisterIcy\ExcelWriter\Generator;
5
6
use MisterIcy\ExcelWriter\Exceptions\GeneratorException;
7
use PhpOffice\PhpSpreadsheet\Spreadsheet;
8
9
/**
10
 * Class BasicGenerator
11
 * @package MisterIcy\ExcelWriter\Generator
12
 */
13
final class BasicGenerator extends AbstractGenerator
14
{
15
    /**
16
     * BasicGenerator constructor.
17
     * @throws \PhpOffice\PhpSpreadsheet\Exception
18
     */
19
    public function __construct()
20
    {
21
        $this->spreadsheet = new Spreadsheet();
22
        $this->spreadsheet->setActiveSheetIndex(0);
23
    }
24
25
    /**
26
     * @param Spreadsheet|null $spreadsheet
27
     * @return GeneratorInterface
28
     * @throws GeneratorException
29
     */
30
    public function generate(Spreadsheet $spreadsheet = null): GeneratorInterface
31
    {
32
        if (is_null($this->handler)) {
33
            throw new GeneratorException("Handlers must be provided in order to generate a document");
34
        }
35
        if (!is_null($spreadsheet)) {
36
            $this->spreadsheet = $spreadsheet;
37
        }
38
        $this->handler->handle($this);
39
40
        return $this;
41
    }
42
}
43