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

ArrayBatchIterableStep   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 10
cts 10
cp 1
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 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