Completed
Push — master ( 377f81...1c0919 )
by Richard
16s queued 12s
created

Asset::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 3
c 1
b 0
f 1
nc 2
nop 2
dl 0
loc 6
rs 10
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()
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() {
38
		if (!array_key_exists('filename', $this->content)) {
0 ignored issues
show
Bug introduced by
It seems like $this->content can also be of type string; however, parameter $array of array_key_exists() does only seem to accept ArrayObject|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
		if (!array_key_exists('filename', /** @scrutinizer ignore-type */ $this->content)) {
Loading history...
39
			return false;
40
		}
41
42
		return (bool) $this->content['filename'];
43
	}
44
}
45