Completed
Push — master ( 692093...daa27a )
by Vitaly
02:57
created

InjectableArgumentConfigurator::toMethodMetadata()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 28
Code Lines 16

Duplication

Lines 16
Ratio 57.14 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 16
loc 28
ccs 0
cts 15
cp 0
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 16
nc 3
nop 1
crap 12
1
<?php declare(strict_types = 1);
2
/**
3
 * Created by Vitaly Iegorov <[email protected]>.
4
 * on 07.08.16 at 15:46
5
 */
6
namespace samsonframework\container\configurator;
7
8
use samsonframework\container\metadata\MethodMetadata;
9
10
/**
11
 * Method argument injection configurator.
12
 *
13
 * @author Vitaly Egorov <[email protected]>
14
 */
15
class InjectableArgumentConfigurator extends InjectableAbstractConfigurator implements MethodConfiguratorInterface
16
{
17
    /**
18
     * {@inheritdoc}
19
     *
20
     * @throws \InvalidArgumentException
21
     */
22
    public function toMethodMetadata(MethodMetadata $methodMetadata)
23
    {
24
        // Check for argument name input and validity
25 View Code Duplication
        if (!$this->checkArgumentExists($this->argumentName, $methodMetadata)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
            throw new \InvalidArgumentException(
27
                '@InjectArgument argument "'
28
                . $methodMetadata->classMetadata->className . '::'
29
                . $methodMetadata->name . ' '
30
                . $this->argumentName . '" does not exists'
31
            );
32
        }
33
34
        // Check for type input
35 View Code Duplication
        if ($this->argumentType === null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
            throw new \InvalidArgumentException(
37
                '@InjectArgument argument "'
38
                . $methodMetadata->classMetadata->className . '::'
39
                . $methodMetadata->name . ' '
40
                . $this->argumentName . '" type not specified'
41
            );
42
        }
43
44
        // Store dependency with fully qualified type name
45
        $methodMetadata->dependencies[$this->argumentName] = $this->buildFullClassName(
46
            $this->argumentType,
47
            $methodMetadata->classMetadata->nameSpace
48
        );
49
    }
50
51
    /**
52
     * Check method argument existance.
53
     *
54
     * @param string         $argument
55
     * @param MethodMetadata $methodMetadata
56
     *
57
     * @return bool True if @InjectArgument argument name is valid
58
     */
59
    protected function checkArgumentExists(string $argument, MethodMetadata $methodMetadata) : bool
60
    {
61
        return $argument !== null && array_key_exists($argument, $methodMetadata->parametersMetadata);
62
    }
63
}
64