| Conditions | 5 |
| Paths | 6 |
| Total Lines | 17 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 30 |
| Changes | 0 | ||
| 1 | <?php |
||
| 9 | public function lock($key, $ttl) |
||
| 10 | { |
||
| 11 | if($this->locked){ |
||
| 12 | \PhpBoot\abort("relock $key"); |
||
| 13 | } |
||
| 14 | $path = sys_get_temp_dir().'/lock_252a8fdc9b944af99a9bc53d2aea08f1_'.$key; |
||
| 15 | $this->file = @fopen($path, 'a'); |
||
| 16 | if (!$this->file || !flock($this->file, LOCK_EX | LOCK_NB)) { |
||
| 17 | if($this->file){ |
||
| 18 | fclose($this->file); |
||
| 19 | } |
||
| 20 | return false; |
||
| 21 | } else { |
||
| 22 | $this->locked = true; |
||
| 23 | } |
||
| 24 | return true; |
||
| 25 | } |
||
| 26 | |||
| 37 | } |
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.