GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( a3c5fc...13d483 )
by Dragos
11:38
created

DayBuilder::isIntervalAllDay()   B

Complexity

Conditions 7
Paths 3

Size

Total Lines 12
Code Lines 6

Duplication

Lines 6
Ratio 50 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 6
loc 12
rs 8.2222
cc 7
eloc 6
nc 3
nop 2
1
<?php
2
3
namespace Speicher210\BusinessHours\Day;
4
5
use Speicher210\BusinessHours\Day\Time\Time;
6
use Speicher210\BusinessHours\Day\Time\TimeBuilder;
7
use Speicher210\BusinessHours\Day\Time\TimeInterval;
8
9
/**
10
 * Build a DayInterface concrete implementation.
11
 */
12
class DayBuilder
13
{
14
    /**
15
     * Create a new Day.
16
     *
17
     * @param integer $dayOfWeek The day of week.
18
     * @param array $openingIntervals The opening intervals.
19
     * @return Day
20
     */
21
    public static function fromArray($dayOfWeek, array $openingIntervals)
22
    {
23
        $intervals = array();
24
        foreach ($openingIntervals as $interval) {
25
            $intervals[] = new TimeInterval(
26
                TimeBuilder::fromString($interval[0]),
27
                TimeBuilder::fromString($interval[1])
28
            );
29
        }
30
31
        return new Day($dayOfWeek, $intervals);
32
    }
33
34
    /**
35
     * Create a DayInterface object from an array.
36
     *
37
     * @param array $data The day data.
38
     * @return DayInterface
39
     */
40
    public static function fromAssociativeArray(array $data)
41
    {
42 View Code Duplication
        if (!isset($data['openingIntervals']) || !is_array($data['openingIntervals']) || !isset($data['dayOfWeek'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
            throw new \InvalidArgumentException('Array is not valid.');
44
        }
45
46
        $openingIntervals = array();
47
        foreach ($data['openingIntervals'] as $openingInterval) {
48
            $start = TimeBuilder::fromArray($openingInterval['start']);
49
            $end = TimeBuilder::fromArray($openingInterval['end']);
50
            if (self::isIntervalAllDay($start, $end)) {
51
                return new AllDay($data['dayOfWeek']);
0 ignored issues
show
Documentation introduced by
$data['dayOfWeek'] is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
            }
53
54
            $openingIntervals[] = new TimeInterval($start, $end);
55
        }
56
57
        return new Day($data['dayOfWeek'], $openingIntervals);
0 ignored issues
show
Documentation introduced by
$data['dayOfWeek'] is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
58
    }
59
60
    /**
61
     * Check if an interval array is all day.
62
     *
63
     * @param Time $start The start time.
64
     * @param Time $end The end time.
65
     * @return boolean
66
     */
67
    private static function isIntervalAllDay(Time $start, Time $end)
68
    {
69 View Code Duplication
        if ($start->getHours() !== 0 || $start->getMinutes() !== 0 || $start->getSeconds() !== 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
            return false;
71
        }
72
73 View Code Duplication
        if ($end->getHours() !== 24 || $end->getMinutes() !== 0 || $end->getSeconds() !== 0) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
            return false;
75
        }
76
77
        return true;
78
    }
79
}