Passed
Branch develop (7ed98a)
by Richard
04:39
created

MultiAsset::offsetExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
4
namespace Riclep\Storyblok\Fields;
5
6
7
use Riclep\Storyblok\Field;
8
9
class MultiAsset extends Field implements \ArrayAccess
10
{
11
	public function __toString()
12
	{
13
		// TODO
14
		return '';
15
	}
16
17
	public function init() {
18
		if ($this->hasFiles()) {
19
			$this->content = collect($this->content())->transform(function ($file) {
20
				return new Asset($file);
21
			});
22
		}
23
	}
24
25
	public function hasFiles() {
26
		return (bool) $this->content();
27
	}
28
29
	/*
30
	 * Methods for ArrayAccess Trait - allows us to dig straight down to the content collection
31
	 * when calling a key on the Object
32
	 * */
33
	public function offsetSet($offset, $value) {
34
		if (is_null($offset)) {
35
			$this->content[] = $value;
36
		} else {
37
			$this->content[$offset] = $value;
38
		}
39
	}
40
41
	public function offsetExists($offset) {
42
		return isset($this->content[$offset]);
43
	}
44
45
	public function offsetUnset($offset) {
46
		unset($this->content[$offset]);
47
	}
48
49
	public function offsetGet($offset) {
50
		return isset($this->content[$offset]) ? $this->content[$offset] : null;
51
	}
52
}