BaseModifier::withRole()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\ORM\Entity\Behavior\Schema;
6
7
use Cycle\ORM\Entity\Behavior\Dispatcher\ListenerProvider;
8
use Cycle\ORM\SchemaInterface;
9
use Cycle\Schema\Registry;
10
use Cycle\Schema\SchemaModifierInterface;
11
12
abstract class BaseModifier implements SchemaModifierInterface
13
{
14
    protected string $role;
15
16
    public function compute(Registry $registry): void {}
17
18
    public function render(Registry $registry): void {}
19
20
    final public function withRole(string $role): static
21
    {
22
        $clone = clone $this;
23
        $clone->role = $role;
24
        return $clone;
25
    }
26
27
    final public function modifySchema(array &$schema): void
28
    {
29
        // todo: compare with default constructor values
30
        $args = $this->getListenerArgs();
31
        if ($args === []) {
32
            $schema[SchemaInterface::LISTENERS][] = $this->getListenerClass();
33
            return;
34 112
        }
35
        $schema[SchemaInterface::LISTENERS][] = [
36 112
            ListenerProvider::DEFINITION_CLASS => $this->getListenerClass(),
37 112
            ListenerProvider::DEFINITION_ARGS => $args,
38 112
        ];
39
    }
40
41 96
    /**
42
     * @return class-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
43
     */
44 96
    abstract protected function getListenerClass(): string;
45 96
46
    /**
47
     * @return array<string, mixed>
48
     */
49 96
    abstract protected function getListenerArgs(): array;
50
}
51