ImageParams::toArray()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 6
cts 7
cp 0.8571
rs 9.6
c 0
b 0
f 0
cc 3
nc 2
nop 0
crap 3.0261
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Model;
15
16
/**
17
 * Description of EMongoImageParams
18
 * @since 2.0.2
19
 * @property int $width Width of image
20
 * @property int $height Height of image
21
 * @property bool $adaptive If true adaptive (with crop) resize will be used, if false best match scalling will be used
22
 * @property bool $isTemp This is to indicate that image is temporary, will be automatically set to true
23
 * @author Piotr
24
 */
25
class ImageParams
26
{
27
28
	use \Maslosoft\Mangan\Traits\Access\GetSet;
29
30
	/**
31
	 *
32
	 * @var int
33
	 */
34
	private $_width = 0;
35
36
	/**
37
	 *
38
	 * @var int
39
	 */
40
	private $_height = 0;
41
42
	/**
43
	 * If true adaptive (with crop) resize will be used, if false best match scalling will be used
44
	 * @var bool
45
	 */
46
	private $_adaptive = false;
47
48
	/**
49
	 * This is to indicate that image is temporary, this should set to true for thumbs etc.
50
	 * @var bool
51
	 */
52
	private $_isTemp = false;
53
54 2
	public function toArray()
55
	{
56 2
		if ($this->_width || $this->_height)
57
		{
58
			// Get resized
59
			return [
60 2
				'width' => $this->getWidth(),
61 2
				'height' => $this->getHeight(),
62 2
				'adaptive' => $this->getAdaptive(),
63 2
				'isTemp' => $this->getIsTemp()
64
			];
65
		}
66
		else
67
		{
68
			// Get original image
69
			return [
70
				'isTemp' => false
71
			];
72
		}
73
	}
74
75 2
	public function getWidth()
76
	{
77 2
		return (int) $this->_width;
78
	}
79
80 2
	public function getHeight()
81
	{
82 2
		return (int) $this->_height;
83
	}
84
85 2
	public function getAdaptive()
86
	{
87 2
		return (bool) $this->_adaptive;
88
	}
89
90 2
	public function getIsTemp()
91
	{
92 2
		return $this->_isTemp;
93
	}
94
95 2
	public function setWidth($width)
96
	{
97 2
		$this->_width = $width;
98 2
		return $this;
99
	}
100
101 2
	public function setHeight($height)
102
	{
103 2
		$this->_height = $height;
104 2
		return $this;
105
	}
106
107
	public function setAdaptive($adaptive)
108
	{
109
		$this->_adaptive = $adaptive;
110
		return $this;
111
	}
112
113 2
	public function setIsTemp($isTemp)
114
	{
115 2
		$this->_isTemp = $isTemp;
116 2
		return $this;
117
	}
118
119
}
120