Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
34 / 34
100.00% covered (success)
100.00%
12 / 12
CRAP
100.00% covered (success)
100.00%
1 / 1
Row
100.00% covered (success)
100.00%
34 / 34
100.00% covered (success)
100.00%
12 / 12
18
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
 getCell
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
3
 hasCell
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCells
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 nextCell
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
 getFill
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setFill
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getHeight
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHeight
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getHashCode
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 getHashIndex
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHashIndex
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
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
18declare(strict_types=1);
19
20namespace PhpOffice\PhpPresentation\Shape\Table;
21
22use PhpOffice\PhpPresentation\ComparableInterface;
23use PhpOffice\PhpPresentation\Exception\OutOfBoundsException;
24use PhpOffice\PhpPresentation\Style\Fill;
25
26/**
27 * Table row.
28 */
29class Row implements ComparableInterface
30{
31    /**
32     * Cells.
33     *
34     * @var Cell[]
35     */
36    private $cells = [];
37
38    /**
39     * Fill.
40     *
41     * @var Fill
42     */
43    private $fill;
44
45    /**
46     * Height (in pixels).
47     *
48     * @var int
49     */
50    private $height = 38;
51
52    /**
53     * Active cell index.
54     *
55     * @var int
56     */
57    private $activeCellIndex = -1;
58
59    /**
60     * Hash index.
61     *
62     * @var int
63     */
64    private $hashIndex;
65
66    /**
67     * @param int $columns Number of columns
68     */
69    public function __construct(int $columns = 1)
70    {
71        // Fill
72        $this->fill = new Fill();
73        // Cells
74        for ($inc = 0; $inc < $columns; ++$inc) {
75            $this->cells[] = new Cell();
76        }
77    }
78
79    /**
80     * Get cell.
81     *
82     * @param int $cell Cell number
83     */
84    public function getCell(int $cell = 0): Cell
85    {
86        if (!isset($this->cells[$cell])) {
87            throw new OutOfBoundsException(
88                0,
89                (count($this->cells) - 1) < 0 ? count($this->cells) - 1 : 0,
90                $cell
91            );
92        }
93
94        return $this->cells[$cell];
95    }
96
97    /**
98     * Get cell.
99     *
100     * @param int $cell Cell number
101     */
102    public function hasCell(int $cell): bool
103    {
104        return isset($this->cells[$cell]);
105    }
106
107    /**
108     * Get cells.
109     *
110     * @return array<Cell>
111     */
112    public function getCells(): array
113    {
114        return $this->cells;
115    }
116
117    /**
118     * Next cell (moves one cell to the right).
119     */
120    public function nextCell(): Cell
121    {
122        ++$this->activeCellIndex;
123        if (isset($this->cells[$this->activeCellIndex])) {
124            $this->cells[$this->activeCellIndex]->setFill(clone $this->getFill());
125
126            return $this->cells[$this->activeCellIndex];
127        }
128
129        throw new OutOfBoundsException(
130            0,
131            (count($this->cells) - 1) < 0 ? count($this->cells) - 1 : 0,
132            $this->activeCellIndex
133        );
134    }
135
136    /**
137     * Get fill.
138     */
139    public function getFill(): Fill
140    {
141        return $this->fill;
142    }
143
144    /**
145     * Set fill.
146     */
147    public function setFill(Fill $fill): self
148    {
149        $this->fill = $fill;
150
151        return $this;
152    }
153
154    /**
155     * Get height.
156     */
157    public function getHeight(): int
158    {
159        return $this->height;
160    }
161
162    /**
163     * Set height.
164     */
165    public function setHeight(int $value = 0): self
166    {
167        $this->height = $value;
168
169        return $this;
170    }
171
172    /**
173     * Get hash code.
174     *
175     * @return string Hash code
176     */
177    public function getHashCode(): string
178    {
179        $hashElements = '';
180        foreach ($this->cells as $cell) {
181            $hashElements .= $cell->getHashCode();
182        }
183
184        return md5($hashElements . $this->fill->getHashCode() . $this->height . __CLASS__);
185    }
186
187    /**
188     * Get hash index.
189     *
190     * Note that this index may vary during script execution! Only reliable moment is
191     * while doing a write of a workbook and when changes are not allowed.
192     *
193     * @return null|int Hash index
194     */
195    public function getHashIndex(): ?int
196    {
197        return $this->hashIndex;
198    }
199
200    /**
201     * Set hash index.
202     *
203     * Note that this index may vary during script execution! Only reliable moment is
204     * while doing a write of a workbook and when changes are not allowed.
205     *
206     * @param int $value Hash index
207     *
208     * @return $this
209     */
210    public function setHashIndex(int $value)
211    {
212        $this->hashIndex = $value;
213
214        return $this;
215    }
216}