Test Failed
Pull Request — master (#78)
by Dmitriy
12:33
created

ServiceDefinition::setProperties()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
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 string $class;
14
    private array $calls = [];
15
16
    public static function for(string $class): self
17
    {
18
        $definition = new self();
19
        $definition->class = $class;
20
        return $definition;
21
    }
22
23
    public function constructor(array $arguments): self
24
    {
25
        $this->constructorArguments = $arguments;
26
        return $this;
27
    }
28
29
    public function callMethod(string $method, array $arguments = []): self
30
    {
31
        $this->calls[$method] = $arguments;
32
        return $this;
33
    }
34
35
    public function callMethods(array $properties): self
36
    {
37
        foreach ($properties as $property => $value) {
38
            $this->callMethod($property, $value);
39
        }
40
        return $this;
41
    }
42
43
    public function setProperty(string $property, mixed $value): self
44
    {
45
        $this->calls[$property] = $value;
46
        return $this;
47
    }
48
49
    public function setProperties(array $properties): self
50
    {
51
        foreach ($properties as $property => $value) {
52
            $this->setProperty($property, $value);
53
        }
54
        return $this;
55
    }
56
57
    public function resolve(ContainerInterface $container): mixed
58
    {
59
        $config = [
60
            ArrayDefinition::CLASS_NAME => $this->class,
61
            ArrayDefinition::CONSTRUCTOR => $this->constructorArguments,
62
            ...$this->calls,
63
        ];
64
        return ArrayDefinition::fromConfig($config)->resolve($container);
65
    }
66
67
    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

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