Service   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 34.48 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 20
loc 58
ccs 0
cts 14
cp 0
c 0
b 0
f 0
wmc 5
lcom 1
cbo 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
disabled() 0 1 ?
enabled() 0 1 ?
A is_enabled() 0 3 1
A enable() 10 10 2
A disable() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Carbon_Fields\Service;
4
5
abstract class Service {
6
7
	/**
8
	 * Service enabled state
9
	 *
10
	 * @var boolean
11
	 */
12
	protected $enabled = false;
13
14
	/**
15
	 * Check whether the service is enabled
16
	 */
17
	public function is_enabled() {
18
		return $this->enabled;
19
	}
20
21
	/**
22
	 * Enable the service
23
	 *
24
	 * @return bool
25
	 */
26 View Code Duplication
	public function enable() {
27
		if ( $this->is_enabled() ) {
28
			return false;
29
		}
30
		$this->enabled = true;
31
32
		$this->enabled();
33
34
		return true;
35
	}
36
37
	/**
38
	 * Enable actions for inheriting classes
39
	 */
40
	abstract protected function enabled();
41
42
	/**
43
	 * Disable the service
44
	 *
45
	 * @return bool
46
	 */
47 View Code Duplication
	public function disable() {
48
		if ( ! $this->is_enabled() ) {
49
			return false;
50
		}
51
		$this->enabled = false;
52
53
		$this->disabled();
54
55
		return true;
56
	}
57
58
	/**
59
	 * Disable actions for inheriting classes
60
	 */
61
	abstract protected function disabled();
62
}