SplitExcelStep   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 50
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A valid() 0 3 1
A execute() 0 4 1
A __construct() 0 3 1
A configureOptionResolver() 0 5 1
A next() 0 5 1
A describe() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Darkilliant\ImportBundle\Step;
6
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
use Darkilliant\ImportBundle\Extractor\ExcelSplitter;
9
use Darkilliant\ProcessBundle\State\ProcessState;
10
use Darkilliant\ProcessBundle\Step\AbstractConfigurableStep;
11
use Darkilliant\ProcessBundle\Step\IterableStepInterface;
12
13
class SplitExcelStep extends AbstractConfigurableStep implements IterableStepInterface
14
{
15
    /** @var \ArrayIterator */
16
    private $iterator;
17
18
    /** @var ExcelSplitter */
19
    private $excelSpliter;
20
21 5
    public function __construct(ExcelSplitter $splitter)
22
    {
23 5
        $this->excelSpliter = $splitter;
24 5
    }
25
26
    /**
27
     * @param ProcessState $state
28
     *
29
     * @throws \PHPExcel_Reader_Exception
30
     * @throws \PHPExcel_Writer_Exception
31
     */
32 3
    public function execute(ProcessState $state)
33
    {
34 3
        $this->iterator = new \ArrayIterator(
35 3
            $this->excelSpliter->split($state->getOptions()['filepath'])
36
        );
37 3
    }
38
39 1
    public function configureOptionResolver(OptionsResolver $resolver): OptionsResolver
40
    {
41 1
        $resolver->setRequired('filepath');
42
43 1
        return parent::configureOptionResolver($resolver);
44
    }
45
46 1
    public function next(ProcessState $state)
47
    {
48 1
        $state->setData($this->iterator->current());
49
50 1
        $this->iterator->next();
51 1
    }
52
53 1
    public function valid(ProcessState $state)
54
    {
55 1
        return $this->iterator->valid();
56
    }
57
58 1
    public function describe(ProcessState $state)
59
    {
60 1
        $state->info(
61 1
            'split excel file {filepath} into one csv file for each tab',
62 1
            ['filepath' => $state->getOptions()['filepath'] ?? 'unkow']
63
        );
64 1
    }
65
}
66