Passed
Push — 3.x ( bb376d...4024d2 )
by Aleksei
11:03
created

GeneratedValue::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Annotated\Annotation;
6
7
use Cycle\ORM\Schema\GeneratedField;
8
use Spiral\Attributes\NamedArgumentConstructor;
9
10
/**
11
 * @Annotation
12
 * @NamedArgumentConstructor
13
 * @Target({"PROPERTY"})
14
 */
15
#[\Attribute(\Attribute::TARGET_PROPERTY)]
16
#[NamedArgumentConstructor]
17
class GeneratedValue
18
{
19
    public function __construct(
20
        protected bool $beforeInsert = false,
21
        protected bool $onInsert = false,
22
        protected bool $beforeUpdate = false,
23
    ) {
24
    }
25
26
    public function getFlags(): ?int
27
    {
28
        if (!$this->beforeInsert && !$this->onInsert && !$this->beforeUpdate) {
29
            return null;
30
        }
31
32
        return
33
            ($this->beforeInsert ? GeneratedField::BEFORE_INSERT : 0) |
34
            ($this->onInsert ? GeneratedField::ON_INSERT : 0) |
35
            ($this->beforeUpdate ? GeneratedField::BEFORE_UPDATE : 0);
36
    }
37
}
38