Completed
Pull Request — master (#19)
by Mykola (Nikolay)
04:20
created

SuperAttributeAkeneoApiReadStream   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 47
rs 10
c 2
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A open() 0 6 1
A eof() 0 7 3
A get() 0 12 4
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