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

ServiceDefinition   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A for() 0 5 1
A callMethod() 0 4 1
A setProperty() 0 4 1
A callMethods() 0 6 2
A setProperties() 0 6 2
A merge() 0 2 1
A resolve() 0 8 1
A constructor() 0 4 1
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