Completed
Push — master ( 06db8f...7dd0ed )
by Francimar
04:19
created

Diebold::drawer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 10
cts 10
cp 1
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
1
<?php
2
3
namespace Thermal\Profile;
4
5
use Thermal\Printer;
6
7
class Diebold extends Elgin
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 => '0'
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
        $on_time = min((int)($on_time / 2), 65);
26 1
        $off_time = min((int)($off_time / 2), 65);
27 1
        $this->getConnection()->write("\e&" . $index[$number] . chr($on_time) . chr($off_time));
28 1
        return $this;
29
    }
30
}
31