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

SuperAttributeAkeneoApiReadStream::eof()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 10
rs 10
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
        $isValidCursorVariants = false;
53
54
        if ($this->cursorVariants !== null) {
55
            $this->cursorVariants->next();
56
            $isValidCursorVariants = $this->cursorVariants->valid();
57
        }
58
59
        return parent::eof() && !$isValidCursorVariants;
60
    }
61
}
62