Deferred   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A disarm() 0 3 1
A prime() 0 3 1
A __destruct() 0 3 2
1
<?php
2
3
/**
4
 * Deferred
5
 *
6
 * Run callback when script execution is stopped.
7
 *
8
 * @package core
9
 * @author [email protected]
10
 * @copyright Caffeina srl - 2016 - http://caffeina.com
11
 */
12
13
class Deferred {
14
15
	protected $callback,
16
            $enabled = true;
17
18
	public function __construct( callable $callback ) {
19
		$this->callback = $callback;
20
	}
21
22
  public function disarm() {
23
    $this->enabled = false;
24
  }
25
26
  public function prime() {
27
    $this->enabled = true;
28
  }
29
30
	public function __destruct() {
31
		if ( $this->enabled ) call_user_func( $this->callback );
32
	}
33
34
}