| Conditions | 6 |
| Paths | 5 |
| Total Lines | 22 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 6.972 |
| Changes | 2 | ||
| Bugs | 2 | Features | 0 |
| 1 | <?php |
||
| 15 | 25 | public function dateFormat($date) |
|
| 16 | { |
||
| 17 | 25 | if (preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $date)) { |
|
| 18 | 9 | return $date; |
|
| 19 | } |
||
| 20 | |||
| 21 | 19 | if ($date instanceof Carbon or $date instanceof \DateTime) { |
|
|
|
|||
| 22 | 15 | return $date->format('Y-m-d'); |
|
| 23 | } |
||
| 24 | |||
| 25 | // sqlite |
||
| 26 | 4 | if ($carbonDate = Carbon::createFromFormat('Y-m-d H:i:s', $date)) { |
|
| 27 | 3 | return $carbonDate->format('Y-m-d'); |
|
| 28 | } |
||
| 29 | |||
| 30 | // JPAS |
||
| 31 | if ($carbonDate = \DateTime::createFromFormat('n/j/Y G:i', $date)) { |
||
| 32 | return $carbonDate->format('Y-m-d'); |
||
| 33 | } |
||
| 34 | |||
| 35 | return null; |
||
| 36 | } |
||
| 37 | } |
||
| 38 |
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
dieintroduces 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 withthrowat this point:These limitations lead to logical operators rarely being of use in current PHP code.