| Total Complexity | 14 |
| Total Lines | 124 |
| Duplicated Lines | 0 % |
| Coverage | 97.44% |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class File implements FileInterface |
||
| 6 | { |
||
| 7 | protected $name = ''; |
||
| 8 | |||
| 9 | protected $size = 0; |
||
| 10 | |||
| 11 | protected $thumbUrl = ''; |
||
| 12 | |||
| 13 | protected $url = ''; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * File constructor |
||
| 17 | */ |
||
| 18 | 9 | public function __construct($json = null) |
|
| 19 | { |
||
| 20 | 9 | $this->parseJson($json); |
|
| 21 | 9 | } |
|
| 22 | |||
| 23 | /** |
||
| 24 | * @inheritdoc |
||
| 25 | */ |
||
| 26 | 9 | public function parseJson($json) |
|
| 27 | { |
||
| 28 | 9 | if (!$json) { |
|
| 29 | 7 | return; |
|
| 30 | } |
||
| 31 | |||
| 32 | 3 | $this->name = $json['name']; |
|
| 33 | 3 | $this->size = (int) $json['size']; |
|
| 34 | 3 | $this->url = $json['url']; |
|
| 35 | |||
| 36 | 3 | if (isset($json['thumb_url'])) { |
|
| 37 | 3 | $this->thumbUrl = $json['thumb_url']; |
|
| 38 | } |
||
| 39 | 3 | } |
|
| 40 | |||
| 41 | /** |
||
| 42 | * @inheritdoc |
||
| 43 | */ |
||
| 44 | 1 | public function toJson() |
|
| 45 | { |
||
| 46 | $json = array( |
||
| 47 | 1 | 'name' => $this->name, |
|
| 48 | 1 | 'size' => $this->size, |
|
| 49 | 1 | 'url' => $this->url, |
|
| 50 | ); |
||
| 51 | |||
| 52 | 1 | if ($this->thumbUrl) { |
|
| 53 | $json['thumb_url'] = $this->thumbUrl; |
||
| 54 | } |
||
| 55 | |||
| 56 | 1 | return $json; |
|
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @inheritdoc |
||
| 61 | */ |
||
| 62 | 2 | public function setName($name) |
|
| 63 | { |
||
| 64 | 2 | $this->name = $name; |
|
| 65 | |||
| 66 | 2 | return $this; |
|
| 67 | } |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @inheritdoc |
||
| 71 | */ |
||
| 72 | 1 | public function getName() |
|
| 73 | { |
||
| 74 | 1 | return $this->name; |
|
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @inheritdoc |
||
| 79 | */ |
||
| 80 | 1 | public function setSize($size) |
|
| 81 | { |
||
| 82 | 1 | $this->size = (int) $size; |
|
| 83 | |||
| 84 | 1 | return $this; |
|
| 85 | } |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @inheritdoc |
||
| 89 | */ |
||
| 90 | 1 | public function getSize() |
|
| 91 | { |
||
| 92 | 1 | return $this->size; |
|
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @inheritdoc |
||
| 97 | */ |
||
| 98 | 1 | public function setThumbUrl($thumbUrl) |
|
| 99 | { |
||
| 100 | 1 | $this->thumbUrl = $thumbUrl; |
|
| 101 | |||
| 102 | 1 | return $this; |
|
| 103 | } |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @inheritdoc |
||
| 107 | */ |
||
| 108 | 1 | public function getThumbUrl() |
|
| 111 | } |
||
| 112 | |||
| 113 | /** |
||
| 114 | * @inheritdoc |
||
| 115 | */ |
||
| 116 | 2 | public function setUrl($url) |
|
| 117 | { |
||
| 118 | 2 | $this->url = $url; |
|
| 119 | |||
| 120 | 2 | return $this; |
|
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @inheritdoc |
||
| 125 | */ |
||
| 126 | 1 | public function getUrl() |
|
| 129 | } |
||
| 130 | } |
||
| 131 |