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

BaseModifier   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 40
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A withRole() 0 5 1
A compute() 0 2 1
A render() 0 2 1
A modifySchema() 0 11 2
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