Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
22 / 22 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
Table | |
100.00% |
22 / 22 |
|
100.00% |
8 / 8 |
11 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getRow | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
3 | |||
hasRow | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getRows | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createRow | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getNumColumns | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
setNumColumns | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
getHashCode | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | /** |
3 | * This file is part of PHPPresentation - A pure PHP library for reading and writing |
4 | * presentations documents. |
5 | * |
6 | * PHPPresentation 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/PHPPresentation/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPPresentation |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | declare(strict_types=1); |
19 | |
20 | namespace PhpOffice\PhpPresentation\Shape; |
21 | |
22 | use PhpOffice\PhpPresentation\ComparableInterface; |
23 | use PhpOffice\PhpPresentation\Exception\OutOfBoundsException; |
24 | use PhpOffice\PhpPresentation\Shape\Table\Row; |
25 | |
26 | /** |
27 | * Table shape. |
28 | */ |
29 | class Table extends AbstractGraphic implements ComparableInterface |
30 | { |
31 | /** |
32 | * Rows. |
33 | * |
34 | * @var array<int, Row> |
35 | */ |
36 | private $rows = []; |
37 | |
38 | /** |
39 | * Number of columns. |
40 | * |
41 | * @var int |
42 | */ |
43 | private $columnCount = 1; |
44 | |
45 | /** |
46 | * Create a new \PhpOffice\PhpPresentation\Shape\Table instance. |
47 | * |
48 | * @param int $columns Number of columns |
49 | */ |
50 | public function __construct($columns = 1) |
51 | { |
52 | $this->columnCount = $columns; |
53 | |
54 | // Initialize parent |
55 | parent::__construct(); |
56 | |
57 | // No resize proportional |
58 | $this->resizeProportional = false; |
59 | } |
60 | |
61 | /** |
62 | * Get row. |
63 | * |
64 | * @param int $row Row number |
65 | */ |
66 | public function getRow(int $row = 0): Row |
67 | { |
68 | if (!isset($this->rows[$row])) { |
69 | throw new OutOfBoundsException( |
70 | 0, |
71 | (count($this->rows) - 1) < 0 ? 0 : count($this->rows) - 1, |
72 | $row |
73 | ); |
74 | } |
75 | |
76 | return $this->rows[$row]; |
77 | } |
78 | |
79 | public function hasRow(int $row): bool |
80 | { |
81 | return isset($this->rows[$row]); |
82 | } |
83 | |
84 | /** |
85 | * Get rows. |
86 | * |
87 | * @return Row[] |
88 | */ |
89 | public function getRows(): array |
90 | { |
91 | return $this->rows; |
92 | } |
93 | |
94 | /** |
95 | * Create row. |
96 | */ |
97 | public function createRow(): Row |
98 | { |
99 | $row = new Row($this->columnCount); |
100 | $this->rows[] = $row; |
101 | |
102 | return $row; |
103 | } |
104 | |
105 | public function getNumColumns(): int |
106 | { |
107 | return $this->columnCount; |
108 | } |
109 | |
110 | public function setNumColumns(int $numColumn): self |
111 | { |
112 | $this->columnCount = $numColumn; |
113 | |
114 | return $this; |
115 | } |
116 | |
117 | /** |
118 | * Get hash code. |
119 | * |
120 | * @return string Hash code |
121 | */ |
122 | public function getHashCode(): string |
123 | { |
124 | $hashElements = ''; |
125 | foreach ($this->rows as $row) { |
126 | $hashElements .= $row->getHashCode(); |
127 | } |
128 | |
129 | return md5($hashElements . __CLASS__); |
130 | } |
131 | } |