Passed
Pull Request — master (#58)
by Sergei
12:07 queued 09:37
created

LazyDefinition::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Definitions;
6
7
use ProxyManager\Factory\LazyLoadingValueHolderFactory;
8
use Psr\Container\ContainerInterface;
9
use Yiisoft\Definitions\Contract\DefinitionInterface;
10
use Yiisoft\Di\Helpers\DefinitionNormalizer;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Di\Helpers\DefinitionNormalizer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
12
final class LazyDefinition implements DefinitionInterface
13
{
14 3
    public function __construct(
15
        private mixed $definition,
16
        private string $objectClass,
17
    ) {
18 3
    }
19
20 3
    public function resolve(ContainerInterface $container): mixed
21
    {
22 3
        $factory = $container->get(LazyLoadingValueHolderFactory::class);
23 3
        $definition = $this->definition;
24 3
        $objectClass = $this->objectClass;
25
26 3
        return $factory->createProxy(
27 3
            $objectClass,
28 3
            function (&$wrappedObject) use ($container, $objectClass, $definition) {
29
                $definition = DefinitionNormalizer::normalize($definition, $objectClass);
30
                $wrappedObject = $definition->resolve($container);
31 3
            }
32 3
        );
33
    }
34
}
35