BarcodeBox::setSize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * BarcodeBox class.
6
 *
7
 * @package   YetiForcePDF\Layout
8
 *
9
 * @copyright YetiForce Sp. z o.o
10
 * @license   MIT
11
 * @author    Rafal Pospiech <[email protected]>
12
 */
13
14
namespace YetiForcePDF\Layout;
15
16
use Milon\Barcode\DNS1D;
17
18
/**
19
 * Class BarcodeBox.
20
 */
21
class BarcodeBox extends InlineBlockBox
22
{
23
	/**
24
	 * @var string barcode type
25
	 */
26
	protected $type = 'EAN13';
27
	/**
28
	 * @var string barcode size
29
	 */
30
	protected $size = '3';
31
	/**
32
	 * @var string barcode height
33
	 */
34
	protected $height = '33';
35
	/**
36
	 * @var string code
37
	 */
38
	protected $code = '';
39
40
	/**
41
	 * Get barcode type.
42
	 *
43
	 * @return string
44
	 */
45
	public function getType(): string
46
	{
47
		return $this->type;
48
	}
49
50
	/**
51
	 * Set barcode type.
52
	 *
53
	 * @param string $type
54
	 *
55
	 * @return $this
56
	 */
57
	public function setType(string $type)
58
	{
59
		$this->type = $type;
60
		return $this;
61
	}
62
63
	/**
64
	 * Get barcode size.
65
	 *
66
	 * @return string
67
	 */
68
	public function getSize(): string
69
	{
70
		return $this->size;
71
	}
72
73
	/**
74
	 * Set barcode size.
75
	 *
76
	 * @param string $size
77
	 *
78
	 * @return $this
79
	 */
80
	public function setSize(string $size)
81
	{
82
		$this->size = $size;
83
		return $this;
84
	}
85
86
	/**
87
	 * Get barcode height.
88
	 *
89
	 * @return string
90
	 */
91
	public function getHeight(): string
92
	{
93
		return $this->height;
94
	}
95
96
	/**
97
	 * Set barcode height.
98
	 *
99
	 * @param string $height
100
	 *
101
	 * @return $this
102
	 */
103
	public function setHeight(string $height)
104
	{
105
		$this->height = $height;
106
		return $this;
107
	}
108
109
	/**
110
	 * Get code.
111
	 *
112
	 * @return string
113
	 */
114
	public function getCode(): string
115
	{
116
		return $this->code;
117
	}
118
119
	/**
120
	 * Set code.
121
	 *
122
	 * @param string $code
123
	 *
124
	 * @return $this
125
	 */
126
	public function setCode(string $code)
127
	{
128
		$this->code = $code;
129
		return $this;
130
	}
131
132
	/**
133
	 * Generate barcode image.
134
	 *
135
	 * @return $this
136
	 */
137
	public function generateBarcodeImage()
138
	{
139
		$barcode = new DNS1D();
140
		$barcode->setStorPath(__DIR__ . '/cache/');
141
		$image = 'data:image/png;base64,' . $barcode->getBarcodePNG($this->getCode(), $this->getType(), (int) $this->getSize(), (int) $this->getHeight());
0 ignored issues
show
Bug introduced by
Are you sure $barcode->getBarcodePNG(...int)$this->getHeight()) of type false|string can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

141
		$image = 'data:image/png;base64,' . /** @scrutinizer ignore-type */ $barcode->getBarcodePNG($this->getCode(), $this->getType(), (int) $this->getSize(), (int) $this->getHeight());
Loading history...
142
		$this->getStyle()->setContent("background-image: url($image)");
143
		return $this;
144
	}
145
}
146