Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
29 / 29 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
1 / 1 |
Tab | |
100.00% |
29 / 29 |
|
100.00% |
7 / 7 |
7 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
getType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setType | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
getLeader | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setLeader | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
getPosition | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setPosition | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPWord - A pure PHP library for reading and writing |
4 | * word processing documents. |
5 | * |
6 | * PHPWord is free software distributed under the terms of the GNU Lesser |
7 | * General Public License version 3 as published by the Free Software Foundation. |
8 | * |
9 | * For the full copyright and license information, please read the LICENSE |
10 | * file that was distributed with this source code. For the full list of |
11 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPWord |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | namespace PhpOffice\PhpWord\Style; |
19 | |
20 | /** |
21 | * Tab style. |
22 | */ |
23 | class Tab extends AbstractStyle |
24 | { |
25 | /** |
26 | * Tab stop types. |
27 | * |
28 | * @const string |
29 | */ |
30 | const TAB_STOP_CLEAR = 'clear'; |
31 | const TAB_STOP_LEFT = 'left'; |
32 | const TAB_STOP_CENTER = 'center'; |
33 | const TAB_STOP_RIGHT = 'right'; |
34 | const TAB_STOP_DECIMAL = 'decimal'; |
35 | const TAB_STOP_BAR = 'bar'; |
36 | const TAB_STOP_NUM = 'num'; |
37 | |
38 | /** |
39 | * Tab leader types. |
40 | * |
41 | * @const string |
42 | */ |
43 | const TAB_LEADER_NONE = 'none'; |
44 | const TAB_LEADER_DOT = 'dot'; |
45 | const TAB_LEADER_HYPHEN = 'hyphen'; |
46 | const TAB_LEADER_UNDERSCORE = 'underscore'; |
47 | const TAB_LEADER_HEAVY = 'heavy'; |
48 | const TAB_LEADER_MIDDLEDOT = 'middleDot'; |
49 | |
50 | /** |
51 | * Tab stop type. |
52 | * |
53 | * @var string |
54 | */ |
55 | private $type = self::TAB_STOP_CLEAR; |
56 | |
57 | /** |
58 | * Tab leader character. |
59 | * |
60 | * @var string |
61 | */ |
62 | private $leader = self::TAB_LEADER_NONE; |
63 | |
64 | /** |
65 | * Tab stop position (twip). |
66 | * |
67 | * @var float|int |
68 | */ |
69 | private $position = 0; |
70 | |
71 | /** |
72 | * Create a new instance of Tab. Both $type and $leader |
73 | * must conform to the values put forth in the schema. If they do not |
74 | * they will be changed to default values. |
75 | * |
76 | * @param string $type Defaults to 'clear' if value is not possible |
77 | * @param int $position Must be numeric; otherwise defaults to 0 |
78 | * @param string $leader Defaults to null if value is not possible |
79 | */ |
80 | public function __construct($type = null, $position = 0, $leader = null) |
81 | { |
82 | $stopTypes = [ |
83 | self::TAB_STOP_CLEAR, self::TAB_STOP_LEFT, self::TAB_STOP_CENTER, |
84 | self::TAB_STOP_RIGHT, self::TAB_STOP_DECIMAL, self::TAB_STOP_BAR, self::TAB_STOP_NUM, |
85 | ]; |
86 | $leaderTypes = [ |
87 | self::TAB_LEADER_NONE, self::TAB_LEADER_DOT, self::TAB_LEADER_HYPHEN, |
88 | self::TAB_LEADER_UNDERSCORE, self::TAB_LEADER_HEAVY, self::TAB_LEADER_MIDDLEDOT, |
89 | ]; |
90 | |
91 | $this->type = $this->setEnumVal($type, $stopTypes, $this->type); |
92 | $this->position = $this->setNumericVal($position, $this->position); |
93 | $this->leader = $this->setEnumVal($leader, $leaderTypes, $this->leader); |
94 | } |
95 | |
96 | /** |
97 | * Get stop type. |
98 | * |
99 | * @return string |
100 | */ |
101 | public function getType() |
102 | { |
103 | return $this->type; |
104 | } |
105 | |
106 | /** |
107 | * Set stop type. |
108 | * |
109 | * @param string $value |
110 | * |
111 | * @return self |
112 | */ |
113 | public function setType($value) |
114 | { |
115 | $enum = [ |
116 | self::TAB_STOP_CLEAR, self::TAB_STOP_LEFT, self::TAB_STOP_CENTER, |
117 | self::TAB_STOP_RIGHT, self::TAB_STOP_DECIMAL, self::TAB_STOP_BAR, |
118 | self::TAB_STOP_NUM, |
119 | ]; |
120 | $this->type = $this->setEnumVal($value, $enum, $this->type); |
121 | |
122 | return $this; |
123 | } |
124 | |
125 | /** |
126 | * Get leader. |
127 | * |
128 | * @return string |
129 | */ |
130 | public function getLeader() |
131 | { |
132 | return $this->leader; |
133 | } |
134 | |
135 | /** |
136 | * Set leader. |
137 | * |
138 | * @param string $value |
139 | * |
140 | * @return self |
141 | */ |
142 | public function setLeader($value) |
143 | { |
144 | $enum = [ |
145 | self::TAB_LEADER_NONE, self::TAB_LEADER_DOT, self::TAB_LEADER_HYPHEN, |
146 | self::TAB_LEADER_UNDERSCORE, self::TAB_LEADER_HEAVY, self::TAB_LEADER_MIDDLEDOT, |
147 | ]; |
148 | $this->leader = $this->setEnumVal($value, $enum, $this->leader); |
149 | |
150 | return $this; |
151 | } |
152 | |
153 | /** |
154 | * Get position. |
155 | * |
156 | * @return float|int |
157 | */ |
158 | public function getPosition() |
159 | { |
160 | return $this->position; |
161 | } |
162 | |
163 | /** |
164 | * Set position. |
165 | * |
166 | * @param float|int $value |
167 | * |
168 | * @return self |
169 | */ |
170 | public function setPosition($value) |
171 | { |
172 | $this->position = $this->setNumericVal($value, $this->position); |
173 | |
174 | return $this; |
175 | } |
176 | } |