Passed
Push — master ( 844081...2958af )
by JHONATAN
02:19
created

TransferMetadata::addPropertyMetadata()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 9.2
c 0
b 0
f 0
cc 4
eloc 7
nc 6
nop 1
crap 4
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 11
    public function addPropertyMetadata(BasePropertyMetadata $metadata)
23
    {
24 11
        if ($metadata instanceof PropertyMetadata) {
25 11
            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 11
        parent::addPropertyMetadata($metadata);
31
        
32 11
        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 11
        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
    public function serialize()
49
    {
50
        return serialize(array(
51
            $this->name,
52
            $this->methodMetadata,
53
            $this->propertyMetadata,
54
            $this->fileResources,
55
            $this->createdAt,
56
            $this->annotations,
57
            $this->id,
58
            $this->associations,
59
        ));
60
    }
61
62 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
            $this->name,
66
            $this->methodMetadata,
67
            $this->propertyMetadata,
68
            $this->fileResources,
69
            $this->createdAt,
70
            $this->annotations,
71
            $this->id,
72
            $this->associations
73
        ) = unserialize($str);
74
75
        $this->reflection = new \ReflectionClass($this->name);
76
    }
77
78
}
79