ResultCollection   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 112
rs 10
c 1
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A push() 0 4 1
A asArray() 0 7 2
A getIterator() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
A count() 0 4 1
A get() 0 3 2
A getScore() 0 4 1
A setScore() 0 5 1
1
<?php
2
3
/*
4
 * (c) Jean-François Lépine <https://twitter.com/Halleck45>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Hal\Component\Result;
11
use Hal\Component\Score\ScoreInterface;
12
13
14
/**
15
 * ResultSet
16
 *
17
 * @author Jean-François Lépine <https://twitter.com/Halleck45>
18
 */
19
class ResultCollection implements ExportableInterface, \IteratorAggregate, \ArrayAccess, \Countable {
20
21
    /**
22
     * Results
23
     *
24
     * @var array
25
     */
26
    private $results = array();
27
28
    /**
29
     * @var ScoreInterface
30
     */
31
    private $score;
32
33
    /**
34
     * Push resultset
35
     *
36
     * @param ResultSetInterface $resultset
37
     * @return $this
38
     */
39
    public function push(ResultSetInterface $resultset) {
40
        $this->results[$resultset->getName()] = $resultset;
41
        return $this;
42
    }
43
44
    /**
45
     * @inheritedDoc
46
     */
47
    public function asArray() {
48
        $array = array();
49
        foreach($this->results as $result) {
50
            array_push($array, $result->asArray());
51
        }
52
        return $array;
53
    }
54
55
    /**
56
     * @inheritedDoc
57
     */
58
    public function getIterator()
59
    {
60
        return new \ArrayIterator($this->results);
61
    }
62
63
    /**
64
     * @inheritedDoc
65
     */
66
    public function offsetExists($offset)
67
    {
68
        return isset($this->results[$offset]);
69
    }
70
71
    /**
72
     * @inheritedDoc
73
     */
74
    public function offsetGet($offset)
75
    {
76
        return $this->results[$offset];
77
    }
78
79
    /**
80
     * @inheritedDoc
81
     */
82
    public function offsetSet($offset, $value)
83
    {
84
        $this->results[$offset] = $value;
85
    }
86
87
    /**
88
     * @inheritedDoc
89
     */
90
    public function offsetUnset($offset)
91
    {
92
        unset($this->results[$offset]);
93
    }
94
95
    /**
96
     * @inheritedDoc
97
     */
98
    public function count()
99
    {
100
        return sizeof($this->results, COUNT_NORMAL);
101
    }
102
103
    /**
104
     * Get by file
105
     *
106
     * @param $key
107
     * @return null|ResultSet
108
     */
109
    public function get($key) {
110
        return isset($this->results[$key]) ? $this->results[$key] : null;
111
    }
112
113
    /**
114
     * @return ScoreInterface
115
     */
116
    public function getScore()
117
    {
118
        return $this->score;
119
    }
120
121
    /**
122
     * @param ScoreInterface $score
123
     * @return $this
124
     */
125
    public function setScore(ScoreInterface $score)
126
    {
127
        $this->score = $score;
128
        return $this;
129
    }
130
}