ExampleStateMachineItemReader   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 19
dl 0
loc 64
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hydrateTransferFromPersistence() 0 16 3
A getStateMachineItems() 0 6 1
A __construct() 0 3 1
A getStateMachineItemTransferByItemStateIds() 0 8 1
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types = 1);
9
10
namespace Pyz\Zed\ExampleStateMachine\Business\Model;
11
12
use Generated\Shared\Transfer\StateMachineItemTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StateMachineItemTransfer 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 Propel\Runtime\Collection\ObjectCollection;
14
use Pyz\Zed\ExampleStateMachine\Persistence\ExampleStateMachineQueryContainerInterface;
15
16
class ExampleStateMachineItemReader
17
{
18
    /**
19
     * @var \Pyz\Zed\ExampleStateMachine\Persistence\ExampleStateMachineQueryContainerInterface
20
     */
21
    protected $exampleStateMachineQueryContainer;
22
23
    /**
24
     * @param \Pyz\Zed\ExampleStateMachine\Persistence\ExampleStateMachineQueryContainerInterface $exampleStateMachineQueryContainer
25
     */
26
    public function __construct(ExampleStateMachineQueryContainerInterface $exampleStateMachineQueryContainer)
27
    {
28
        $this->exampleStateMachineQueryContainer = $exampleStateMachineQueryContainer;
29
    }
30
31
    /**
32
     * @param array<int> $stateIds
33
     *
34
     * @return array<\Generated\Shared\Transfer\StateMachineItemTransfer>
35
     */
36
    public function getStateMachineItemTransferByItemStateIds(array $stateIds = []): array
37
    {
38
        /** @var \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\ExampleStateMachine\Persistence\ExampleStateMachineItem> $exampleStateMachineItems */
39
        $exampleStateMachineItems = $this->exampleStateMachineQueryContainer
40
            ->queryStateMachineItemsByStateIds($stateIds)
41
            ->find();
42
43
        return $this->hydrateTransferFromPersistence($exampleStateMachineItems);
44
    }
45
46
    /**
47
     * @return array<\Generated\Shared\Transfer\StateMachineItemTransfer>
48
     */
49
    public function getStateMachineItems(): array
50
    {
51
        $exampleStateMachineItems = $this->exampleStateMachineQueryContainer
52
            ->queryAllStateMachineItems();
53
54
        return $this->hydrateTransferFromPersistence($exampleStateMachineItems);
55
    }
56
57
    /**
58
     * @psalm-suppress TooManyTemplateParams
59
     *
60
     * @param \Propel\Runtime\Collection\ObjectCollection<\Orm\Zed\ExampleStateMachine\Persistence\ExampleStateMachineItem> $exampleStateMachineItems
61
     *
62
     * @return array<\Generated\Shared\Transfer\StateMachineItemTransfer>
63
     */
64
    protected function hydrateTransferFromPersistence(ObjectCollection $exampleStateMachineItems): array
65
    {
66
        $stateMachineItems = [];
67
        foreach ($exampleStateMachineItems as $exampleStateMachineItemEntity) {
68
            if (!$exampleStateMachineItemEntity->getFkStateMachineItemState()) {
69
                continue;
70
            }
71
72
            $stateMachineItemIdentifier = new StateMachineItemTransfer();
73
            $stateMachineItemIdentifier->setIdentifier($exampleStateMachineItemEntity->getIdExampleStateMachineItem());
74
            $stateMachineItemIdentifier->setIdItemState($exampleStateMachineItemEntity->getFkStateMachineItemState());
75
76
            $stateMachineItems[] = $stateMachineItemIdentifier;
77
        }
78
79
        return $stateMachineItems;
80
    }
81
}
82