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

MultiAsset   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 42
rs 10
c 1
b 0
f 0
wmc 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A hasFiles() 0 2 1
A offsetUnset() 0 2 1
A offsetExists() 0 2 1
A __toString() 0 4 1
A offsetGet() 0 2 2
A offsetSet() 0 5 2
A init() 0 4 2
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
}