Completed
Pull Request — master (#243)
by Luc
05:30
created

OpeningHours::equalOpeningHour()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
3
namespace CultuurNet\UDB3;
4
5
use ValueObjects\DateTime\WeekDay;
6
7
class OpeningHours
8
{
9
    /**
10
     * @var OpeningHour[]
11
     */
12
    private $openingHours;
13
14
    /**
15
     * OpeningHours constructor.
16
     * @param OpeningHour[]|null $openingHours
17
     */
18
    public function __construct(array $openingHours = null)
19
    {
20
        $this->openingHours = $openingHours ? $openingHours : null;
0 ignored issues
show
Documentation Bug introduced by
It seems like $openingHours ? $openingHours : null can be null. However, the property $openingHours 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...
21
    }
22
23
    /**
24
     * @param OpeningHour $openingHour
25
     */
26
    public function addOpeningHour(OpeningHour $openingHour)
27
    {
28
        $this->openingHours[] = $openingHour;
29
    }
30
31
    /**
32
     * @return OpeningHour[]
33
     */
34
    public function getOpeningHours()
35
    {
36
        return $this->openingHours;
37
    }
38
39
    /**
40
     * @return Weekday[]
41
     */
42
    public function getWeekDays()
43
    {
44
        $weekdays = [];
45
        
46
        foreach ($this->openingHours as $openingHour) {
47
            $weekdays[] = $openingHour->getWeekDay();
48
        }
49
        
50
        return $weekdays;
51
    }
52
53
    /**
54
     * @param OpeningHour $otherOpeningHour
55
     * @return bool
56
     */
57
    public function equalOpeningHour(OpeningHour $otherOpeningHour)
58
    {
59
        $equal = false;
60
61
        foreach ($this->openingHours as $openingHour) {
62
            if ($openingHour->equalHours($otherOpeningHour)) {
63
                $equal = true;
64
                break;
65
            }
66
        }
67
68
        return $equal;
69
    }
70
}
71