MethodCreator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 16
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromMethod() 0 7 3
1
<?php
2
3
namespace evelikto\di\creator;
4
use evelikto\di\Bean;
5
6
/** Creates dependency if config class has factory method named $name */
7
trait MethodCreator
8
{
9
    /**
10
     * Resolves dependency from a factory method.
11
     * Method parameters will be autowired.
12
     *
13
     * @param   string  $name  Name of the factory method
14
     * @return  Bean|null      Wrapped factory method result or null if no such factory
15
     */
16
    protected function fromMethod(string $name) {
17
        if (method_exists($this->config, $name) === false)
18
            return null;
19
20
        $method = $this->configReflClass->getMethod($name);
21
        $value = $this->config->$name(...$this->autowire($method));
0 ignored issues
show
Bug introduced by
It seems like autowire() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

21
        $value = $this->config->$name(...$this->/** @scrutinizer ignore-call */ autowire($method));
Loading history...
22
        return ($value instanceof Bean) ? $value : new Bean($name, $value);
23
    }
24
}