Passed
Push — 3.x ( 42ab4a...bb376d )
by Aleksei
12:31 queued 16s
created

Entity::getForeignKeys()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\Annotated\Annotation;
6
7
use Doctrine\Common\Annotations\Annotation\Target;
8
use Spiral\Attributes\NamedArgumentConstructor;
9
10
/**
11
 * @Annotation
12
 *
13
 * @NamedArgumentConstructor
14
 *
15
 * @Target("CLASS")
16
 */
17
#[\Attribute(\Attribute::TARGET_CLASS), NamedArgumentConstructor]
18
final class Entity
19
{
20
    /**
21
     * @param non-empty-string|null $role Entity role. Defaults to the lowercase class name without a namespace.
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string|null at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string|null.
Loading history...
22
     * @param class-string|null $mapper Mapper class name. Defaults to {@see \Cycle\ORM\Mapper\Mapper}
23
     * @param class-string|null $repository Repository class to represent read operations for an entity.
24
     *        Defaults to {@see \Cycle\ORM\Select\Repository}
25
     * @param non-empty-string|null $table Entity source table. Defaults to plural form of entity role.
26
     * @param bool $readonlySchema Set to true to disable schema synchronization for the assigned table.
27
     * @param non-empty-string|null $database Database name. Defaults to null (default database).
28
     * @param class-string|null $source Entity source class (internal). Defaults to {@see \Cycle\ORM\Select\Source}
29
     * @param non-empty-string|non-empty-string[]|null $typecast
30
     * @param class-string|null $scope Class name of constraint to be applied to every entity query.
31 1056
     * @param Column[] $columns Entity columns.
32
     * @param ForeignKey[] $foreignKeys Entity foreign keys.
33
     */
34
    public function __construct(
35
        private ?string $role = null,
36
        private ?string $mapper = null,
37
        private ?string $repository = null,
38
        private ?string $table = null,
39
        private bool $readonlySchema = false,
40
        private ?string $database = null,
41
        private ?string $source = null,
42
        private array|string|null $typecast = null,
43
        private ?string $scope = null,
44
        private array $columns = [],
45 1056
        /** @deprecated Use {@see $scope} instead */
46
        private ?string $constrain = null,
47 1056
        private array $foreignKeys = [],
48
    ) {
49 1056
    }
50
51
    public function getRole(): ?string
52 1056
    {
53
        return $this->role;
54 1056
    }
55
56
    public function getMapper(): ?string
57 1056
    {
58
        return $this->mapper;
59 1056
    }
60
61
    public function getRepository(): ?string
62 1056
    {
63
        return $this->repository;
64 1056
    }
65
66
    public function getTable(): ?string
67 1056
    {
68
        return $this->table;
69 1056
    }
70
71
    public function isReadonlySchema(): bool
72 1056
    {
73
        return $this->readonlySchema;
74 1056
    }
75
76
    public function getDatabase(): ?string
77 1056
    {
78
        return $this->database;
79 1056
    }
80
81
    public function getSource(): ?string
82 1056
    {
83
        return $this->source;
84 1056
    }
85
86
    public function getScope(): ?string
87 1032
    {
88
        return $this->scope ?? $this->constrain;
89 1032
    }
90
91
    public function getColumns(): array
92 1056
    {
93
        return $this->columns;
94 1056
    }
95
96
    public function getForeignKeys(): array
97
    {
98 1056
        return $this->foreignKeys;
99
    }
100
101
    public function getTypecast(): array|string|null
102
    {
103
        if (is_array($this->typecast) && count($this->typecast) === 1) {
104
            return reset($this->typecast);
105
        }
106
107
        return $this->typecast;
108
    }
109
}
110