GeneratedValue   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 21
rs 10
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B getFlags() 0 10 7
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