Passed
Push — master ( 5aa4b6...5758c7 )
by Francimar
02:45
created

Printer::draw()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Thermal;
4
5
class Printer
6
{
7
    const ALIGN_LEFT = 0;
8
    const ALIGN_CENTER = 1;
9
    const ALIGN_RIGHT = 2;
10
11
    const STYLE_BOLD = 1;
12
    const STYLE_ITALIC = 2;
13
    const STYLE_UNDERLINE = 4;
14
    const STYLE_CONDENSED = 8;
15
    const STYLE_DOUBLE_WIDTH = 16;
16
    const STYLE_DOUBLE_HEIGHT = 32;
17
18
    const CUT_FULL = 0;
19
    const CUT_PARTIAL = 1;
20
21
    const DRAWER_1 = 0;
22
    const DRAWER_2 = 1;
23
24
    private $model;
25
    private $connection;
26
27 11
    public function __construct($model, $connection)
28
    {
29 11
        $this->connection = $connection;
30 11
        $this->connection->open();
31 11
        $this->model = $model;
32 11
        $this->model->getProfile()->setConnection($this->connection);
33 11
        $this->model->getProfile()->initialize();
34 11
    }
35
36 1
    public function setCodePage($codepage)
37
    {
38 1
        $this->model->getProfile()->setCodePage($codepage);
39 1
        return $this;
40
    }
41
42 1
    public function buzzer()
43
    {
44 1
        $this->model->getProfile()->buzzer();
45 1
        return $this;
46
    }
47
48 1
    public function cutter($mode = self::CUT_PARTIAL)
49
    {
50 1
        $this->model->getProfile()->cutter($mode);
51 1
        return $this;
52
    }
53
54
    /**
55
     * @param int $number drawer id
56
     * @param int $on_time time in milliseconds that activate the drawer
57
     * @param int $off_time time in milliseconds that deactivate the drawer
58
     */
59 2
    public function drawer($number = self::DRAWER_1, $on_time = 120, $off_time = 240)
60
    {
61 2
        $this->model->getProfile()->drawer($number, $on_time, $off_time);
62 2
        return $this;
63
    }
64
65 1
    public function draw($image, $align = self::ALIGN_LEFT)
66
    {
67 1
        $this->model->getProfile()->draw($image, $align);
68 1
        return $this;
69
    }
70
71 2
    public function write($text, $styles = 0, $align = self::ALIGN_LEFT)
72
    {
73 2
        $this->model->getProfile()->write($text, $styles, $align);
74 2
        return $this;
75
    }
76
77 1
    public function writeln($text, $styles = 0, $align = self::ALIGN_LEFT)
78
    {
79 1
        if (strlen($text) > 0) {
80 1
            $this->write($text, $styles, $align);
81
        }
82 1
        $this->feed();
83 1
        return $this;
84
    }
85
86 2
    public function feed($lines = 1)
87
    {
88 2
        $this->model->getProfile()->feed($lines);
89 2
        return $this;
90
    }
91
92 4
    public function getColumns()
93
    {
94 4
        return $this->model->getProfile()->getColumns();
95
    }
96
97
    /**
98
     * Set columns aproximated to informed
99
     * @param int $columns aproximated number of columns
100
     */
101 4
    public function setColumns($columns)
102
    {
103 4
        $this->model->getProfile()->setColumns($columns);
104 4
        return $this;
105
    }
106
107 1
    public function close()
108
    {
109 1
        $this->model->getProfile()->finalize();
110 1
        return $this;
111
    }
112
}
113