Completed
Pull Request — master (#487)
by Jonas
02:52
created

ProductStreamsAssignments   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getStreamsByArticleId() 0 8 2
A getArticleIds() 0 4 1
A getArticleIdsWithoutStreams() 0 12 3
A merge() 0 5 1
1
<?php
2
/**
3
 * (c) shopware AG <[email protected]>
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace ShopwarePlugins\Connect\Components\ProductStream;
9
10
use ShopwarePlugins\Connect\Components\Struct;
11
12
class ProductStreamsAssignments extends Struct
13
{
14
    /**
15
     * @var array
16
     */
17
    public $assignments = [];
18
19
    /**
20
     * @param $articleId
21
     * @return array | null
22
     */
23
    public function getStreamsByArticleId($articleId)
24
    {
25
        if (isset($this->assignments[$articleId])) {
26
            return $this->assignments[$articleId];
27
        }
28
29
        return null;
30
    }
31
32
    /**
33
     * @return array
34
     */
35
    public function getArticleIds()
36
    {
37
        return array_keys($this->assignments);
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    public function getArticleIdsWithoutStreams()
44
    {
45
        $articleIds = [];
46
47
        foreach ($this->getArticleIds() as $articleId) {
48
            if (empty($this->getStreamsByArticleId($articleId))) {
49
                $articleIds[] = $articleId;
50
            }
51
        }
52
53
        return $articleIds;
54
    }
55
56
    public function merge(ProductStreamsAssignments $assignments) {
57
        $this->assignments = array_merge($this->assignments, $assignments->assignments);
58
59
        return $this;
60
    }
61
}
62