Group::createTableShape()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
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\AbstractShape;
21
use PhpOffice\PhpPresentation\GeometryCalculator;
22
use PHPOffice\PhpPresentation\ShapeContainerInterface;
23
use PhpOffice\PhpPresentation\Shape\Drawing;
24
use PhpOffice\PhpPresentation\Shape\RichText;
25
use PhpOffice\PhpPresentation\Shape\Table;
26
27
class Group extends AbstractShape implements ShapeContainerInterface
28
{
29
    /**
30
    * Collection of shapes
31
    *
32
    * @var \ArrayObject|\PhpOffice\PhpPresentation\AbstractShape[]
33
    */
34
    private $shapeCollection = null;
35
36
    /**
37
    * Extent X
38
    *
39
    * @var int
40
    */
41
    protected $extentX;
42
43
    /**
44
    * Extent Y
45
    *
46
    * @var int
47
    */
48
    protected $extentY;
49
50 11
    public function __construct()
51
    {
52 11
        parent::__construct();
53
54
        // For logic purposes.
55 11
        $this->offsetX = null;
56 11
        $this->offsetY = null;
57
58
        // Shape collection
59 11
        $this->shapeCollection = new \ArrayObject();
60 11
    }
61
62
    /**
63
    * Get collection of shapes
64
    *
65
     * @return \ArrayObject|AbstractShape[]
66
    */
67 10
    public function getShapeCollection()
68
    {
69 10
        return $this->shapeCollection;
70
    }
71
72
    /**
73
     * Add shape to slide
74
     *
75
     * @param  \PhpOffice\PhpPresentation\AbstractShape $shape
76
     * @return \PhpOffice\PhpPresentation\AbstractShape
77
     * @throws \Exception
78
     */
79 9
    public function addShape(AbstractShape $shape)
80
    {
81 9
        $shape->setContainer($this);
82
83 9
        return $shape;
84
    }
85
86
    /**
87
    * Get X Offset
88
    *
89
    * @return int
90
    */
91 7
    public function getOffsetX()
92
    {
93 7
        if ($this->offsetX === null) {
94 7
            $offsets = GeometryCalculator::calculateOffsets($this);
95 7
            $this->offsetX = $offsets[GeometryCalculator::X];
96 7
            $this->offsetY = $offsets[GeometryCalculator::Y];
97
        }
98
99 7
        return $this->offsetX;
100
    }
101
102
    /**
103
    * Ignores setting the X Offset, preserving the default behavior.
104
    *
105
    * @param  int                 $pValue
106
    * @return $this
107
    */
108 1
    public function setOffsetX($pValue = 0)
109
    {
110 1
        return $this;
111
    }
112
113
    /**
114
    * Get Y Offset
115
    *
116
    * @return int
117
    */
118 7
    public function getOffsetY()
119
    {
120 7
        if ($this->offsetY === null) {
121 1
            $offsets = GeometryCalculator::calculateOffsets($this);
122 1
            $this->offsetX = $offsets[GeometryCalculator::X];
123 1
            $this->offsetY = $offsets[GeometryCalculator::Y];
124
        }
125
126 7
        return $this->offsetY;
127
    }
128
129
    /**
130
    * Ignores setting the Y Offset, preserving the default behavior.
131
    *
132
    * @param  int                 $pValue
133
    * @return $this
134
    */
135 1
    public function setOffsetY($pValue = 0)
136
    {
137 1
        return $this;
138
    }
139
140
    /**
141
    * Get X Extent
142
    *
143
    * @return int
144
    */
145 5
    public function getExtentX()
146
    {
147 5
        if ($this->extentX === null) {
148 5
            $extents = GeometryCalculator::calculateExtents($this);
149 5
            $this->extentX = $extents[GeometryCalculator::X] - $this->getOffsetX();
0 ignored issues
show
Documentation Bug introduced by
It seems like $extents[\PhpOffice\PhpP...] - $this->getOffsetX() can also be of type double. However, the property $extentX is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
150 5
            $this->extentY = $extents[GeometryCalculator::Y] - $this->getOffsetY();
0 ignored issues
show
Documentation Bug introduced by
It seems like $extents[\PhpOffice\PhpP...] - $this->getOffsetY() can also be of type double. However, the property $extentY is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
151
        }
152
153 5
        return $this->extentX;
154
    }
155
156
    /**
157
    * Get Y Extent
158
    *
159
    * @return int
160
    */
161 5
    public function getExtentY()
162
    {
163 5
        if ($this->extentY === null) {
164 1
            $extents = GeometryCalculator::calculateExtents($this);
165 1
            $this->extentX = $extents[GeometryCalculator::X] - $this->getOffsetX();
0 ignored issues
show
Documentation Bug introduced by
It seems like $extents[\PhpOffice\PhpP...] - $this->getOffsetX() can also be of type double. However, the property $extentX is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
166 1
            $this->extentY = $extents[GeometryCalculator::Y] - $this->getOffsetY();
0 ignored issues
show
Documentation Bug introduced by
It seems like $extents[\PhpOffice\PhpP...] - $this->getOffsetY() can also be of type double. However, the property $extentY is declared as type integer. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
167
        }
168
169 5
        return $this->extentY;
170
    }
171
172
    /**
173
    * Ignores setting the width, preserving the default behavior.
174
    *
175
    * @param  int                 $pValue
176
    * @return $this
177
    */
178 1
    public function setWidth($pValue = 0)
179
    {
180 1
        return $this;
181
    }
182
183
    /**
184
    * Ignores setting the height, preserving the default behavior.
185
    *
186
    * @param  int                 $pValue
187
    * @return $this
188
    */
189 1
    public function setHeight($pValue = 0)
190
    {
191 1
        return $this;
192
    }
193
194
    /**
195
     * Create rich text shape
196
     *
197
     * @return \PhpOffice\PhpPresentation\Shape\RichText
198
     * @throws \Exception
199
     */
200 1
    public function createRichTextShape()
201
    {
202 1
        $shape = new RichText();
203 1
        $this->addShape($shape);
204
205 1
        return $shape;
206
    }
207
208
    /**
209
     * Create line shape
210
     *
211
     * @param  int $fromX Starting point x offset
212
     * @param  int $fromY Starting point y offset
213
     * @param  int $toX Ending point x offset
214
     * @param  int $toY Ending point y offset
215
     * @return \PhpOffice\PhpPresentation\Shape\Line
216
     * @throws \Exception
217
     */
218 1
    public function createLineShape($fromX, $fromY, $toX, $toY)
219
    {
220 1
        $shape = new Line($fromX, $fromY, $toX, $toY);
221 1
        $this->addShape($shape);
222
223 1
        return $shape;
224
    }
225
226
    /**
227
     * Create chart shape
228
     *
229
     * @return \PhpOffice\PhpPresentation\Shape\Chart
230
     * @throws \Exception
231
     */
232 1
    public function createChartShape()
233
    {
234 1
        $shape = new Chart();
235 1
        $this->addShape($shape);
236
237 1
        return $shape;
238
    }
239
240
    /**
241
     * Create drawing shape
242
     *
243
     * @return \PhpOffice\PhpPresentation\Shape\Drawing\File
244
     * @throws \Exception
245
     */
246 2
    public function createDrawingShape()
247
    {
248 2
        $shape = new Drawing\File();
249 2
        $this->addShape($shape);
250
251 2
        return $shape;
252
    }
253
254
    /**
255
     * Create table shape
256
     *
257
     * @param  int $columns Number of columns
258
     * @return \PhpOffice\PhpPresentation\Shape\Table
259
     * @throws \Exception
260
     */
261 1
    public function createTableShape($columns = 1)
262
    {
263 1
        $shape = new Table($columns);
264 1
        $this->addShape($shape);
265
266 1
        return $shape;
267
    }
268
}
269