EntityOptions::__set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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
use Maslosoft\Mangan\Traits\Defaults\MongoClientOptions;
21
22
/**
23
 * EntityOptions
24
 *
25
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
26
 */
27
class EntityOptions
28
{
29
30
	use MongoClientOptions;
31
32
	/**
33
	 *
34
	 * @var Mangan
35
	 */
36
	private $_mangan = null;
37
38
	/**
39
	 * Values of this instance
40
	 * @var mixed[]
41
	 */
42
	private $_values = [];
43
	private $_defaults = [];
44
45 137
	public function __construct($model)
46
	{
47
		// This is to use get/set
48 137
		foreach ($this->_getOptionNames() as $name)
49
		{
50 137
			PropertyMaker::defineProperty($this, $name, $this->_defaults);
51
		}
52
53 137
		foreach (ManganMeta::create($model)->type()->clientFlags as $name => $value)
54
		{
55 1
			$this->_values[$name] = $value;
56
		}
57 137
		$this->_mangan = Mangan::fromModel($model);
58 137
	}
59
60 3
	public function __get($name)
61
	{
62 3
		if (array_key_exists($name, $this->_values))
63
		{
64 3
			return $this->_values[$name]; // We have flag set, return it
65
		}
66 1
		return $this->_mangan->$name;
67
	}
68
69 2
	public function __set($name, $value)
70
	{
71 2
		$this->_values[$name] = $value;
72 2
	}
73
74
	public function __unset($name)
75
	{
76
		unset($this->_values[$name]);
77
	}
78
79
	public function __isset($name)
80
	{
81
		return isset($this->_values[$name]);
82
	}
83
84 126
	public function getSaveOptions($extraOptions = [])
85
	{
86 126
		return $extraOptions;
87
		$result = [];
0 ignored issues
show
Unused Code introduced by
$result = array(); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
88
		foreach ($this->_getOptionNames() as $name)
89
		{
90
			$result[$name] = $this->$name;
91
		}
92
		foreach ($extraOptions as $name => $value)
93
		{
94
			$result[$name] = $value;
95
		}
96
		return $result;
97
	}
98
99
}
100