Completed
Pull Request — master (#97)
by
unknown
03:44
created

File::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 1
1
<?php
2
namespace Kunnu\Dropbox\Models;
3
4
use Kunnu\Dropbox\DropboxFile;
5
6
class File extends BaseModel
7
{
8
9
    /**
10
     * The file contents
11
     *
12
     * @var string|DropboxFile
13
     */
14
    protected $contents;
15
16
    /**
17
     * File Metadata
18
     *
19
     * @var \Kunnu\Dropbox\Models\FileMetadata
20
     */
21
    protected $metadata;
22
23
24
    /**
25
     * Create a new File instance
26
     *
27
     * @param array  $data
28
     * @param string|DropboxFile $contents
29
     */
30 3
    public function __construct(array $data, $contents)
31
    {
32 3
        parent::__construct($data);
33 3
        $this->contents = $contents;
34 3
        $this->metadata = new FileMetadata($data);
35 3
    }
36
37
    /**
38
     * The metadata for the file
39
     *
40
     * @return \Kunnu\Dropbox\Models\FileMetadata
41
     */
42 3
    public function getMetadata()
43
    {
44 3
        return $this->metadata;
45
    }
46
47
    /**
48
     * Get the file contents
49
     *
50
     * @return string
51
     */
52 3
    public function getContents()
53
    {
54 3
        if ($this->contents instanceof DropboxFile) {
55 1
            return $this->contents->getContents();
56
        }
57 2
        return $this->contents;
58
    }
59
}
60