Completed
Push — master ( 7deb6b...300324 )
by Tim
02:03
created

TestResult::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 3
b 0
f 0
nc 1
nop 2
dl 0
loc 6
rs 9.4285
1
<?php
2
3
namespace SimpleSAML\Module\monitor;
4
5
final class TestResult
6
{
7
    /**
8
     * @var string  Test category this test belongs to
9
     */
10
    private $category;
11
12
    /**
13
     * @var string  The subject that was tested
14
     */
15
    private $subject;
16
17
    /**
18
     * @var string  Message describing the result
19
     */
20
    private $message;
21
22
    /**
23
     * @var array   Data to be used by TestSuite or other TestCases
24
     */
25
    private $output;
26
27
    /**
28
     * @var State   The State object reflecting the result
29
     */
30
    private $state = State::NOSTATE;
31
32
    /**
33
     * @param string $category
34
     * @param string $subject
35
     */
36
    public function __construct($category = 'Unknown category', $subject = 'Unknown subject')
37
    {
38
        $this->category = $this->setCategory($category);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->category is correct as $this->setCategory($category) (which targets SimpleSAML\Module\monito...stResult::setCategory()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
39
        $this->subject = $this->setSubject($subject);
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $this->subject is correct as $this->setSubject($subject) (which targets SimpleSAML\Module\monitor\TestResult::setSubject()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
40
        $this->output = setOutput(array());
41
    }
42
43
    /**
44
     * @param string $subject
0 ignored issues
show
Bug introduced by
There is no parameter named $subject. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
45
     *
46
     * @return void
47
     */
48
    public function setSubject($value)
49
    {
50
        assert(is_string($value));
51
        $this->subject = $value;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getSubject()
58
    {
59
        assert(is_string($this->subject));
60
        return $this->subject;
61
    }
62
63
    /**
64
     * @param string $category
0 ignored issues
show
Bug introduced by
There is no parameter named $category. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
65
     *
66
     * @return void
67
     */
68
    public function setCategory($value)
69
    {
70
        assert(is_string($value));
71
        $this->category = $value;
72
    }
73
74
    /**
75
     * @return string
76
     */
77
    public function getCategory()
78
    {
79
        assert(is_string($this->category));
80
        return $this->category;
81
    }
82
83
        /**
84
     * @param string $message
85
     *
86
     * @return void
87
     */
88
    public function setMessage($message)
89
    {
90
        assert(is_string($message));
91
        $this->message = $message;
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function getMessage()
98
    {
99
        assert(is_string($this->message));
100
        return $this->message;
101
    }
102
103
    /**
104
     * @param array $value
105
     *
106
     * @return void
107
     */
108
    public function setOutput($value)
109
    {
110
        assert(is_array($value));
111
        $this->output = $value;
112
    }
113
114
    /**
115
     * @param string|null $key
116
     *
117
     * @return mixed
118
     */
119
    public function getOutput($key = null)
120
    {
121
        assert(is_array($this->output));
122
        return is_null($key) ? $this->output : (isSet($this->output[$key]) ? $this->output[$key] : null);
123
    }
124
125
    /**
126
     * @param State $state
127
     *
128
     * @return void
129
     */
130
    public function setState($state = State::NOSTATE)
131
    {
132
        assert($state instanceof State);
133
        $this->state = $state;
134
    }
135
136
    /**
137
     * @return State
138
     */
139
    public function getState()
140
    {
141
        assert($this->state instanceof State);
142
        return $this->state;
143
    }
144
}
145