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 ( 62bde9...a3c5fc )
by Dragos
13:39
created

DayBuilder::isIntervalArrayAllDay()   C

Complexity

Conditions 11
Paths 6

Size

Total Lines 25
Code Lines 12

Duplication

Lines 12
Ratio 48 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 12
loc 25
rs 5.2653
cc 11
eloc 12
nc 6
nop 1

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Speicher210\BusinessHours;
4
5
/**
6
 * Build a DayInterface concrete implementation.
7
 */
8
class DayBuilder
9
{
10
    /**
11
     * Create a DayInterface object from an array.
12
     *
13
     * @param array $data The day data.
14
     * @return DayInterface
15
     */
16
    public static function fromArray(array $data)
17
    {
18
        if (!isset($data['openingIntervals']) || !is_array($data['openingIntervals']) || !isset($data['dayOfWeek'])) {
19
            throw new \InvalidArgumentException('Array is not valid.');
20
        }
21
22
        if (count($data['openingIntervals']) === 1 && self::isIntervalArrayAllDay(reset($data['openingIntervals']))) {
23
            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...
24
        }
25
26
        $openingIntervals = array();
27
        foreach ($data['openingIntervals'] as $openingInterval) {
28
            $start = new Time(
29
                $openingInterval['start']['hours'],
30
                isset($openingInterval['start']['minutes']) ? $openingInterval['start']['minutes'] : 0,
31
                isset($openingInterval['start']['seconds']) ? $openingInterval['start']['seconds'] : 0
32
            );
33
            $end = new Time(
34
                $openingInterval['end']['hours'],
35
                isset($openingInterval['end']['minutes']) ? $openingInterval['end']['minutes'] : 0,
36
                isset($openingInterval['end']['seconds']) ? $openingInterval['end']['seconds'] : 0
37
            );
38
            $openingIntervals[] = array($start, $end);
39
        }
40
41
        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...
42
    }
43
44
    /**
45
     * Check if an interval array is all day.
46
     *
47
     * @param array $data The interval as an array to check.
48
     * @return boolean
49
     */
50
    private static function isIntervalArrayAllDay(array $data)
51
    {
52
        if ($data['start']['hours'] != 0 || $data['end']['hours'] != 24) {
53
            return false;
54
        }
55
56 View Code Duplication
        if (isset($data['start']['minutes']) && $data['start']['minutes'] != 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...
57
            return false;
58
        }
59
60 View Code Duplication
        if (isset($data['end']['minutes']) && $data['end']['minutes'] != 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...
61
            return false;
62
        }
63
64
65 View Code Duplication
        if (isset($data['start']['seconds']) && $data['start']['seconds'] != 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...
66
            return false;
67
        }
68
69 View Code Duplication
        if (isset($data['end']['seconds']) && $data['end']['seconds'] != 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
        return true;
74
    }
75
}