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