Completed
Push — 0.2.3 ( 4e241d...b4719c )
by Anton
06:36 queued 02:56
created

Fill::fill()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 24
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 24
rs 8.5125
c 1
b 0
f 1
cc 6
eloc 9
nc 8
nop 1
1
<?php
2
3
namespace Modules\Entitizer\Utils\Entity\Action {
4
5
	// use DB;
6
7
	trait Fill {
8
9
		protected $definition = null, $error = false, $id = 0, $data = [];
10
11
		# Fill entity with custom data
12
13
		public function fill(array $data) {
14
15
			if (0 !== $this->id) return false;
16
17
			$set = $this->definition->implement($data, true);
18
19
			if (!($set['id'] > 0)) return false;
20
21
			# Re-init entity
22
23
			$this->error = false; $this->id = $set['id'];
24
25
			foreach ($set as $name => $value) if ($name !== 'id') $this->data[$name] = $value;
26
27
			if (static::$nesting) $this->data['path'] = $this->getPath();
28
29
			# Implement entity
30
31
			$this->implement();
32
33
			# ------------------------
34
35
			return true;
36
		}
37
38
		# Get path interface
39
40
		abstract protected function getPath();
41
42
		# Implementor interface
43
44
		abstract protected function implement();
45
	}
46
}
47