Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
13 / 13
CRAP
100.00% covered (success)
100.00%
41 / 41
AbstractGraphic
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
13 / 13
23
100.00% covered (success)
100.00%
41 / 41
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
7 / 7
 __clone
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 getImageIndex
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getName
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setName
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getDescription
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setDescription
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 setWidth
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
5 / 5
 setHeight
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
5 / 5
 setWidthAndHeight
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
9 / 9
 isResizeProportional
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setResizeProportional
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
1
100.00% covered (success)
100.00%
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 * @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\AbstractShape;
24use PhpOffice\PhpPresentation\ComparableInterface;
25
26/**
27 * Abstract drawing.
28 */
29abstract class AbstractGraphic extends AbstractShape implements ComparableInterface
30{
31    /**
32     * Image counter.
33     *
34     * @var int
35     */
36    private static $imageCounter = 0;
37
38    /**
39     * Image index.
40     *
41     * @var int
42     */
43    private $imageIndex = 0;
44
45    /**
46     * Name.
47     *
48     * @var string
49     */
50    protected $name;
51
52    /**
53     * Description.
54     *
55     * @var string
56     */
57    protected $description;
58
59    /**
60     * Proportional resize.
61     *
62     * @var bool
63     */
64    protected $resizeProportional;
65
66    /**
67     * Slide relation ID (should not be used by user code!).
68     *
69     * @var string
70     */
71    public $relationId = null;
72
73    /**
74     * Create a new \PhpOffice\PhpPresentation\Slide\AbstractDrawing.
75     */
76    public function __construct()
77    {
78        // Initialise values
79        $this->name = '';
80        $this->description = '';
81        $this->resizeProportional = true;
82
83        // Set image index
84        ++self::$imageCounter;
85        $this->imageIndex = self::$imageCounter;
86
87        // Initialize parent
88        parent::__construct();
89    }
90
91    public function __clone()
92    {
93        parent::__clone();
94
95        ++self::$imageCounter;
96        $this->imageIndex = self::$imageCounter;
97    }
98
99    /**
100     * Get image index.
101     *
102     * @return int
103     */
104    public function getImageIndex()
105    {
106        return $this->imageIndex;
107    }
108
109    /**
110     * Get Name.
111     *
112     * @return string
113     */
114    public function getName()
115    {
116        return $this->name;
117    }
118
119    /**
120     * Set Name.
121     *
122     * @param string $pValue
123     *
124     * @return $this
125     */
126    public function setName($pValue = '')
127    {
128        $this->name = $pValue;
129
130        return $this;
131    }
132
133    /**
134     * Get Description.
135     *
136     * @return string
137     */
138    public function getDescription()
139    {
140        return $this->description;
141    }
142
143    /**
144     * Set Description.
145     *
146     * @param string $pValue
147     *
148     * @return $this
149     */
150    public function setDescription($pValue = '')
151    {
152        $this->description = $pValue;
153
154        return $this;
155    }
156
157    /**
158     * Set Width.
159     *
160     * @return self
161     */
162    public function setWidth(int $pValue = 0)
163    {
164        // Resize proportional?
165        if ($this->resizeProportional && 0 != $pValue && 0 != $this->width) {
166            $ratio = $this->height / $this->width;
167            $this->height = (int) round($ratio * $pValue);
168        }
169
170        // Set width
171        $this->width = $pValue;
172
173        return $this;
174    }
175
176    /**
177     * Set Height.
178     *
179     * @return self
180     */
181    public function setHeight(int $pValue = 0)
182    {
183        // Resize proportional?
184        if ($this->resizeProportional && 0 != $pValue && 0 != $this->height) {
185            $ratio = $this->width / $this->height;
186            $this->width = (int) round($ratio * $pValue);
187        }
188
189        // Set height
190        $this->height = $pValue;
191
192        return $this;
193    }
194
195    /**
196     * Set width and height with proportional resize.
197     *
198     * @author Vincent@luo MSN:kele_100@hotmail.com
199     *
200     * @return self
201     */
202    public function setWidthAndHeight(int $width = 0, int $height = 0)
203    {
204        $xratio = $width / $this->width;
205        $yratio = $height / $this->height;
206        if ($this->resizeProportional && !(0 == $width || 0 == $height)) {
207            if (($xratio * $this->height) < $height) {
208                $this->height = (int) ceil($xratio * $this->height);
209                $this->width = $width;
210            } else {
211                $this->width = (int) ceil($yratio * $this->width);
212                $this->height = $height;
213            }
214        }
215
216        return $this;
217    }
218
219    /**
220     * Get ResizeProportional.
221     *
222     * @return bool
223     */
224    public function isResizeProportional()
225    {
226        return $this->resizeProportional;
227    }
228
229    /**
230     * Set ResizeProportional.
231     *
232     * @param bool $pValue
233     */
234    public function setResizeProportional($pValue = true): self
235    {
236        $this->resizeProportional = $pValue;
237
238        return $this;
239    }
240
241    /**
242     * Get hash code.
243     *
244     * @return string Hash code
245     */
246    public function getHashCode(): string
247    {
248        return md5($this->name . $this->description . parent::getHashCode() . __CLASS__);
249    }
250}