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

ArrayBatchIterableStep   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureOptionResolver() 0 5 1
A execute() 0 12 3
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