Test Failed
Pull Request — master (#78)
by Dmitriy
03:55 queued 01:26
created

ServiceDefinition::call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Definitions;
6
7
use Psr\Container\ContainerInterface;
8
use Yiisoft\Definitions\Contract\DefinitionInterface;
9
10
final class ServiceDefinition implements DefinitionInterface
11
{
12
    private array $calls = [];
13
14
    private function __construct(
15
        private string $class,
16
        private array $constructor = [],
17
    ) {
18
    }
19
20
    public static function for(string $class, array $constructor = []): self
21
    {
22
        return new self($class, $constructor);
23
    }
24
25
    public function constructor(array $arguments): self
26
    {
27
        $this->constructor = $arguments;
28
        return $this;
29
    }
30
31
    public function call(string $method, array $arguments = []): self
32
    {
33
        $this->calls[$method . '()'] = $arguments;
34
        return $this;
35
    }
36
37
    public function calls(array $methods): self
38
    {
39
        foreach ($methods as $method => $arguments) {
40
            $this->call($method, $arguments);
41
        }
42
        return $this;
43
    }
44
45
    public function set(string $property, mixed $value): self
46
    {
47
        $this->calls['$' . $property] = $value;
48
        return $this;
49
    }
50
51
    public function sets(array $properties): self
52
    {
53
        foreach ($properties as $property => $value) {
54
            $this->set($property, $value);
55
        }
56
        return $this;
57
    }
58
59
    public function resolve(ContainerInterface $container): mixed
60
    {
61
        $config = [
62
            ArrayDefinition::CLASS_NAME => $this->class,
63
            ArrayDefinition::CONSTRUCTOR => $this->constructor,
64
            ...$this->calls,
65
        ];
66
        return ArrayDefinition::fromConfig($config)->resolve($container);
67
    }
68
69
    public function merge(self $other)
0 ignored issues
show
Unused Code introduced by
The parameter $other is not used and could be removed. ( Ignorable by Annotation )

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

69
    public function merge(/** @scrutinizer ignore-unused */ self $other)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
    {
71
        // TBD
72
    }
73
}
74