Completed
Pull Request — master (#139)
by
unknown
04:18
created

SearchResults::add()   B

Complexity

Conditions 7
Paths 6

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 7.6024

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 18
ccs 10
cts 13
cp 0.7692
rs 8.2222
cc 7
eloc 9
nc 6
nop 1
crap 7.6024
1
<?php
2
3
namespace Yandex\Market\Content\Models;
4
5
use Yandex\Common\ObjectModel;
6
use Yandex\Market\Content\Models\Base\MarketModel;
7
8
class SearchResults extends ObjectModel
9
{
10
    /**
11
     * Add category to collection
12
     *
13
     * @param ModelParent|ModelChild|ModelVisual|ModelSingle|ModelInfo|Offer|array $searchResult
14
     *
15
     * @return SearchResults
16
     */
17 2
    public function add($searchResult)
18
    {
19 2
        if (is_array($searchResult)) {
20 2
            if (isset($searchResult['model'])) {
21 2
                $this->collection[] = MarketModel::getInstance($searchResult['model']);
22 2
            }
23
24 2
            if (isset($searchResult['offer'])) {
25 2
                $this->collection[] = new Offer($searchResult['offer']);
26 2
            }
27
28 2
        } elseif (is_object($searchResult) && ($searchResult instanceof MarketModel || $searchResult instanceof Offer)
29
        ) {
30
            $this->collection[] = $searchResult;
31
        }
32
33 2
        return $this;
34
    }
35
36
    /**
37
     * Retrieve the collection property
38
     *
39
     * @return SearchResults|null
40
     */
41
    public function getAll()
42
    {
43
        return $this->collection;
44
    }
45
}
46