Passed
Push — 3.x ( 885785...4e5cb3 )
by Aleksei
01:36
created

Column::getType()   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
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Annotated\Annotation;
6
7
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
8
use Doctrine\Common\Annotations\Annotation\Target;
9
use JetBrains\PhpStorm\ExpectedValues;
10
11
/**
12
 * @Annotation
13
 * @NamedArgumentConstructor
14
 * @Target({"PROPERTY", "ANNOTATION", "CLASS"})
15
 */
16
#[
17
    \Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE),
18
    NamedArgumentConstructor
19
]
20
final class Column
21
{
22
    private bool $hasDefault = false;
23
24
    /**
25
     * @param non-empty-string $type Column type. {@see \Cycle\Database\Schema\AbstractColumn::$mapping}
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
26
     * @param non-empty-string|null $name Column name. Defaults to the property name.
27
     * @param non-empty-string|null $property Property that belongs to column. For virtual columns.
28
     * @param bool $primary Explicitly set column as a primary key.
29
     * @param bool $nullable Set column as nullable.
30
     * @param mixed|null $default Default column value.
31
     * @param non-empty-string|null $typecast Column typecast function.
32
     *        Defaults to one of (int|float|bool|datetime) based on column type
33
     * @param bool $castDefault
34
     */
35 468
    public function __construct(
36
        #[ExpectedValues(values: ['primary', 'bigPrimary', 'enum', 'boolean', 'integer', 'tinyInteger', 'bigInteger',
37
            'string', 'text', 'tinyText', 'longText', 'double', 'float', 'decimal', 'datetime', 'date', 'time',
38
            'timestamp', 'binary', 'tinyBinary', 'longBinary', 'json',
39
        ])]
40
        private string $type,
41
        private ?string $name = null,
42
        private ?string $property = null,
43
        private bool $primary = false,
44
        private bool $nullable = false,
45
        private mixed $default = null,
46
        private mixed $typecast = null,
47
        private bool $castDefault = false,
48
    ) {
49 468
        if ($default !== null) {
50 248
            $this->hasDefault = true;
51
        }
52 468
    }
53
54 468
    public function getType(): ?string
55
    {
56 468
        return $this->type;
57
    }
58
59 468
    public function getColumn(): ?string
60
    {
61 468
        return $this->name;
62
    }
63
64 236
    public function getProperty(): ?string
65
    {
66 236
        return $this->property;
67
    }
68
69 468
    public function isNullable(): bool
70
    {
71 468
        return $this->nullable;
72
    }
73
74 468
    public function isPrimary(): bool
75
    {
76 468
        return $this->primary;
77
    }
78
79 468
    public function hasDefault(): bool
80
    {
81 468
        return $this->hasDefault;
82
    }
83
84 248
    public function getDefault(): mixed
85
    {
86 248
        return $this->default;
87
    }
88
89 468
    public function castDefault(): bool
90
    {
91 468
        return $this->castDefault;
92
    }
93
94 468
    public function getTypecast(): mixed
95
    {
96 468
        return $this->typecast;
97
    }
98
}
99