Conditions | 7 |
Paths | 8 |
Total Lines | 16 |
Code Lines | 9 |
Lines | 0 |
Ratio | 0 % |
Tests | 8 |
CRAP Score | 7.392 |
Changes | 0 |
1 | <?php |
||
15 | 16 | public function normalize($widget): void |
|
16 | { |
||
17 | 16 | if (! property_exists($widget, 'cacheLifeTime')) { |
|
18 | 13 | $M = (int) (config('widgetize.default_cache_lifetime', 0)); |
|
19 | 13 | $widget->cacheLifeTime = new \DateInterval('PT'.$M.'M'); |
|
20 | } |
||
21 | |||
22 | 16 | if(is_object($widget->cacheLifeTime) or $widget->cacheLifeTime === 0){ |
|
|
|||
23 | 14 | return ; |
|
24 | } |
||
25 | |||
26 | 2 | if ($widget->cacheLifeTime === 'forever' || $widget->cacheLifeTime < 0) { |
|
27 | // 2 weeks which is long enough ! |
||
28 | 2 | $widget->cacheLifeTime = new \DateInterval('P2W'); |
|
29 | } elseif (is_numeric($widget->cacheLifeTime)) { |
||
30 | $widget->cacheLifeTime = new \DateInterval('PT'.(string) $widget->cacheLifeTime.'M'); |
||
31 | } |
||
34 |
PHP has two types of connecting operators (logical operators, and boolean operators):
and
&&
or
||
The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&
, or||
.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
die
introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrow
at this point:These limitations lead to logical operators rarely being of use in current PHP code.