Singleton::initializes()
last analyzed

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
nc 1
dl 0
loc 1
c 0
b 0
f 0
1
<?php 
2
3
namespace WPDFI\Traits;
4
5
/**
6
 * Trait for single instance using in this plugin
7
 *
8
 * @author Duc Bui Quang <[email protected]>
9
 * @since 1.0.0
10
 */
11
12
Trait Singleton
13
{
14
	/**
15
	 * Singleton instance of this class.
16
	 *
17
	 * @since   1.0.0
18
	 * @var     \WPDFI\Traits\Singleton
19
	 */
20
	protected static $instance = null;
21
22
	/**
23
	 * Constructor
24
	 *
25
	 * @since 1.0.0
26
	 * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
27
	 */ 
28
	protected function __construct() {
29
		$this->initializes();
30
	}
31
32
	/**
33
	 * Creates or returns an instance of this class.
34
	 *
35
	 * @since   1.0.0
36
	 * @return  WPDFI\Traits\Singleton A single instance of this class.
37
	 */
38
	public static function instance() {
39
		if ( null === self::$instance ) {
40
			self::$instance = new self();
41
		}
42
		return self::$instance;
43
	}
44
45
	/**
46
	 * All Initialize actions come here
47
	 *
48
	 * @since 1.0.0
49
	 * @return void
50
	 */
51
	abstract public function initializes();
52
}
53