Completed
Pull Request — master (#64)
by Thibaud
03:11
created

SearchResult::fromList()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
namespace PhraseanetSDK\Search;
4
5
class SearchResult
6
{
7
8
    public static function fromList($valueType, array $values)
9
    {
10
        $results = [];
11
12
        foreach ($values as $value) {
13
            $results[] = self::fromValue($valueType, $value);
14
        }
15
16
        return $results;
17
    }
18
19
    public static function fromValue($valueType, \stdClass $value)
20
    {
21
        return new self($valueType, $value->databox_id, $value->collection_id, $value->record_id, $value->version);
22
    }
23
24
    const TYPE_RECORD = 0;
25
26
    const TYPE_STORY = 1;
27
28
    /**
29
     * @var int A SearchResult::TYPE_* constant
30
     */
31
    private $type = self::TYPE_RECORD;
32
33
    /**
34
     * @var int
35
     */
36
    private $databoxId;
37
38
    /**
39
     * @var int
40
     */
41
    private $collectionId;
42
43
    /**
44
     * @var int
45
     */
46
    private $recordId;
47
48
    /**
49
     * @var int
50
     */
51
    private $version;
52
53
    /**
54
     * @param int $type
55
     * @param int $databoxId
56
     * @param int $collectionId
57
     * @param int $recordId
58
     * @param int $version
59
     */
60
    public function __construct($type, $databoxId, $collectionId, $recordId, $version)
61
    {
62
        $this->type = $type;
63
        $this->databoxId = $databoxId;
64
        $this->collectionId = $collectionId;
65
        $this->recordId = $recordId;
66
        $this->version = $version;
67
    }
68
69
    /**
70
     * @return int
71
     */
72
    public function getType()
73
    {
74
        return $this->type;
75
    }
76
77
    /**
78
     * @return int
79
     */
80
    public function getDataboxId()
81
    {
82
        return $this->databoxId;
83
    }
84
85
    /**
86
     * @return int
87
     */
88
    public function getCollectionId()
89
    {
90
        return $this->collectionId;
91
    }
92
93
    /**
94
     * @return int
95
     */
96
    public function getRecordId()
97
    {
98
        return $this->recordId;
99
    }
100
101
    /**
102
     * @return int
103
     */
104
    public function getVersion()
105
    {
106
        return $this->version;
107
    }
108
}
109