Completed
Push — master ( eef885...465d0c )
by
unknown
30:08 queued 12:49
created

Singleton_Util   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
construct() 0 1 ?
B g() 0 11 5
1
<?php
2
/**
3
 * Le singleton
4
 *
5
 * @package Evarisk\Plugin
6
 */
7
8
namespace eoxia;
9
10
if ( ! defined( 'ABSPATH' ) ) {
11
	exit;
12
}
13
14
if ( ! class_exists( '\eoxia\Singleton_Util' ) ) {
15
	/**
16
	 * Le singleton
17
	 *
18
	 * @author Jimmy Latour <[email protected]>
19
	 * @version 1.1.0.0
20
	 */
21
	abstract class Singleton_Util {
22
		/**
23
		 * L'instance courant du singleton
24
		 *
25
		 * @var \eoxia\Singleton_Util
26
		 */
27
		protected static $instance;
28
29
		/**
30
		 * Appelle le constructeur parent
31
		 */
32
		protected final function __construct() {
33
			$this->construct();
34
		}
35
36
		/**
37
		 * Le constructeur pour les enfants
38
		 *
39
		 * @return void nothing
40
		 */
41
		abstract protected function construct();
42
43
		/**
44
		 * Récupères l'instance courante
45
		 *
46
		 * @return \eoxia\Singleton_Util L'instance courante
47
		 */
48
		final public static function g() {
49
			if ( ! isset( self::$instance ) || get_called_class() !== get_class( self::$instance ) ) {
50
				$class_name = get_called_class();
51
				$new_instance = new $class_name();
52
				// extending classes can set $instance to any value, so check to make sure it's still unset before giving it the default value.
53
				if ( ! isset( self::$instance ) || get_called_class() !== get_class( self::$instance ) ) {
54
					self::$instance = $new_instance;
55
				}
56
			}
57
			return self::$instance;
58
		}
59
	}
60
} // End if().
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
61