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

Index::statement()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
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