mageekguy\atoum\template\tag: lines coverage

96% of 248

OPs

100% of 55

Lines

81% of 42

Branches

85% of 20

Paths
Method OPs OPs % Lines Line % Branches Branches % Paths Path %
mageekguy\atoum\template\tag::__construct() 78 96% 23 100% 16 75% 8 63%
mageekguy\atoum\template\tag::getId() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\template\tag::getTag() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\template\tag::getLine() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\template\tag::getOffset() 6 100% 1 100% 1 100% 1 100%
mageekguy\atoum\template\tag::setId() 68 97% 11 100% 7 71% 3 100%
mageekguy\atoum\template\tag::unsetId() 9 100% 2 100% 1 100% 1 100%
mageekguy\atoum\template\tag::setAttribute() 37 95% 8 100% 7 86% 2 100%
mageekguy\atoum\template\tag::unsetAttribute() 32 94% 7 100% 7 86% 2 100%
#
1
<?php
2

                    
3
namespace mageekguy\atoum\template;
4

                    
5
use
6
	mageekguy\atoum,
7
	mageekguy\atoum\exceptions
8
;
9

                    
10
class tag extends atoum\template
11
{
12
	private $tag = '';
13
	private $id = null;
14
	private $line = null;
15
	private $offset = null;
16

                    
17
	public function __construct($tag, $data = null, $line = null, $offset = null)100%
18
	{
19
		$tag = (string) $tag;
20

                    
21
		if ($tag === '')
22
		{
23
			throw new exceptions\logic('Tag must not be an empty string');
24
		}
25

                    
26
		if ($line !== null)
27
		{
28
			$line = (int) $line;
29

                    
30
			if ($line <= 0)
31
			{
32
				throw new exceptions\logic('Line must be greater than 0');
33
			}
34
		}
35

                    
36
		if ($offset !== null)
37
		{
38
			$offset = (int) $offset;
39

                    
40
			if ($offset <= 0)
41
			{
42
				throw new exceptions\logic('Offset must be greater than 0');
43
			}
44
		}
45

                    
46
		parent::__construct($data);
47

                    
48
		$this->tag = $tag;
49
		$this->line = $line;
50
		$this->offset = $offset;
51
	}
52

                    
53
	public function getId()100%
54
	{
55
		return $this->id;
56
	}
57

                    
58
	public function getTag()100%
59
	{
60
		return $this->tag;
61
	}
62

                    
63
	public function getLine()100%
64
	{
65
		return $this->line;
66
	}
67

                    
68
	public function getOffset()100%
69
	{
70
		return $this->offset;
71
	}
72

                    
73
	public function setId($id)100%
74
	{
75
		$id = (string) $id;
76

                    
77
		if ($id === '')
78
		{
79
			throw new exceptions\logic('Id must not be empty');
80
		}
81

                    
82
		if (($tagWithSameId = $this->getById($id)) !== null)
83
		{
84
			$line = $tagWithSameId->getLine();
85
			$offset = $tagWithSameId->getOffset();
86

                    
87
			throw new exceptions\logic('Id \'' . $id . '\' is already defined in line ' . ($line !== null ?: 'unknown') . ' at offset ' . ($offset !== null ?: 'unknown'));
88
		}
89

                    
90
		$this->id = $id;
91

                    
92
		return $this;
93
	}
94

                    
95
	public function unsetId()100%
96
	{
97
		$this->id = null;
98

                    
99
		return $this;
100
	}
101

                    
102
	public function setAttribute($name, $value)100%
103
	{
104
		switch (true)
105
		{
106
			case $name == 'id':
107
				$this->setId($value);
108
				break;
109

                    
110
			default:
111
				throw new exceptions\logic('Attribute \'' . $name . '\' is unknown');
112
		}
113

                    
114
		return $this;
115
	}
116

                    
117
	public function unsetAttribute($name)100%
118
	{
119
		switch ($name)
120
		{
121
			case 'id':
122
				$this->unsetId();
123
				break;
124

                    
125
			default:
126
				throw new exceptions\logic('Attribute \'' . $name . '\' is unknown');
127
		}
128

                    
129
		return $this;
130
	}
131
}