Completed
Push — master ( 6f46dc...2c5f1b )
by Peter
08:02 queued 11s
created

EntityOptions   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 80.77%

Importance

Changes 0
Metric Value
wmc 11
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 72
ccs 21
cts 26
cp 0.8077
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __set() 0 4 1
A __unset() 0 4 1
A __isset() 0 4 1
A __construct() 0 14 3
A __get() 0 8 2
A getSaveOptions() 0 13 3
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Options;
15
16
use Maslosoft\Mangan\Helpers\PropertyMaker;
17
use Maslosoft\Mangan\Mangan;
18
use Maslosoft\Mangan\Meta\DocumentTypeMeta;
19
use Maslosoft\Mangan\Meta\ManganMeta;
20
21
/**
22
 * EntityOptions
23
 *
24
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
25
 */
26
class EntityOptions
27
{
28
29
	use \Maslosoft\Mangan\Traits\Defaults\MongoClientOptions;
30
31
	/**
32
	 *
33
	 * @var Mangan
34
	 */
35
	private $_mangan = null;
36
37
	/**
38
	 * Values of this instance
39
	 * @var mixed[]
40
	 */
41
	private $_values = [];
42
	private $_defaults = [];
43
44 97
	public function __construct($model)
45
	{
46
		// This is to use get/set
47 97
		foreach ($this->_getOptionNames() as $name)
48
		{
49 97
			PropertyMaker::defineProperty($this, $name, $this->_defaults);
50
		}
51
52 97
		foreach (ManganMeta::create($model)->type()->clientFlags as $name => $value)
53
		{
54 1
			$this->_values[$name] = $value;
55
		}
56 97
		$this->_mangan = Mangan::fromModel($model);
57 97
	}
58
59 93
	public function __get($name)
60
	{
61 93
		if (array_key_exists($name, $this->_values))
62
		{
63 3
			return $this->_values[$name]; // We have flag set, return it
64
		}
65 91
		return $this->_mangan->$name;
66
	}
67
68 2
	public function __set($name, $value)
69
	{
70 2
		$this->_values[$name] = $value;
71 2
	}
72
73
	public function __unset($name)
74
	{
75
		unset($this->_values[$name]);
76
	}
77
78
	public function __isset($name)
79
	{
80
		return isset($this->_values[$name]);
81
	}
82
83 90
	public function getSaveOptions($extraOptions = [])
84
	{
85 90
		$result = [];
86 90
		foreach ($this->_getOptionNames() as $name)
87
		{
88 90
			$result[$name] = $this->$name;
89
		}
90 90
		foreach ($extraOptions as $name => $value)
91
		{
92 60
			$result[$name] = $value;
93
		}
94 90
		return $result;
95
	}
96
97
}
98