Completed
Push — master ( 2994aa...19d116 )
by Patrick
08:28
created

CopyReference::setMetadata()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
namespace Dropbox\Models;
3
4
use DateTime;
5
6
class CopyReference extends BaseModel
7
{
8
9
    /**
10
     * The expiration date of the copy reference
11
     *
12
     * @var DateTime
13
     */
14
    protected $expires;
15
16
    /**
17
     * The copy reference
18
     *
19
     * @var string
20
     */
21
    protected $reference;
22
23
    /**
24
     * File or Folder Metadata
25
     *
26
     * @var \Dropbox\Models\FileMetadata|\Dropbox\Models\FolderMetadata
27
     */
28
    protected $metadata;
29
30
31
    /**
32
     * Create a new CopyReference instance
33
     *
34
     * @param array $data
35
     */
36 2
    public function __construct(array $data)
37
    {
38 2
        parent::__construct($data);
39 2
        $this->expires = new DateTime($this->getDataProperty('expires'));
40 2
        $this->reference = $this->getDataProperty('copy_reference');
41 2
        $this->setMetadata();
42 2
    }
43
44
    /**
45
     * Set Metadata
46
     */
47 2
    protected function setMetadata()
48
    {
49 2
        $metadata = $this->getDataProperty('metadata');
50 2
        if (is_array($metadata)) {
51 2
            $this->metadata = ModelFactory::make($metadata);
0 ignored issues
show
Documentation Bug introduced by
It seems like \Dropbox\Models\ModelFactory::make($metadata) of type object<Dropbox\Models\ModelInterface> is incompatible with the declared type object<Dropbox\Models\Fi...\Models\FolderMetadata> of property $metadata.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
52
        }
53 2
    }
54
55
    /**
56
     * Get the expiration date of the copy reference
57
     *
58
     * @return DateTime
59
     */
60
    public function getExpirationDate()
61
    {
62
        return $this->expires;
63
    }
64
65
    /**
66
     * The metadata for the file/folder
67
     *
68
     * @return \Dropbox\Models\FileMetadata|\Dropbox\Models\FolderMetadata
69
     */
70 2
    public function getMetadata()
71
    {
72 2
        return $this->metadata;
73
    }
74
75
    /**
76
     * Get the copy reference
77
     *
78
     * @return string
79
     */
80 2
    public function getReference()
81
    {
82 2
        return $this->reference;
83
    }
84
}
85