Passed
Push — master ( f38dcf...954e17 )
by Jean Paul
01:37
created

FindMissingFromSequenceExtractor::extract()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 12
c 1
b 0
f 0
nc 6
nop 0
dl 0
loc 24
rs 9.8666
1
<?php
2
3
namespace Coco\SourceWatcher\Core\Extractors;
4
5
use Coco\SourceWatcher\Core\Row;
6
use Coco\SourceWatcher\Core\SourceWatcherException;
7
8
/**
9
 * Class FindMissingFromSequenceExtractor
10
 *
11
 * @package Coco\SourceWatcher\Core\Extractors
12
 */
13
class FindMissingFromSequenceExtractor extends ExecutionExtractor
14
{
15
    protected string $filterField;
16
17
    protected array $availableOptions = [ "filterField" ];
18
19
    public function __construct ()
20
    {
21
        $this->filterField = "id";
22
    }
23
24
    /**
25
     * @return string
26
     */
27
    public function getFilterField () : string
28
    {
29
        return $this->filterField;
30
    }
31
32
    /**
33
     * @param string $filterField
34
     */
35
    public function setFilterField ( string $filterField ) : void
36
    {
37
        $this->filterField = $filterField;
38
    }
39
40
    /**
41
     * @return array
42
     * @throws SourceWatcherException
43
     */
44
    public function extract ()
45
    {
46
        $previousExtractorResult = parent::extract();
47
48
        $copy = [];
49
50
        foreach ( $previousExtractorResult as $currentRow ) {
51
            $copy[] = $currentRow[$this->filterField];
52
        }
53
54
        asort( $copy );
55
56
        $min = reset( $copy );
57
        $max = end( $copy );
58
59
        $result = [];
60
61
        for ( $i = $min; $i <= $max; $i++ ) {
62
            if ( !in_array( $i, $copy ) ) {
63
                $result[] = new Row( [ $this->filterField => $i ] );
64
            }
65
        }
66
67
        return $result;
68
    }
69
}
70