Completed
Push — master ( 2d1bc2...dd293e )
by Peter
06:06
created

NullableAnnotation   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 2
dl 0
loc 11
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A init() 0 4 1
1
<?php
2
3
4
namespace Maslosoft\Mangan\Annotations;
5
6
use Maslosoft\Mangan\Meta\ManganPropertyAnnotation;
7
8
/**
9
 * If true, value will be set to `null` **only** if it is one of:
10
 *
11
 * 1. Empty string
12
 * 2. `null`
13
 * 3. Empty array
14
 * 4. Integer `0`
15
 * 5. Float `0.0`
16
 * 6. Boolean `false`
17
 * 7. String `"0"`
18
 *
19
 * This will use the PHP's built in `empty` construct.
20
 *
21
 * This annotation default to true, and using false might have sense
22
 * on on overridden properties.
23
 *
24
 * Example usage:
25
 *
26
 * ```php
27
 * @Nullable
28
 * ```
29
 *
30
 * Example of overriding nullable state:
31
 *
32
 * ```php
33
 * // On base class
34
 * @Nullable
35
 * // On inherited property
36
 * @Nullable(false)
37
 * ```
38
 *
39
 * @Target('property')
40
 * @template Persistent(${false})
41
 * @author Piotr
42
 */
43
class NullableAnnotation extends ManganPropertyAnnotation
44
{
45
46
	public $value = true;
47
48 1
	public function init()
49
	{
50 1
		$this->getEntity()->nullable = (bool) $this->value;
51 1
	}
52
53
}