Passed
Push — master ( 848038...ea0350 )
by Luiz Kim
02:16
created

ProductService::getProductsInventory()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 3
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 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...
9
use Symfony\Component\Security\Core\Security;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Security\Core\Security 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 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...
11
12
class ProductService
13
{
14
    public function __construct(
15
        private EntityManagerInterface $manager,
16
        private Security $security,
17
        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...
18
        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...
19
    ) {}
20
21
    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

21
    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 $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

21
    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...
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

21
    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 $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

21
    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...
22
    {
23
        // $this->PeopleService->checkCompany('company', $queryBuilder, $resourceClass, $applyTo, $rootAlias);
24
    }
25
26
    public function getProductsInventory(?People $company): array
27
    {
28
        return $this->manager->getRepository(Product::class)->getProductsInventory($company);
29
    }
30
31
    public function productsInventoryPrintData(?People $provider, string $printType, string $deviceType)
32
    {
33
        $products = $this->getProductsInventory($provider);
34
35
        $groupedByInventory = [];
36
        foreach ($products as $product) {
37
            $inventoryName = $product['inventory_name'];
38
            if (!isset($groupedByInventory[$inventoryName])) {
39
                $groupedByInventory[$inventoryName] = [];
40
            }
41
            $groupedByInventory[$inventoryName][] = $product;
42
        }
43
44
        foreach ($groupedByInventory as $inventoryName => $items) {
45
            $companyName = $items[0]['company_name'] ;
46
            $this->printService->addLine("", "", "-");
47
            $this->printService->addLine($companyName, "", " ");
48
            $this->printService->addLine("INVENTARIO: " . $inventoryName, "", " ");
49
            $this->printService->addLine("", "", "-");
50
            $this->printService->addLine("Produto", "Disponivel", " ");
51
            $this->printService->addLine("", "", "-");
52
53
            foreach ($items as $item) {
54
                $productName = substr($item['product_name'], 0, 20);
55
                if (!empty($item['description'])) {
56
                    $productName .= " " . substr($item['description'], 0, 10);
57
                }
58
                $productName .= " (" . $item['productUnit'] . ")";
59
                $available = str_pad($item['available'], 4, " ", STR_PAD_LEFT);
60
                $this->printService->addLine($productName, $available, " ");
61
            }
62
63
            $this->printService->addLine("", "", "-");
64
        }
65
66
        return $this->printService->generatePrintData($printType, $deviceType);
67
    }
68
69
    public function getPurchasingSuggestion(People $company)
70
    {
71
        return $this->manager->getRepository(Product::class)->getPurchasingSuggestion($company);
72
    }
73
74
    public function purchasingSuggestionPrintData(?People $provider, string $printType, string $deviceType)
75
    {
76
        $products = $this->getPurchasingSuggestion($provider);
0 ignored issues
show
Bug introduced by
It seems like $provider can also be of type null; however, parameter $company of ControleOnline\Service\P...tPurchasingSuggestion() does only seem to accept ControleOnline\Entity\People, maybe add an additional type check? ( Ignorable by Annotation )

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

76
        $products = $this->getPurchasingSuggestion(/** @scrutinizer ignore-type */ $provider);
Loading history...
77
78
        $groupedByCompany = [];
79
        foreach ($products as $product) {
80
            $companyName = $product['company_name'] ;
81
            if (!isset($groupedByCompany[$companyName])) {
82
                $groupedByCompany[$companyName] = [];
83
            }
84
            $groupedByCompany[$companyName][] = $product;
85
        }
86
87
        $this->printService->addLine("", "", "-");
88
        $this->printService->addLine("SUGESTAO DE COMPRA", "", " ");
89
        $this->printService->addLine("", "", "-");
90
91
        foreach ($groupedByCompany as $companyName => $items) {
92
            $this->printService->addLine($companyName, "", " ");
93
            $this->printService->addLine("", "", "-");
94
            $this->printService->addLine("Produto", "Necessario", " ");
95
            $this->printService->addLine("", "", "-");
96
97
            foreach ($items as $item) {
98
                $productName = substr($item['product_name'], 0, 20);
99
                if (!empty($item['description'])) {
100
                    $productName .= " " . substr($item['description'], 0, 10);
101
                }
102
                if (!empty($item['unity'])) {
103
                    $productName .= " (" . $item['unity'] . ")";
104
                }
105
                $needed = str_pad($item['needed'], 4, " ", STR_PAD_LEFT);
106
                $this->printService->addLine($productName, $needed, " ");
107
            }
108
109
            $this->printService->addLine("", "", "-");
110
        }
111
112
        return $this->printService->generatePrintData($printType, $deviceType);
113
    }
114
}
115