Completed
Push — master ( 3b73d9...1ded02 )
by Stefano
03:20
created

Deferred   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

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 {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
14
15
	protected $callback,
0 ignored issues
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
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
}