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

ResultsCollection   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addResult() 0 3 1
A getGroupName() 0 3 1
A getResults() 0 3 1
A toArray() 0 15 3
A toJson() 0 3 1
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
}