Passed
Push — master ( e7dd88...04553d )
by Luiz Kim
02:45
created

PrintService::generatePrintData()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
eloc 7
c 7
b 0
f 0
dl 0
loc 14
rs 10
cc 3
nc 3
nop 2
1
<?php
2
3
namespace ControleOnline\Service;
4
5
use ControleOnline\Entity\Order;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\Order was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use ControleOnline\Entity\ProductGroupProduct;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\ProductGroupProduct was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use Doctrine\ORM\EntityManagerInterface;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\EntityManagerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use Exception;
9
10
class PrintService
11
{
12
    private $initialSpace = 8;
13
    private $totalChars = 48;
14
    private $text = '';
15
16
    public function __construct(
17
        private EntityManagerInterface $entityManager
18
    ) {}
19
20
    public function addLine($prefix = '', $suffix = '', $delimiter = ' ')
21
    {
22
        $initialSpace = str_repeat(" ", $this->initialSpace);
23
        $count =   $this->totalChars - $this->initialSpace - strlen($prefix) - strlen($suffix);
24
        if ($count > 0)
25
            $delimiter = str_repeat($delimiter, $count);
26
        $this->text .= $initialSpace . $prefix . $delimiter . $suffix . "\n";
27
    }
28
29
    public function generatePrintData($printType, $deviceType)
30
    {
31
32
        if ($printType === 'pos') {
33
            if ($deviceType === 'cielo') {
34
                return [
35
                    "operation" => "PRINT_TEXT",
36
                    "styles" => [[]],
37
                    "value" => [$this->text]
38
                ];
39
            }
40
        }
41
42
        throw new Exception("Printer type not found", 1);
43
    }
44
}
45