Completed
Push — master ( 51452e...eeb01f )
by Tristan
11:39
created

GenericBadNews::getReasons()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Enzyme\Axiom\Containers;
4
5
use Enzyme\Axiom\Atoms\StringAtom;
6
7
class GenericBadNews implements BadNewsInterface
8
{
9
    /**
10
     * The message describing this bad news.
11
     * @var StringAtom
12
     */
13
    protected $message;
14
15
    /**
16
     * The optional reasons associated with this bad news.
17
     * @var array
18
     */
19
    protected $reasons;
20
21
    /**
22
     * Create a new generic bad news container given the message and optional
23
     * reasons associated with it.
24
     *
25
     * @param StringAtom $message
26
     * @param array $reasons
27
     */
28
    public function __construct(StringAtom $message, array $reasons = null)
29
    {
30
        $this->message = $message;
31
        $this->reasons = $reasons;
0 ignored issues
show
Documentation Bug introduced by
It seems like $reasons can be null. However, the property $reasons is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
32
    }
33
34
    /**
35
     * @see BadNewsInterface
36
     */
37
    public function getMessage()
38
    {
39
        return $this->message->getValue();
40
    }
41
42
    /**
43
     * @see BadNewsInterface
44
     */
45
    public function hasReasons()
46
    {
47
        return $this->reasons !== null;
48
    }
49
50
    /**
51
     * @see BadNewsInterface
52
     */
53
    public function getReasons()
54
    {
55
        return $this->reasons;
56
    }
57
}
58