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