Completed
Push — master ( 2958af...77ccc9 )
by JHONATAN
02:21
created

TransferMetadata   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 66
Duplicated Lines 21.21 %

Test Coverage

Coverage 93.55%

Importance

Changes 0
Metric Value
wmc 7
dl 14
loc 66
ccs 29
cts 31
cp 0.9355
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A addPropertyMetadata() 0 15 4
A getAssociation() 0 3 1
A serialize() 0 11 1
A unserialize() 14 14 1

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
namespace Vox\Webservice\Metadata;
4
5
use Metadata\PropertyMetadata as BasePropertyMetadata;
6
use Vox\Metadata\ClassMetadata;
7
use Vox\Metadata\PropertyMetadata;
8
use Vox\Webservice\Mapping\Id;
9
10
class TransferMetadata extends ClassMetadata
11
{
12
    /**
13
     * @var PropertyMetadata
14
     */
15
    public $id;
16
    
17
    /**
18
     * @var PropertyMetadata
19
     */
20
    public $associations;
21
    
22 17
    public function addPropertyMetadata(BasePropertyMetadata $metadata)
23
    {
24 17
        if ($metadata instanceof PropertyMetadata) {
25 17
            if ($id = $metadata->getAnnotation(Id::class)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $id is dead and can be removed.
Loading history...
26 7
                $this->id = $metadata;
27
            }
28
        }
29
        
30 17
        parent::addPropertyMetadata($metadata);
31
        
32 17
        if ($metadata->hasAnnotation(\Vox\Webservice\Mapping\BelongsTo::class)) {
0 ignored issues
show
introduced by
The method hasAnnotation() does not exist on Metadata\PropertyMetadata. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

32
        if ($metadata->/** @scrutinizer ignore-call */ hasAnnotation(\Vox\Webservice\Mapping\BelongsTo::class)) {
Loading history...
33 1
            $this->associations[$metadata->name] = $metadata;
34
        }
35
        
36 17
        return $this;
37
    }
38
    
39
    /**
40
     * @param string $name
41
     * @return PropertyMetadata
42
     */
43
    public function getAssociation(string $name)
44
    {
45
        return $this->associations[$name] ?? null;
46
    }
47
    
48 4
    public function serialize()
49
    {
50 4
        return serialize(array(
51 4
            $this->name,
52 4
            $this->methodMetadata,
53 4
            $this->propertyMetadata,
54 4
            $this->fileResources,
55 4
            $this->createdAt,
56 4
            $this->annotations,
57 4
            $this->id,
58 4
            $this->associations,
59
        ));
60
    }
61
62 3 View Code Duplication
    public function unserialize($str)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
63
    {
64
        list(
65 3
            $this->name,
66 3
            $this->methodMetadata,
67 3
            $this->propertyMetadata,
68 3
            $this->fileResources,
69 3
            $this->createdAt,
70 3
            $this->annotations,
71 3
            $this->id,
72 3
            $this->associations
73 3
        ) = unserialize($str);
74
75 3
        $this->reflection = new \ReflectionClass($this->name);
76 3
    }
77
}
78