Issues (2)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Entity/OrderLineTrait.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Loevgaard\DandomainStock\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\ORM\Mapping as ORM;
9
use Loevgaard\DandomainStock\Entity\Generated\StockMovementInterface;
10
use Loevgaard\DandomainStock\Exception\StockMovementProductMismatchException;
11
12
trait OrderLineTrait
13
{
14
    /**
15
     * @var StockMovement[]|ArrayCollection
16
     *
17
     * @ORM\OneToMany(targetEntity="Loevgaard\DandomainStock\Entity\StockMovement", mappedBy="orderLine", cascade={"persist"})
18
     */
19
    protected $stockMovements;
20
21
    /**
22
     * @param \Loevgaard\DandomainStock\Entity\Generated\StockMovementInterface $stockMovement
23
     *
24
     * @return OrderLineTrait
0 ignored issues
show
Comprehensibility Bug introduced by
The return type OrderLineTrait is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
25
     *
26
     * @throws \Loevgaard\DandomainStock\Exception\StockMovementProductMismatchException
27
     */
28
    public function addStockMovement(StockMovementInterface $stockMovement)
29
    {
30
        $this->initStockMovements();
31
32
        if ($this->stockMovements->count()) {
33
            /** @var StockMovement $firstStockMovement */
34
            $firstStockMovement = $this->stockMovements->first();
35
            if ($stockMovement->getProduct()->getId() !== $firstStockMovement->getProduct()->getId()) {
36
                throw new StockMovementProductMismatchException('The product id of the first product is `'.$firstStockMovement->getProduct()->getId().'` while the one you are adding has this id: `'.$stockMovement->getProduct()->getId().'`');
37
            }
38
        }
39
40
        if (!$this->stockMovements->contains($stockMovement)) {
41
            $this->stockMovements->add($stockMovement);
42
        }
43
44
        return $this;
45
    }
46
47
    /**
48
     * @return \Loevgaard\DandomainStock\Entity\StockMovement[]
49
     */
50
    public function getStockMovements()
51
    {
52
        $this->initStockMovements();
53
54
        return $this->stockMovements;
55
    }
56
57
    /**
58
     * @param \Loevgaard\DandomainStock\Entity\Generated\StockMovementInterface[] $stockMovements
59
     *
60
     * @return OrderLineTrait
0 ignored issues
show
Comprehensibility Bug introduced by
The return type OrderLineTrait is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
61
     *
62
     * @throws \Loevgaard\DandomainStock\Exception\StockMovementProductMismatchException
63
     */
64
    public function setStockMovements($stockMovements)
65
    {
66
        foreach ($stockMovements as $stockMovement) {
67
            $this->addStockMovement($stockMovement);
68
        }
69
70
        return $this;
71
    }
72
73
    /**
74
     * Say you have these two stock movements associated with this order line:.
75
     *
76
     * | qty | product |
77
     * -----------------
78
     * | 1   | Jeans   |
79
     * | -1  | Jeans   |
80
     *
81
     * Then the effective stock movement would be
82
     *
83
     * | qty | product |
84
     * -----------------
85
     * | 0   | Jeans   |
86
     *
87
     * And this is what we return in this method
88
     *
89
     * Returns null if the order line has 0 stock movements
90
     *
91
     * @return \Loevgaard\DandomainStock\Entity\Generated\StockMovementInterface|null
92
     *
93
     * @throws \Loevgaard\DandomainStock\Exception\CurrencyMismatchException
94
     * @throws \Loevgaard\DandomainStock\Exception\UnsetCurrencyException
95
     */
96
    public function computeEffectiveStockMovement(): ?StockMovementInterface
97
    {
98
        $this->initStockMovements();
99
100
        if (!$this->stockMovements->count()) {
101
            return null;
102
        }
103
104
        /** @var StockMovementInterface $lastStockMovement */
105
        $lastStockMovement = $this->stockMovements->last();
106
107
        $qty = 0;
108
        foreach ($this->stockMovements as $stockMovement) {
109
            $qty += $stockMovement->getQuantity();
110
        }
111
112
        $stockMovement = $lastStockMovement->copy();
113
        $stockMovement->setQuantity($qty);
114
115
        return $stockMovement;
116
    }
117
118
    protected function initStockMovements(): void
119
    {
120
        if (is_null($this->stockMovements)) {
121
            $this->stockMovements = new ArrayCollection();
122
        }
123
    }
124
}
125