Completed
Branch 0.2.1 (e70612)
by Anton
09:15
created

Definition   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 1
dl 34
loc 34
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 10 10 3

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 Modules\Entitizer {
4
5
	use Exception;
6
7 View Code Duplication
	abstract class Definition {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
8
9
		private static $error_message = 'Entity definition does not exist';
10
11
		# Objects cache
12
13
		protected static $cache = [];
14
15
		# Definitions classes
16
17
		protected static $classes = [
18
19
			ENTITY_TYPE_PAGE                => 'Modules\Entitizer\Definition\Page',
20
			ENTITY_TYPE_MENUITEM            => 'Modules\Entitizer\Definition\Menuitem',
21
			ENTITY_TYPE_VARIABLE            => 'Modules\Entitizer\Definition\Variable',
22
			ENTITY_TYPE_WIDGET              => 'Modules\Entitizer\Definition\Widget',
23
			ENTITY_TYPE_USER                => 'Modules\Entitizer\Definition\User',
24
			ENTITY_TYPE_USER_SECRET         => 'Modules\Entitizer\Definition\User\Secret',
25
			ENTITY_TYPE_USER_SESSION        => 'Modules\Entitizer\Definition\User\Session'
26
		];
27
28
		# Get definition
29
30
		public static function get(string $type) {
31
32
			if (!isset(self::$classes[$type])) throw new Exception\General(self::$error_message);
33
34
			$cached = isset(self::$cache[$type]);
35
36
			# ------------------------
37
38
			return (!$cached ? (self::$cache[$type] = new self::$classes[$type]) : self::$cache[$type]);
39
		}
40
	}
41
}
42