ProductService::getPurchasingSuggestion()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace ControleOnline\Service;
4
5
use ControleOnline\Entity\Device;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\Device 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\People;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\People 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 ControleOnline\Entity\Product;
8
use ControleOnline\Entity\Spool;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\Spool 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...
9
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...
10
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Securi...e\TokenStorageInterface 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...
11
as Security;
12
use Doctrine\ORM\QueryBuilder;
0 ignored issues
show
Bug introduced by
The type Doctrine\ORM\QueryBuilder 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...
13
14
class ProductService
15
{
16
    public function __construct(
17
        private EntityManagerInterface $manager,
18
        private Security $security,
19
        private PrintService $printService,
0 ignored issues
show
Bug introduced by
The type ControleOnline\Service\PrintService 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...
20
        private PeopleService $PeopleService
0 ignored issues
show
Bug introduced by
The type ControleOnline\Service\PeopleService 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...
21
    ) {}
22
23
    public function securityFilter(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void
0 ignored issues
show
Unused Code introduced by
The parameter $queryBuilder is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
    public function securityFilter(/** @scrutinizer ignore-unused */ QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $applyTo is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
    public function securityFilter(QueryBuilder $queryBuilder, $resourceClass = null, /** @scrutinizer ignore-unused */ $applyTo = null, $rootAlias = null): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $resourceClass is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
    public function securityFilter(QueryBuilder $queryBuilder, /** @scrutinizer ignore-unused */ $resourceClass = null, $applyTo = null, $rootAlias = null): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $rootAlias is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
    public function securityFilter(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, /** @scrutinizer ignore-unused */ $rootAlias = null): void

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    {
25
        // $this->PeopleService->checkCompany('company', $queryBuilder, $resourceClass, $applyTo, $rootAlias);
26
    }
27
28
    public function getProductsInventory(People $company): array
29
    {
30
        return $this->manager->getRepository(Product::class)->getProductsInventory($company);
31
    }
32
33
    public function productsInventoryPrintData(People $provider, Device $device): Spool
34
    {
35
        $products = $this->getProductsInventory($provider);
36
37
        $groupedByInventory = [];
38
        foreach ($products as $product) {
39
            $inventoryName = $product['inventory_name'];
40
            if (!isset($groupedByInventory[$inventoryName])) {
41
                $groupedByInventory[$inventoryName] = [];
42
            }
43
            $groupedByInventory[$inventoryName][] = $product;
44
        }
45
46
        foreach ($groupedByInventory as $inventoryName => $items) {
47
            $companyName = $items[0]['company_name'];
48
            $this->printService->addLine("", "", "-");
49
            $this->printService->addLine($companyName, "", " ");
50
            $this->printService->addLine("INVENTARIO: " . $inventoryName, "", " ");
51
            $this->printService->addLine("", "", "-");
52
            $this->printService->addLine("Produto", "Disponivel", " ");
53
            $this->printService->addLine("", "", "-");
54
55
            foreach ($items as $item) {
56
                $productName = substr($item['product_name'], 0, 20);
57
                if (!empty($item['description'])) {
58
                    $productName .= " " . substr($item['description'], 0, 10);
59
                }
60
                $productName .= " (" . $item['productUnit'] . ")";
61
                $available = str_pad($item['available'], 4, " ", STR_PAD_LEFT);
62
                $this->printService->addLine($productName, $available, " ");
63
            }
64
65
            $this->printService->addLine("", "", "-");
66
        }
67
        return $this->printService->generatePrintData($device, $provider);
68
    }
69
70
    public function getPurchasingSuggestion(People $company)
71
    {
72
        return $this->manager->getRepository(Product::class)->getPurchasingSuggestion($company);
73
    }
74
75
    public function purchasingSuggestionPrintData(People $provider, Device $device): Spool
76
    {
77
        $products = $this->getPurchasingSuggestion($provider);
78
79
        $groupedByCompany = [];
80
        foreach ($products as $product) {
81
            $companyName = $product['company_name'];
82
            if (!isset($groupedByCompany[$companyName])) {
83
                $groupedByCompany[$companyName] = [];
84
            }
85
            $groupedByCompany[$companyName][] = $product;
86
        }
87
88
        $this->printService->addLine("", "", "-");
89
        $this->printService->addLine("SUGESTAO DE COMPRA", "", " ");
90
        $this->printService->addLine("", "", "-");
91
92
        foreach ($groupedByCompany as $companyName => $items) {
93
            $this->printService->addLine($companyName, "", " ");
94
            $this->printService->addLine("", "", "-");
95
            $this->printService->addLine("Produto", "Necessario", " ");
96
            $this->printService->addLine("", "", "-");
97
98
            foreach ($items as $item) {
99
                $productName = substr($item['product_name'], 0, 20);
100
                if (!empty($item['description'])) {
101
                    $productName .= " " . substr($item['description'], 0, 10);
102
                }
103
                if (!empty($item['unity'])) {
104
                    $productName .= " (" . $item['unity'] . ")";
105
                }
106
                $needed = str_pad($item['needed'], 4, " ", STR_PAD_LEFT);
107
                $this->printService->addLine($productName, $needed, " ");
108
            }
109
110
            $this->printService->addLine("", "", "-");
111
        }
112
113
        return $this->printService->generatePrintData($device, $provider);
114
    }
115
}
116