Passed
Pull Request — master (#10)
by Anton
04:10
created

Foreign   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getAction() 0 6 2
A __construct() 0 8 3
A statement() 0 8 3
1
<?php
2
3
namespace Modules\Entitizer\Utils\Definition\Item {
4
5
	use Modules\Entitizer\Utils\Definition;
6
7
	class Foreign extends Definition\Item {
8
9
		protected $table = '', $field = '', $delete = null, $update = null;
10
11
		# Get action
12
13
		private function getAction(string $value) {
14
15
			$value = strtoupper($value); $range = ['CASCADE', 'RESTRICT', 'SET NULL'];
16
17
			return (in_array($value, $range, true) ? $value : null);
18
		}
19
20
		# Constructor
21
22
		public function __construct(string $name, string $table, string $field, string $delete = null, string $update = null) {
23
24
			$this->name = $name; $this->table = $table; $this->field = $field;
25
26
			if (null !== $delete) $this->delete = $this->getAction($delete);
27
28
			if (null !== $update) $this->update = $this->getAction($delete);
29
		}
30
31
		# Get statement
32
33
		public function statement() {
34
35
			return ("FOREIGN KEY (`" . $this->name . "`) REFERENCES `" . $this->table . "` (`" . $this->field . "`)") .
36
37
				   ((null !== $this->delete) ? (" ON DELETE " . $this->delete) : "") .
38
39
				   ((null !== $this->update) ? (" ON UPDATE " . $this->update) : "");
40
		}
41
	}
42
}
43