Completed
Push — master ( 92472c...fe56a0 )
by Vitaly
02:18
created

Inject   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 33
Duplicated Lines 18.18 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 2
Metric Value
wmc 9
c 5
b 0
f 2
lcom 1
cbo 3
dl 6
loc 33
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toMethodMetadata() 0 4 1
C toPropertyMetadata() 6 23 8

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
2
/**
3
 * Created by PhpStorm.
4
 * User: root
5
 * Date: 27.07.2016
6
 * Time: 1:55.
7
 */
8
namespace samsonframework\container\annotation;
9
10
use samsonframework\container\metadata\MethodMetadata;
11
use samsonframework\container\metadata\PropertyMetadata;
12
13
/**
14
 * Injection annotation class.
15
 *
16
 * @Annotation
17
 */
18
class Inject extends CollectionValue implements MethodInterface, PropertyInterface
19
{
20
    /** {@inheritdoc} */
21 1
    public function toMethodMetadata(MethodMetadata $metadata)
22
    {
23 1
        $metadata->dependencies = $this->collection;
0 ignored issues
show
Bug introduced by
The property dependencies does not seem to exist in samsonframework\container\metadata\MethodMetadata.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
24 1
    }
25
26
    /** {@inheritdoc} */
27 4
    public function toPropertyMetadata(PropertyMetadata $propertyMetadata)
28
    {
29
        // Get @Inject("value")
30 4
        $propertyMetadata->injectable = array_shift($this->collection);
31
32
        // Check if we need to append namespace to injectable
33 4 View Code Duplication
        if ($propertyMetadata->injectable !== null && strpos($propertyMetadata->injectable, '\\') === false) {
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...
34 1
            $propertyMetadata->injectable = $propertyMetadata->classMetadata->nameSpace . '\\' . $propertyMetadata->injectable;
35 1
        }
36
37
        // Check if we need to append namespace to type hint
38 4 View Code Duplication
        if ($propertyMetadata->typeHint !== null && strpos($propertyMetadata->typeHint, '\\') === false) {
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...
39 1
            $propertyMetadata->typeHint = $propertyMetadata->classMetadata->nameSpace . '\\' . $propertyMetadata->typeHint;
40 1
        }
41
42
        // Check for inheritance violation
43 4
        if ($propertyMetadata->injectable !== null && $propertyMetadata->typeHint !== null) {
44 3
            $inheritance = array_merge([$propertyMetadata->injectable], class_parents($propertyMetadata->injectable));
45 3
            if (!in_array($propertyMetadata->typeHint, $inheritance, true)) {
46 1
                throw new \InvalidArgumentException('@Inject dependency violates ' . $propertyMetadata->typeHint . ' inheritance');
47
            }
48 2
        }
49 3
    }
50
}
51