Asset::__toString()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 3
c 2
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
4
namespace Riclep\Storyblok\Fields;
5
6
7
use Riclep\Storyblok\Field;
8
9
/**
10
 * @property false|string filename
11
 */
12
class Asset extends Field
13
{
14
	public function __construct($content, $block)
15
	{
16
		parent::__construct($content, $block);
17
18
		if (isset($this->content['filename'])) {
19
			$this->content['filename'] = str_replace('a.storyblok.com', config('storyblok.asset_domain'), $this->content['filename']);
20
        }
21
	}
22
23
	public function __toString(): string
24
	{
25
		if ($this->content['filename']) {
26
			return $this->content['filename'];
27
		}
28
29
		return '';
30
	}
31
32
	/**
33
	 * Checks a file was uploaded
34
	 *
35
	 * @return bool
36
	 */
37
	public function hasFile(): bool
38
	{
39
		if (!array_key_exists('filename', $this->content)) {
40
			return false;
41
		}
42
43
		return (bool) $this->content['filename'];
44
	}
45
}
46