Passed
Push — 0.4 ( 487c21 )
by jean
05:10
created

ArrayBatchIterableStep::configureOptionResolver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Darkilliant\ProcessBundle\Step;
6
7
use Darkilliant\ProcessBundle\State\ProcessState;
8
use Symfony\Component\OptionsResolver\OptionsResolver;
9
10
class ArrayBatchIterableStep extends AbstractConfigurableStep
11
{
12
    private $data = [];
13
14 1
    public function configureOptionResolver(OptionsResolver $resolver): OptionsResolver
15
    {
16 1
        $resolver->setRequired('batch_count');
17
18 1
        return parent::configureOptionResolver($resolver); // TODO: Change the autogenerated stub
19
    }
20
21 1
    public function execute(ProcessState $state)
22
    {
23 1
        $this->data[] = $state->getData();
24
25 1
        if (count($this->data) >= $state->getOptions()['batch_count'] || $state->getLoop()['last'] ?? false) {
26 1
            $state->setData($this->data);
27 1
            $this->data = [];
28
29 1
            return;
30
        }
31
32 1
        $state->markIgnore();
33 1
    }
34
}
35