Test Failed
Pull Request — master (#78)
by Dmitriy
02:27
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 $constructorArguments = [];
13
    private array $calls = [];
14
15
    private function __construct(private string $class)
16
    {
17
    }
18
19
    public static function for(string $class): self
20
    {
21
        return new self($class);
22
    }
23
24
    public function constructor(array $arguments): self
25
    {
26
        $this->constructorArguments = $arguments;
27
        return $this;
28
    }
29
30
    public function call(string $method, array $arguments = []): self
31
    {
32
        $this->calls[$method . '()'] = $arguments;
33
        return $this;
34
    }
35
36
    public function calls(array $methods): self
37
    {
38
        foreach ($methods as $method => $arguments) {
39
            $this->call($method, $arguments);
40
        }
41
        return $this;
42
    }
43
44
    public function set(string $property, mixed $value): self
45
    {
46
        $this->calls['$' . $property] = $value;
47
        return $this;
48
    }
49
50
    public function sets(array $properties): self
51
    {
52
        foreach ($properties as $property => $value) {
53
            $this->set($property, $value);
54
        }
55
        return $this;
56
    }
57
58
    public function resolve(ContainerInterface $container): mixed
59
    {
60
        $config = [
61
            ArrayDefinition::CLASS_NAME => $this->class,
62
            ArrayDefinition::CONSTRUCTOR => $this->constructorArguments,
63
            ...$this->calls,
64
        ];
65
        return ArrayDefinition::fromConfig($config)->resolve($container);
66
    }
67
68
    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

68
    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...
69
    {
70
        // TBD
71
    }
72
}
73