Asset   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
eloc 10
c 4
b 0
f 1
dl 0
loc 32
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A __toString() 0 7 2
A hasFile() 0 7 2
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