Completed
Branch master (2e2c40)
by Rob
01:16
created

CerberusModel::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 5
cp 0
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace devtoolboxuk\cerberus\Models;
4
5
class CerberusModel
6
{
7
    /**
8
     * @var array
9
     */
10
    private $references = [];
11
12
    /**
13
     * @var int
14
     */
15
    private $score = 0;
16
17
    /**
18
     * @var array
19
     */
20
    private $result = [];
21
22
    /**
23
     * DetectModel constructor.
24
     * @param array $references
25
     * @param int $score
26
     * @param array $result
27
     */
28 4
    function __construct($references = [], $score = 0, $result = [])
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
Comprehensibility Best Practice introduced by
It is recommend to declare an explicit visibility for __construct.

Generally, we recommend to declare visibility for all methods in your source code. This has the advantage of clearly communication to other developers, and also yourself, how this method should be consumed.

If you are not sure which visibility to choose, it is a good idea to start with the most restrictive visibility, and then raise visibility as needed, i.e. start with private, and only raise it to protected if a sub-class needs to have access, or public if an external class needs access.

Loading history...
29
    {
30 4
        $this->references = $references;
31 4
        $this->score = $score;
32 4
        $this->result = $result;
33 4
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function toArray()
39
    {
40
        return [
41
            'results' => [
42
                "array" => $this->decodedResult(),
43
                'string' => $this->getResult(),
44
            ],
45
            'references' => $this->getReferences(),
46
            'score' => $this->getScore()
47
        ];
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    private function decodedResult()
54
    {
55
        return $this->result;
56
    }
57
58
    /**
59
     * @return false|string
60
     */
61 4
    public function getResult()
62
    {
63 4
        return json_encode($this->result);
64
    }
65
66
    /**
67
     * @return array
68
     */
69
    public function getReferences()
70
    {
71
        return $this->references;
72
    }
73
74
    /**
75
     * @return integer
76
     */
77 4
    public function getScore()
78
    {
79 4
        return $this->score;
80
    }
81
82
    /**
83
     * @return bool
84
     */
85
    public function hasScore()
86
    {
87
        return ($this->getScore() > 0) ? true : false;
88
    }
89
90
}