Completed
Push — master ( eb6a78...9e6b52 )
by
unknown
24s queued 19s
created

PagingConverter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * MIT License
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace SprykerEco\Client\FactFinderSdk\Business\Api\Converter\Data;
9
10
use FACTFinder\Data\Paging;
11
use Generated\Shared\Transfer\FactFinderSdkDataPageTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...nderSdkDataPageTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Generated\Shared\Transfer\FactFinderSdkDataPagingTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...erSdkDataPagingTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use SprykerEco\Client\FactFinderSdk\Business\Api\Converter\BaseConverter;
14
15
class PagingConverter extends BaseConverter implements PagingConverterInterface
16
{
17
    /**
18
     * @var \FACTFinder\Data\Paging
19
     */
20
    protected $paging;
21
22
    /**
23
     * @var \SprykerEco\Client\FactFinderSdk\Business\Api\Converter\Data\ItemConverterInterface
24
     */
25
    protected $itemConverter;
26
27
    /**
28
     * @param \SprykerEco\Client\FactFinderSdk\Business\Api\Converter\Data\ItemConverterInterface $itemConverter
29
     */
30
    public function __construct(ItemConverterInterface $itemConverter)
31
    {
32
        $this->itemConverter = $itemConverter;
33
    }
34
35
    /**
36
     * @param \FACTFinder\Data\Paging|null $paging
37
     *
38
     * @return void
39
     */
40
    public function setPaging(?Paging $paging = null)
41
    {
42
        $this->paging = $paging;
43
    }
44
45
    /**
46
     * @return \Generated\Shared\Transfer\FactFinderSdkDataPagingTransfer
47
     */
48
    public function convert()
49
    {
50
        $factFinderDataPagingTransfer = new FactFinderSdkDataPagingTransfer();
51
52
        if ($this->paging === null) {
53
            return $factFinderDataPagingTransfer;
54
        }
55
56
        $factFinderDataPagingTransfer->setPageCount($this->paging->getPageCount());
57
        $factFinderDataPagingTransfer->setFirstPage($this->convertPage($this->paging->getFirstPage()));
58
        $factFinderDataPagingTransfer->setLastPage($this->convertPage($this->paging->getLastPage()));
59
        $factFinderDataPagingTransfer->setPreviousPage($this->convertPage($this->paging->getPreviousPage()));
60
        $factFinderDataPagingTransfer->setCurrentPage($this->convertPage($this->paging->getCurrentPage()));
61
        $factFinderDataPagingTransfer->setNextPage($this->convertPage($this->paging->getNextPage()));
62
63
        $this->addPagesArray($factFinderDataPagingTransfer);
64
65
        return $factFinderDataPagingTransfer;
66
    }
67
68
    /**
69
     * @param \FACTFinder\Data\Page|null $page
70
     *
71
     * @return \Generated\Shared\Transfer\FactFinderSdkDataPageTransfer
72
     */
73
    protected function convertPage($page)
74
    {
75
        $factFinderDataPageTransfer = new FactFinderSdkDataPageTransfer();
76
        if ($page === null) {
77
            return $factFinderDataPageTransfer;
78
        }
79
80
        $factFinderDataPageTransfer->setPageNumber($page->getPageNumber());
81
        $this->itemConverter->setItem($page);
82
        $factFinderDataPageTransfer->setItem(
83
            $this->itemConverter->convert()
84
        );
85
86
        return $factFinderDataPageTransfer;
87
    }
88
89
    /**
90
     * @param \Generated\Shared\Transfer\FactFinderSdkDataPagingTransfer $factFinderDataPagingTransfer
91
     *
92
     * @return void
93
     */
94
    protected function addPagesArray(FactFinderSdkDataPagingTransfer $factFinderDataPagingTransfer)
95
    {
96
        foreach ($this->paging->getArrayCopy() as $item) {
97
            $factFinderDataPagingTransfer->addPages($this->convertPage($item));
98
        }
99
    }
100
}
101