OrderService::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 1
c 3
b 0
f 0
dl 0
loc 8
rs 10
cc 1
nc 1
nop 5
1
<?php
2
3
namespace ControleOnline\Service;
4
5
use ControleOnline\Entity\ExtraFields;
0 ignored issues
show
Bug introduced by
The type ControleOnline\Entity\ExtraFields 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\Order;
7
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...
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\Authentication\Token\Storage\TokenStorageInterface as Security;
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...
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
use Symfony\Component\HttpFoundation\RequestStack;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\RequestStack 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...
12
use Doctrine\DBAL\Types\Type;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Types\Type 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 OrderService
15
{
16
    private $request;
17
18
    public function __construct(
19
        private EntityManagerInterface $manager,
20
        private Security $security,
21
        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...
22
        private StatusService $statusService,
0 ignored issues
show
Bug introduced by
The type ControleOnline\Service\StatusService 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...
23
        RequestStack $requestStack
24
    ) {
25
        $this->request  = $requestStack->getCurrentRequest();
26
    }
27
28
    public function calculateOrderPrice(Order $order)
29
    {
30
        $sql = 'UPDATE orders O
31
                JOIN (
32
                    SELECT order_id, IFNULL(SUM(total), 0) AS new_total
33
                    FROM order_product
34
                    WHERE order_product_id IS NULL
35
                    GROUP BY order_id
36
                ) AS subquery ON O.id = subquery.order_id
37
                SET O.price = IFNULL(subquery.new_total, 0)
38
                WHERE O.id = :order_id;
39
                ';
40
        $connection = $this->manager->getConnection();
41
        $statement = $connection->prepare($sql);
42
        $statement->bindValue(':order_id', $order->getId(), Type::getType('integer'));
43
        $statement->executeStatement();
44
45
        return $order;
46
    }
47
48
    public function calculateGroupProductPrice(Order $order)
49
    {
50
        $sql = 'UPDATE order_product OPO
51
                JOIN (
52
                    SELECT 
53
                        OP.order_product_id,
54
                        (CASE 
55
                            WHEN PG.price_calculation = "biggest" THEN MAX(PGP.price)
56
                            WHEN PG.price_calculation = "sum" THEN SUM(PGP.price)
57
                            WHEN PG.price_calculation = "average" THEN AVG(PGP.price) 
58
                            WHEN PG.price_calculation = "free" THEN 0
59
                            ELSE NULL
60
                        END) AS calculated_price
61
                    FROM order_product OP
62
                    INNER JOIN product_group PG ON OP.product_group_id = PG.id
63
                    INNER JOIN product_group_product PGP ON PGP.product_group_id = OP.product_group_id AND PGP.product_child_id = OP.product_id
64
                    INNER JOIN product P ON P.id = OP.product_id
65
                    WHERE OP.parent_product_id IS NOT NULL AND OP.order_id = :order_id
66
                    GROUP BY OP.order_product_id, PG.id
67
                ) AS subquery ON OPO.id = subquery.order_product_id
68
                SET OPO.price = subquery.calculated_price,
69
                    OPO.total = (subquery.calculated_price * OPO.quantity)
70
                ';
71
        $connection = $this->manager->getConnection();
72
        $statement = $connection->prepare($sql);
73
        $statement->bindValue(':order_id', $order->getId(), Type::getType('integer'));
74
        $statement->executeStatement();
75
76
        return $order;
77
    }
78
79
    public function createOrder(People $receiver, People $payer, $app)
80
    {
81
82
        $status = $this->statusService->discoveryStatus(
83
            'pending',
84
            'waiting payment',
85
            'order'
86
        );
87
88
        $order = new Order();
89
        $order->setProvider($receiver);
90
        $order->setClient($payer);
91
        $order->setPayer($payer);
92
        $order->setOrderType('sale');
93
        $order->setStatus($status);
94
        $order->setApp($app);
95
96
        $this->manager->persist($order);
97
        $this->manager->flush();
98
        return $order;
99
    }
100
101
    public function securityFilter(QueryBuilder $queryBuilder, $resourceClass = null, $applyTo = null, $rootAlias = null): void
0 ignored issues
show
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

101
    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

101
    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...
102
    {
103
        $companies   = $this->peopleService->getMyCompanies();
104
105
        if ($invoice = $this->request->query->get('invoiceId', null)) {
106
            $queryBuilder->join(sprintf('%s.invoice', $rootAlias), 'OrderInvoice');
107
            $queryBuilder->andWhere(sprintf('OrderInvoice.invoice IN(:invoice)', $rootAlias, $rootAlias));
108
            $queryBuilder->setParameter('invoice', $invoice);
109
        }
110
111
        $queryBuilder->andWhere(sprintf('%s.client IN(:companies) OR %s.provider IN(:companies)', $rootAlias, $rootAlias));
112
        $queryBuilder->setParameter('companies', $companies);
113
114
        if ($provider = $this->request->query->get('provider', null)) {
115
            $queryBuilder->andWhere(sprintf('%s.provider IN(:provider)', $rootAlias));
116
            $queryBuilder->setParameter('provider', preg_replace("/[^0-9]/", "", $provider));
117
        }
118
119
        if ($client = $this->request->query->get('client', null)) {
120
            $queryBuilder->andWhere(sprintf('%s.client IN(:client)', $rootAlias));
121
            $queryBuilder->setParameter('client', preg_replace("/[^0-9]/", "", $client));
122
        }
123
    }
124
}
125