Test Failed
Push — master ( 0ba858...da6932 )
by Francimar
05:42
created

Daruma::setMode()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 8.9617
c 0
b 0
f 0
cc 6
nc 8
nop 2
crap 6
1
<?php
2
3
namespace Thermal\Profile;
4
5
use Thermal\Printer;
6
7
class Daruma extends EscPOS
8
{
9
    /**
10
     * @param int $number drawer id
11
     * @param int $on_time time in milliseconds that activate the drawer
12
     * @param int $off_time time in milliseconds that deactivate the drawer
13
     */
14 1
    public function drawer($number, $on_time, $off_time)
15
    {
16
        $index = [
17 1
            Printer::DRAWER_1 => "p"
18
        ];
19 1
        if (!isset($index[$number])) {
20 1
            throw new \Exception(
21 1
                sprintf('Drawer %d not available for printer "%s"', $this->getName(), intval($number)),
22 1
                404
23
            );
24
        }
25 1
        $this->getConnection()->write("\e" . $index[$number]);
26 1
        return $this;
27
    }
28
29 2
    protected function setAlignment($align)
30
    {
31
        $cmd = [
32 2
            Printer::ALIGN_LEFT => "\ej0",
33
            Printer::ALIGN_CENTER => "\ej1",
34
            Printer::ALIGN_RIGHT => "\ej2"
35
        ];
36 2
        $this->getConnection()->write($cmd[$align]);
37 2
    }
38
39 2
    protected function setStyle($style, $enable)
40
    {
41 2
        if ($enable) {
42
            // enable styles
43 2
            if (Printer::STYLE_BOLD == $style) {
44 1
                $this->getConnection()->write("\eE");
45 2
                return $this;
46
            }
47
        } else {
48
            // disable styles
49 2
            if (Printer::STYLE_BOLD == $style) {
50 1
                $this->getConnection()->write("\eF");
51 1
                return $this;
52
            }
53
        }
54 2
        return parent::setStyle($style, $enable);
55
    }
56
57 2
    protected function setMode($mode, $enable)
58
    {
59 2
        if ($enable) {
60
            // enable styles
61 2
            if (Printer::STYLE_DOUBLE_WIDTH & $mode) {
62 1
                $this->getConnection()->write("\x0E");
63
            }
64 2
            if (Printer::STYLE_DOUBLE_HEIGHT & $mode) {
65 2
                $this->getConnection()->write("\ew1");
66
            }
67
        } else {
68
            // disable styles
69 2
            if (Printer::STYLE_DOUBLE_HEIGHT & $mode) {
70 1
                $this->getConnection()->write("\ew0");
71
            }
72 2
            if (Printer::STYLE_DOUBLE_WIDTH & $mode) {
73 1
                $this->getConnection()->write("\x14");
74
            }
75
        }
76 2
        return $this;
77
    }
78
79 1
    protected function fontChanged($new_font, $old_font)
80
    {
81 1
        if ($new_font['name'] == 'Font A') {
82 1
            $this->getConnection()->write("\e\xC6XXXXXXXXXX0XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
83 1
        } elseif ($new_font['name'] == 'Font B') {
84 1
            $this->getConnection()->write("\e\xC6XXXXXXXXXX1XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
85
        }
86 1
        return $this;
87
    }
88
89 1
    public function feed($lines)
90
    {
91 1
        if ($lines > 1) {
92 1
            $this->getConnection()->write(\str_repeat("\r\n", $lines));
93
        } else {
94 1
            $this->getConnection()->write("\r\n");
95
        }
96 1
        return $this;
97
    }
98
99 1
    protected function getBitmapCmd()
100
    {
101 1
        return "\e*m";
102
    }
103
}
104