MarkupCollection::offsetSet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Patron package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Patron;
13
14
/**
15
 * A markup collection
16
 */
17
class MarkupCollection implements \ArrayAccess
18
{
19
	/**
20
	 * @var array
21
	 */
22
	private $collection = [];
23
24
	/**
25
	 * @param array $markups
26
	 */
27
	public function __construct(array $markups = [])
28
	{
29
		foreach ($markups as $name => $definition)
30
		{
31
			$this[$name] = $definition;
32
		}
33
	}
34
35
	/**
36
	 * Whether a markup exists.
37
	 *
38
	 * @param string $name Markup name.
39
	 *
40
	 * @return boolean `true` if the markup exists, `false` otherwise.
41
	 */
42
	public function offsetExists($name)
43
	{
44
		return isset($this->collection[$name]);
45
	}
46
47
	/**
48
	 * Returns a markup definition.
49
	 *
50
	 * @param string $name Markup name.
51
	 *
52
	 * @return array The markup's definition.
53
	 *
54
	 * @throws MarkupNotDefined when the markup is not defined.
55
	 */
56
	public function offsetGet($name)
57
	{
58
		if (!$this->offsetExists($name))
59
		{
60
			throw new MarkupNotDefined([ $name, $this ]);
61
		}
62
63
		return $this->collection[$name];
64
	}
65
66
	/**
67
	 * Sets a markup definition.
68
	 *
69
	 * @param string $name Markup name.
70
	 * @param array $definition Markup definition.
71
	 */
72
	public function offsetSet($name, $definition)
73
	{
74
		$this->collection[$name] = $definition;
75
	}
76
77
	/**
78
	 * Removes a markup.
79
	 *
80
	 * @param string $name Markup name.
81
	 */
82
	public function offsetUnset($name)
83
	{
84
		unset($this->collection[$name]);
85
	}
86
}
87