Passed
Push — master ( d32d3d...0995a0 )
by Andrea Marco
02:44 queued 12s
created

HasFlags::getDefaultFlags()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Cerbero\Dto\Traits;
4
5
use const Cerbero\Dto\ARRAY_DEFAULT_TO_EMPTY_ARRAY;
0 ignored issues
show
Bug introduced by
The constant Cerbero\Dto\ARRAY_DEFAULT_TO_EMPTY_ARRAY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
6
use const Cerbero\Dto\BOOL_DEFAULT_TO_FALSE;
0 ignored issues
show
Bug introduced by
The constant Cerbero\Dto\BOOL_DEFAULT_TO_FALSE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
7
use const Cerbero\Dto\NONE;
0 ignored issues
show
Bug introduced by
The constant Cerbero\Dto\NONE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
8
use const Cerbero\Dto\NULLABLE_DEFAULT_TO_NULL;
0 ignored issues
show
Bug introduced by
The constant Cerbero\Dto\NULLABLE_DEFAULT_TO_NULL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
9
10
/**
11
 * Trait to interact with flags.
12
 *
13
 */
14
trait HasFlags
15
{
16
    /**
17
     * The default flags.
18
     *
19
     * @var int
20
     */
21
    protected static $defaultFlags = NONE;
22
23
    /**
24
     * The actual flags.
25
     *
26
     * @var int
27
     */
28
    protected $flags;
29
30
    /**
31
     * Retrieve the default flags
32
     *
33
     * @return int
34
     */
35 192
    public static function getDefaultFlags(): int
36
    {
37 192
        return static::$defaultFlags;
38
    }
39
40
    /**
41
     * Retrieve the DTO flags
42
     *
43
     * @return int
44
     */
45 189
    public function getFlags(): int
46
    {
47 189
        return $this->flags;
48
    }
49
50
    /**
51
     * Retrieve the DTO flags excluding the flags for default values
52
     *
53
     * @return int
54
     */
55 12
    protected function getFlagsWithoutDefaults(): int
56
    {
57 12
        $flags = $this->getFlags();
58 12
        $flagsForDefaults = NULLABLE_DEFAULT_TO_NULL | BOOL_DEFAULT_TO_FALSE | ARRAY_DEFAULT_TO_EMPTY_ARRAY;
59
60 12
        return $flags ^ ($flags & $flagsForDefaults);
61
    }
62
}
63