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

InjectableArgumentConfigurator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 32.65 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 16
loc 49
ccs 0
cts 17
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B toMethodMetadata() 16 28 3
A checkArgumentExists() 0 4 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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