Completed
Push — master ( 4f40d9...14b52b )
by Franck
17s
created

Table::getNumColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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
 * @link        https://github.com/PHPOffice/PHPPresentation
14
 * @copyright   2009-2015 PHPPresentation contributors
15
 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16
 */
17
18
namespace PhpOffice\PhpPresentation\Shape;
19
20
use PhpOffice\PhpPresentation\ComparableInterface;
21
use PhpOffice\PhpPresentation\Shape\Table\Row;
22
23
/**
24
 * Table shape
25
 */
26
class Table extends AbstractGraphic implements ComparableInterface
27
{
28
    /**
29
     * Rows
30
     *
31
     * @var \PhpOffice\PhpPresentation\Shape\Table\Row[]
32
     */
33
    private $rows;
34
35
    /**
36
     * Number of columns
37
     *
38
     * @var int
39
     */
40
    private $columnCount = 1;
41
42
    /**
43
     * Create a new \PhpOffice\PhpPresentation\Shape\Table instance
44
     *
45
     * @param int $columns Number of columns
46
     */
47 23
    public function __construct($columns = 1)
48
    {
49
        // Initialise variables
50 23
        $this->rows        = array();
51 23
        $this->columnCount = $columns;
52
53
        // Initialize parent
54 23
        parent::__construct();
55
56
        // No resize proportional
57 23
        $this->resizeProportional = false;
58 23
    }
59
60
    /**
61
     * Get row
62
     *
63
     * @param  int $row Row number
64
     * @param  boolean $exceptionAsNull Return a null value instead of an exception?
65
     * @throws \Exception
66
     * @return \PhpOffice\PhpPresentation\Shape\Table\Row
67
     */
68 12
    public function getRow($row = 0, $exceptionAsNull = false)
69
    {
70 12
        if (!isset($this->rows[$row])) {
71 12
            if ($exceptionAsNull) {
72 11
                return null;
73
            }
74 1
            throw new \Exception('Row number out of bounds.');
75
        }
76
77 11
        return $this->rows[$row];
78
    }
79
80
    /**
81
     * Get rows
82
     *
83
     * @return \PhpOffice\PhpPresentation\Shape\Table\Row[]
84
     */
85 19
    public function getRows()
86
    {
87 19
        return $this->rows;
88
    }
89
90
    /**
91
     * Create row
92
     *
93
     * @return \PhpOffice\PhpPresentation\Shape\Table\Row
94
     */
95 18
    public function createRow()
96
    {
97 18
        $row           = new Row($this->columnCount);
98 18
        $this->rows[] = $row;
99
100 18
        return $row;
101
    }
102
103
    /**
104
     * @return int
105
     */
106 1
    public function getNumColumns()
107
    {
108 1
        return $this->columnCount;
109
    }
110
111
    /**
112
     * @param int $numColumn
113
     * @return Table
114
     */
115 1
    public function setNumColumns($numColumn)
116
    {
117 1
        $this->columnCount = $numColumn;
118 1
        return $this;
119
    }
120
121
    /**
122
     * Get hash code
123
     *
124
     * @return string Hash code
125
     */
126 1
    public function getHashCode()
127
    {
128 1
        $hashElements = '';
129 1
        foreach ($this->rows as $row) {
130 1
            $hashElements .= $row->getHashCode();
131 1
        }
132
133 1
        return md5($hashElements . __CLASS__);
134
    }
135
}
136