Completed
Pull Request — master (#30)
by
unknown
03:52
created

ValuePart::unsetValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
namespace gossi\codegen\model\parts;
3
4
/**
5
 * Value part
6
 *
7
 * For all models that have a value (or expression)
8
 *
9
 * @author Thomas Gossmann
10
 */
11
trait ValuePart {
12
13
	/** @var mixed */
14
	private $value;
15
16
	/** @var bool */
17
	private $hasValue = false;
18
19
	/** @var string */
20
	private $expression;
21
22
	/** @var bool */
23
	private $hasExpression = false;
24
25
	/**
26
	 * @deprecated use `setValue()` instead
27
	 * @param mixed $value
28
	 * @return $this
29
	 */
30
	public function setDefaultValue($value) {
31
		return $this->setValue($value);
32
	}
33
34
	/**
35
	 * @deprecated use `unsetValue()` instead
36
	 * @return $this
37
	 */
38
	public function unsetDefaultValue() {
39
		return $this->unsetValue();
40
	}
41
42
	/**
43
	 * @deprecated use `getValue()` instead
44
	 * @return mixed
45
	 */
46
	public function getDefaultValue() {
47
		return $this->getValue();
48
	}
49
50
	/**
51
	 * @deprecated use `hasValue()` instead
52
	 * @return bool
53
	 */
54
	public function hasDefaultValue() {
55
		return $this->hasValue();
56
	}
57
58
	/**
59
	 * Sets the value
60
	 *
61
	 * @param mixed $value
62
	 * @return $this
63
	 */
64 21
	public function setValue($value) {
65 21
		$this->value = $value;
66 21
		$this->hasValue = true;
67
68 21
		return $this;
69
	}
70
71
	/**
72
	 * Unsets the value
73
	 *
74
	 * @return $this
75
	 */
76 1
	public function unsetValue() {
77 1
		$this->value = null;
78 1
		$this->hasValue = false;
79
80 1
		return $this;
81
	}
82
83
	/**
84
	 * Returns the value
85
	 *
86
	 * @return mixed
87
	 */
88 14
	public function getValue() {
89 14
		return $this->value;
90
	}
91
92
	/**
93
	 * Checks whether a value or expression is set
94
	 *
95
	 * @return bool
96
	 */
97 20
	public function hasValue() {
98 20
		return $this->hasValue || $this->hasExpression;
99
	}
100
101
	/**
102
	 * Returns whether an expression is set
103
	 *
104
	 * @return bool
105
	 */
106 10
	public function isExpression() {
107 10
		return $this->hasExpression;
108
	}
109
110
	/**
111
	 * Sets an expression
112
	 *
113
	 * @param string $expr
114
	 * @return $this
115
	 */
116 9
	public function setExpression($expr) {
117 9
		$this->expression = $expr;
118 9
		$this->hasExpression = true;
119
120 9
		return $this;
121
	}
122
123
	/**
124
	 * Returns the expression
125
	 *
126
	 * @return string
127
	 */
128 5
	public function getExpression() {
129 5
		return $this->expression;
130
	}
131
132
	/**
133
	 * Unsets the expression
134
	 *
135
	 * @return $this
136
	 */
137 1
	public function unsetExpression() {
138 1
		$this->expression = null;
139 1
		$this->hasExpression = false;
140
141 1
		return $this;
142
	}
143
}
144