Passed
Push — master ( c53cee...93d9dd )
by Luiz Kim
02:23
created

OrderService::calculateOrderPrice()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 9.9666
1
<?php
2
3
namespace ControleOnline\Service;
4
5
use ControleOnline\Entity\Order;
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\Status;
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
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
13
class OrderService
14
{
15
    private $request;
16
17
    public function __construct(
18
        private EntityManagerInterface $manager,
19
        private Security $security,
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
        RequestStack $requestStack
22
23
    ) {
24
        $this->request  = $requestStack->getCurrentRequest();
25
    }
26
27
    public function calculateOrderPrice(Order $order)
28
    {
29
        $sql = 'SELECT SUM(total) as total FROM order_product WHERE order_id = :order_id';
30
        $connection = $this->manager->getConnection();
31
        $statement = $connection->prepare($sql);
32
        $statement->execute(['order_id' =>  $order->getId()]);
33
34
        $result = $statement->fetchOne();
35
        $order->setPrice($result);
36
        $this->manager->persist($order);
37
        $this->manager->flush();
38
        return $order;
39
    }
40
    public function createOrder(People $receiver, People $payer)
41
    {
42
        $status = $this->manager->getRepository(Status::class)->findOneBy([
43
            'status' => 'waiting payment',
44
            'context' => 'order'
45
        ]);
46
        
47
        $order = new Order();
48
        $order->setProvider($receiver);
49
        $order->setClient($payer);
50
        $order->setPayer($payer);
51
        $order->setOrderType('sale');
52
        $order->setStatus($status);
53
        $order->setApp('Asaas');
54
55
        $this->manager->persist($order);
56
        $this->manager->flush();
57
        return $order;
58
    }
59
60
    public function secutiryFilter(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

60
    public function secutiryFilter(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

60
    public function secutiryFilter(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...
61
    {
62
        $companies   = $this->PeopleService->getMyCompanies();
63
64
        if ($invoice = $this->request->query->get('invoiceId', null)) {
65
            $queryBuilder->join(sprintf('%s.invoice', $rootAlias), 'OrderInvoice');
66
            $queryBuilder->andWhere(sprintf('OrderInvoice.invoice IN(:invoice)', $rootAlias, $rootAlias));
67
            $queryBuilder->setParameter('invoice', $invoice);
68
        }
69
70
        $queryBuilder->andWhere(sprintf('%s.client IN(:companies) OR %s.provider IN(:companies)', $rootAlias, $rootAlias));
71
        $queryBuilder->setParameter('companies', $companies);
72
73
        if ($provider = $this->request->query->get('provider', null)) {
74
            $queryBuilder->andWhere(sprintf('%s.provider IN(:provider)', $rootAlias));
75
            $queryBuilder->setParameter('provider', preg_replace("/[^0-9]/", "", $provider));
76
        }
77
78
        if ($client = $this->request->query->get('client', null)) {
79
            $queryBuilder->andWhere(sprintf('%s.client IN(:client)', $rootAlias));
80
            $queryBuilder->setParameter('client', preg_replace("/[^0-9]/", "", $client));
81
        }
82
    }
83
}
84