Passed
Pull Request — master (#17)
by Anton
03:14
created

Index   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validateType() 0 6 2
A __construct() 0 6 2
A getStatement() 0 6 2
1
<?php
2
3
/**
4
 * @package Cadmium\System\Modules\Entitizer
5
 * @author Anton Romanov
6
 * @copyright Copyright (c) 2015-2017, Anton Romanov
7
 * @link http://cadmium-cms.com
8
 */
9
10
namespace Modules\Entitizer\Utils\Definition\Item {
11
12
	use Modules\Entitizer\Utils\Definition;
13
14
	class Index extends Definition\Item {
15
16
		protected $type = null;
17
18
		/**
19
		 * Validate a type value
20
		 *
21
		 * @return string|null : the type or null if the value is invalid
22
		 */
23
24
		private function validateType(string $value) {
25
26
			$value = strtoupper($value); $range = ['PRIMARY', 'UNIQUE', 'FULLTEXT'];
27
28
			return (in_array($value, $range, true) ? $value : null);
29
		}
30
31
		/**
32
		 * Constructor
33
		 */
34
35
		public function __construct(string $name, string $type = null) {
36
37
			$this->name = $name;
38
39
			if (null !== $type) $this->type = $this->validateType($type);
40
		}
41
42
		/**
43
		 * Get the statement
44
		 */
45
46
		public function getStatement() : string {
47
48
			return ((null !== $this->type) ? ($this->type . " ") : "") .
49
50
			       ("KEY `" . $this->name . "` (`" . $this->name . "`)");
51
		}
52
	}
53
}
54