AbstractLeagueServiceProvider::shared()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Panamax\Providers\League;
4
5
use League\Container\ServiceProvider\AbstractServiceProvider;
6
use Psr\Container\ContainerInterface;
7
8
abstract class AbstractLeagueServiceProvider extends AbstractServiceProvider
9
{
10
    /**
11
     * {@inheritDoc}
12
     */
13
    public function provides(string $id): bool
14
    {
15
        return in_array($id, [
16
            $this->id(),
17
            ...$this->combinedAliases(),
18
            ...$this->combinedTags()
19
        ]);
20
    }
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function register(): void
26
    {
27
        $container = $this->getContainer();
28
        $definition = $container->add(
29
            $id = $this->id(),
30
            fn () => $this->service($container)
31
        );
32
33
        if (null !== $shared = $this->shared()) {
0 ignored issues
show
introduced by
The condition null !== $shared = $this->shared() is always true.
Loading history...
34
            $definition->setShared($shared);
35
        }
36
37
        foreach ($this->combinedAliases() as $alias) {
38
            $container->add($alias, $id);
0 ignored issues
show
Bug introduced by
$alias of type array is incompatible with the type string expected by parameter $id of League\Container\Definit...ntainerInterface::add(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
            $container->add(/** @scrutinizer ignore-type */ $alias, $id);
Loading history...
39
        }
40
41
        foreach ($this->combinedTags() as $tag) {
42
            $definition->addTag($tag);
43
        }
44
    }
45
46
    protected function combinedAliases(): array
47
    {
48
        return [...$this->types(), ...$this->aliases()];
49
    }
50
51
    protected function combinedTags(): array
52
    {
53
        return $this->tags();
54
    }
55
56
    protected function shared(): ?bool
57
    {
58
        return true;
59
    }
60
61
    /**
62
     * @return array<string>
63
     */
64
    protected function types(): array
65
    {
66
        return [];
67
    }
68
69
    /**
70
     * @return array<string>
71
     */
72
    protected function aliases(): array
73
    {
74
        return [];
75
    }
76
77
    /**
78
     * @return array<string>
79
     */
80
    protected function tags(): array
81
    {
82
        return [];
83
    }
84
85
    abstract protected function service(ContainerInterface $container);
86
87
    abstract protected function id(): string;
88
}
89