Passed
Pull Request — master (#19)
by Mykola (Nikolay)
04:33
created

SuperAttributeAkeneoApiReadStream::eof()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 4
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Zed\AkeneoPimMiddlewareConnector\Business\Stream\Akeneo;
9
10
class SuperAttributeAkeneoApiReadStream extends AbstractAkeneoApiReadStream
11
{
12
    /**
13
     * @var \SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Wrapper\AkeneoResourceCursor
14
     */
15
    protected $cursorVariants;
16
17
    protected const KEY_CODE = 'code';
18
19
    /**
20
     * @return bool
21
     */
22
    public function open(): bool
23
    {
24
        $this->cursor = $this->akeneoPimService
25
            ->getAllFamilies();
26
27
        return true;
28
    }
29
30
    /**
31
     * @return array
32
     */
33
    public function get(): array
34
    {
35
        if (($this->cursorVariants !== null) && $this->cursorVariants->valid()) {
36
            return $this->cursorVariants->current();
37
        }
38
39
        $family = $this->cursor->current();
40
        $this->cursor->next();
41
42
        $this->cursorVariants = $this->akeneoPimService->getFamilyVariants($family[static::KEY_CODE]);
43
44
        return $this->cursorVariants->valid() ? $this->cursorVariants->current() : [];
45
    }
46
47
    /**
48
     * @return bool
49
     */
50
    public function eof(): bool
51
    {
52
        if ($this->cursorVariants !== null) {
53
            $this->cursorVariants->next();
54
        }
55
56
        return parent::eof() && !$this->cursorVariants->valid();
57
    }
58
}
59