Failed Conditions
Pull Request — master (#11)
by jean
12:30
created

ArrayBatchIterableStep::execute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 1
dl 0
loc 12
rs 9.4285
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
    public function configureOptionResolver(OptionsResolver $resolver): OptionsResolver
15
    {
16
        $resolver->setRequired('batch_count');
17
18
        return parent::configureOptionResolver($resolver); // TODO: Change the autogenerated stub
19
    }
20
21
    public function execute(ProcessState $state)
22
    {
23
        $this->data[] = $state->getData();
24
25
        if (count($this->data) >= $state->getOptions()['batch_count'] || $state->getLoop()['last'] ?? false) {
26
            $state->setData($this->data);
27
            $this->data = [];
28
29
            return;
30
        }
31
32
        $state->markIgnore();
33
    }
34
}
35