Passed
Push — master ( 71234a...e5baf6 )
by Jhao
01:45
created

Printer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 33
ccs 12
cts 15
cp 0.8
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A ask() 0 5 1
A send() 0 3 1
A __construct() 0 4 1
A print() 0 7 2
1
<?php
2
3
/**
4
 * This file is part of PhpAidc LabelPrinter package.
5
 *
6
 * © Appwilio (https://appwilio.com)
7
 * © JhaoDa (https://github.com/jhaoda)
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace PhpAidc\LabelPrinter;
16
17
use PhpAidc\LabelPrinter\Contract\Job;
18
use PhpAidc\LabelPrinter\Contract\Connector;
19
20
final class Printer
21
{
22
    /** @var Connector */
23
    private $connector;
24
25
    /** @var Compiler|null */
26
    private $compiler;
27
28 3
    public function __construct(Connector $connector, ?Compiler $compiler = null)
29
    {
30 3
        $this->connector = $connector;
31 3
        $this->compiler = $compiler;
32 3
    }
33
34 2
    public function print(Job $job): void
35
    {
36 2
        if ($this->compiler === null) {
37 1
            throw new \DomainException();
38
        }
39
40 1
        $this->connector->write($this->compiler->compile($job));
41 1
    }
42
43 1
    public function send($payload): void
44
    {
45 1
        $this->connector->write($payload);
46 1
    }
47
48
    public function ask(string $message)
49
    {
50
        $this->connector->write($message);
51
52
        return $this->connector->read();
53
    }
54
}
55