Passed
Push — 1.x ( 5002a5...60cc56 )
by butschster
02:42
created

BaseModifier::compute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
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
    /**
17
     * @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...
18
     */
19
    abstract protected function getListenerClass(): string;
20
21
    /**
22
     * @return array<string, mixed>
23
     */
24
    abstract protected function getListenerArgs(): array;
25
26
    public function compute(Registry $registry): void
27
    {
28
    }
29
30
    public function render(Registry $registry): void
31
    {
32
    }
33
34 112
    final public function withRole(string $role): static
35
    {
36 112
        $clone = clone $this;
37 112
        $clone->role = $role;
38 112
        return $clone;
39
    }
40
41 96
    final public function modifySchema(array &$schema): void
42
    {
43
        // todo: compare with default constructor values
44 96
        $args = $this->getListenerArgs();
45 96
        if ($args === []) {
46
            $schema[SchemaInterface::LISTENERS][] = $this->getListenerClass();
47
            return;
48
        }
49 96
        $schema[SchemaInterface::LISTENERS][] = [
50 96
            ListenerProvider::DEFINITION_CLASS => $this->getListenerClass(),
51
            ListenerProvider::DEFINITION_ARGS => $args,
52
        ];
53
    }
54
}
55