Conditions | 11 |
Paths | 4 |
Total Lines | 27 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
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']); |
||
|
|||
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); |
||
42 | } |
||
43 | |||
75 | } |
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: