Passed
Push — main ( fdba16...86b0c8 )
by Michael
11:57
created

BootsCallProxies   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
eloc 15
c 8
b 0
f 0
dl 0
loc 34
ccs 13
cts 14
cp 0.9286
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B bootCallProxies() 0 20 7
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MichaelRubel\EnhancedContainer\Traits;
6
7
use Illuminate\Support\Fluent;
8
9
trait BootsCallProxies
10
{
11
    /**
12
     * @var Fluent|null
13
     */
14
    protected ?Fluent $proxy = null;
15
16
    /**
17
     * Boots the fluent object of call proxies.
18
     *
19
     * @param string|null $method
20
     *
21
     * @return void
22
     */
23 3
    public function bootCallProxies(?string $method = null): void
24
    {
25 3
        $reflection = new \ReflectionClass(static::class);
26
27 3
        $method = is_null($method)
28 3
            ? $reflection->getConstructor()
29
            : $reflection->getMethod($method);
30
31 3
        $dependencies = $method->getParameters();
0 ignored issues
show
Bug introduced by
The method getParameters() does not exist on null. ( Ignorable by Annotation )

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

31
        /** @scrutinizer ignore-call */ 
32
        $dependencies = $method->getParameters();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32
33 3
        if (! empty($dependencies)) {
34 3
            $this->proxy = new Fluent();
35
36 3
            collect($dependencies)->map(function ($param) {
37 3
                $class = $param->getType()->getName();
38
39 3
                if (class_exists($class) || interface_exists($class)) {
40 3
                    property_exists(static::class, $param->getName()) && is_object($this->{$param->getName()})
41 2
                        ? $this->proxy->{$param->getName()} = call($this->{$param->getName()})
42 1
                        : $this->proxy->{$param->getName()} = call($class);
43
                }
44 3
            });
45
        }
46 3
    }
47
}
48