Passed
Push — master ( 30b30c...28afa9 )
by JHONATAN
09:58
created

TransferMetadata::unserialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 11
CRAP Score 1

Importance

Changes 0
Metric Value
dl 14
loc 14
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Vox\Webservice\Metadata;
4
5
use Metadata\PropertyMetadata as BasePropertyMetadata;
6
use ReflectionClass;
7
use Vox\Data\Mapping\Exclude;
8
use Vox\Metadata\ClassMetadata;
9
use Vox\Metadata\PropertyMetadata;
10
use Vox\Webservice\Mapping\BelongsTo;
11
use Vox\Webservice\Mapping\HasMany;
12
use Vox\Webservice\Mapping\HasOne;
13
use Vox\Webservice\Mapping\Id;
14
15
/**
16
 * Holds a single transfer metadata information
17
 * 
18
 * @author Jhonatan Teixeira <[email protected]>
19
 */
20
class TransferMetadata extends ClassMetadata
21
{
22
    /**
23
     * @var PropertyMetadata
24
     */
25
    public $id;
26
    
27
    /**
28
     * @var PropertyMetadata[]
29
     */
30
    public $associations = [];
31
    
32 22
    public function addPropertyMetadata(BasePropertyMetadata $metadata)
33
    {
34 22
        if ($metadata instanceof PropertyMetadata) {
35 22
            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...
36 12
                $this->id = $metadata;
37
            }
38
        }
39
        
40 22
        parent::addPropertyMetadata($metadata);
41
        
42 22
        if ($metadata->hasAnnotation(BelongsTo::class) && !$metadata->hasAnnotation(Exclude::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

42
        if ($metadata->/** @scrutinizer ignore-call */ hasAnnotation(BelongsTo::class) && !$metadata->hasAnnotation(Exclude::class)) {
Loading history...
43 6
            $metadata->annotations[Exclude::class] = new Exclude();
44 6
            $metadata->annotations[Exclude::class]->output = false;
45
        }
46
        
47 22
        if ($metadata->hasAnnotation(BelongsTo::class)
48 22
            || $metadata->hasAnnotation(HasOne::class)
49 22
            || $metadata->hasAnnotation(HasMany::class)) {
50 6
            $this->associations[$metadata->name] = $metadata;
51
        }
52
        
53 22
        return $this;
54
    }
55
    
56
    /**
57
     * @param string $name
58
     * @return PropertyMetadata
59
     */
60
    public function getAssociation(string $name)
61
    {
62
        return $this->associations[$name] ?? null;
63
    }
64
    
65 4
    public function serialize()
66
    {
67 4
        return serialize(array(
68 4
            $this->name,
69 4
            $this->methodMetadata,
70 4
            $this->propertyMetadata,
71 4
            $this->fileResources,
72 4
            $this->createdAt,
73 4
            $this->annotations,
74 4
            $this->id,
75 4
            $this->associations,
76
        ));
77
    }
78
79 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...
80
    {
81
        list(
82 3
            $this->name,
83 3
            $this->methodMetadata,
84 3
            $this->propertyMetadata,
85 3
            $this->fileResources,
86 3
            $this->createdAt,
87 3
            $this->annotations,
88 3
            $this->id,
89 3
            $this->associations
90 3
        ) = unserialize($str);
91
92 3
        $this->reflection = new ReflectionClass($this->name);
93 3
    }
94
}
95