Test Setup Failed
Push — master ( b9c0be...6a3b1f )
by Francimar
06:58
created

Daruma::fontChanged()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.9666
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3
1
<?php
2
3
namespace Thermal\Profile;
4
5
use Thermal\Printer;
6
7
class Daruma extends Epson
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
    public 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
    public function feed($lines)
80
    {
81 1
        if ($lines > 1) {
82 1
            $this->getConnection()->write(\str_repeat("\r\n", $lines));
83
        } else {
84 1
            $this->getConnection()->write("\r\n");
85
        }
86 1
        return $this;
87
    }
88
89 1
    public function qrcode($data, $size)
90
    {
91 1
        $len = strlen($data) + 2;
92 1
        $pL = $len & 0xFF;
0 ignored issues
show
Coding Style introduced by
$pL does not seem to conform to the naming convention (^[a-z_][a-z0-9_]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
93 1
        $pH = ($len >> 8) & 0xFF;
0 ignored issues
show
Coding Style introduced by
$pH does not seem to conform to the naming convention (^[a-z_][a-z0-9_]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
94
        
95 1
        $error = 'M';
96 1
        $size = min(7, max(3, $size ?: 4));
97 1
        $this->getConnection()->write("\e\x81");
98 1
        $this->getConnection()->write(chr($pL) . chr($pH));
0 ignored issues
show
Coding Style introduced by
$pL does not seem to conform to the naming convention (^[a-z_][a-z0-9_]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
99 1
        $this->getConnection()->write(chr($size) . $error);
100 1
        $this->getConnection()->write($data);
101 1
    }
102
103 1
    protected function getBitmapCmd()
104
    {
105 1
        return "\e*m";
106
    }
107
}
108