Passed
Push — main ( 86b0c8...d70237 )
by Michael
03:34
created

BootsCallProxies::bootCallProxies()   B

Complexity

Conditions 8
Paths 6

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 8

Importance

Changes 8
Bugs 0 Features 0
Metric Value
cc 8
eloc 14
c 8
b 0
f 0
nc 6
nop 1
dl 0
loc 22
ccs 15
cts 15
cp 1
crap 8
rs 8.4444
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 5
    public function bootCallProxies(?string $method = null): void
24
    {
25 5
        $reflection = new \ReflectionClass(static::class);
26
27 5
        $method = is_null($method)
28 4
            ? $reflection->getConstructor()
29 2
            : $reflection->getMethod($method);
30
31 5
        $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 5
        if (! empty($dependencies)) {
34 5
            if (! $this->proxy instanceof Fluent) {
35 5
                $this->proxy = new Fluent();
36
            }
37
38 5
            collect($dependencies)->map(function ($param) {
39 5
                $class = $param->getType()->getName();
40
41 5
                if (class_exists($class) || interface_exists($class)) {
42 5
                    property_exists(static::class, $param->getName()) && is_object($this->{$param->getName()})
43 3
                        ? $this->proxy->{$param->getName()} = call($this->{$param->getName()})
44 3
                        : $this->proxy->{$param->getName()} = call($class);
45
                }
46 5
            });
47
        }
48 5
    }
49
}
50