Completed
Push — development ( eb9524...db4517 )
by Andrij
28:49 queued 02:09
created

ResultsCollection::getGroupName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace xbanners\src\UrlFinder;
4
5
use xbanners\src\UrlFinder\Results\Result;
6
7
class ResultsCollection
8
{
0 ignored issues
show
introduced by
Opening brace of a class must be on the same line as the definition
Loading history...
9
10
    /**
11
     * @var null
12
     */
13
    protected $groupName;
14
15
    /**
16
     * @var Result[]
17
     */
18
    protected $results = [];
19
20
    public function addResult(Result $result) {
21
        $this->results[] = $result;
22
    }
23
24
    public function getGroupName() {
25
        return $this->groupName;
26
    }
27
28
    public function getResults() {
29
        return $this->results;
30
    }
31
32
    public function toArray() {
33
34
        $array = [];
35
        foreach ($this->results as $oneResult) {
36
            if (count($oneResult)) {
37
                $oneResultArray = $oneResult->toArray();
38
                $array[] = [
39
                    'label' => $oneResult->getGroupName(),
40
                    'value' => $oneResultArray[$oneResult->getGroupName()],
41
                ];
42
43
            }
44
        }
45
        return $array;
46
    }
47
48
    public function toJson() {
49
        return json_encode($this->toArray());
50
    }
51
52
}