Issues (116)

Security Analysis    not enabled

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.

OrderProductCollectionToArrayTransformer.php (1 issue)

Labels
Severity

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
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\OrderBundle\Form\DataTransformer;
14
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Doctrine\Common\Collections\Collection;
17
use Symfony\Component\PropertyAccess\PropertyPathInterface;
18
use WellCommerce\Bundle\CatalogBundle\Entity\ProductPhoto;
19
use WellCommerce\Bundle\CoreBundle\Form\DataTransformer\CollectionToArrayTransformer;
20
use WellCommerce\Bundle\CoreBundle\Helper\Image\ImageHelperInterface;
21
use WellCommerce\Bundle\OrderBundle\Entity\Order;
22
use WellCommerce\Bundle\OrderBundle\Entity\OrderProduct;
23
use WellCommerce\Bundle\OrderBundle\Manager\OrderProductManagerInterface;
24
25
/**
26
 * Class OrderProductCollectionToArrayTransformer
27
 *
28
 * @author  Adam Piotrowski <[email protected]>
29
 */
30
final class OrderProductCollectionToArrayTransformer extends CollectionToArrayTransformer
31
{
32
    /**
33
     * @var OrderProductManagerInterface
34
     */
35
    private $manager;
36
    
37
    /**
38
     * @var ImageHelperInterface
39
     */
40
    private $imageHelper;
41
    
42
    public function setOrderProductManager(OrderProductManagerInterface $manager)
43
    {
44
        $this->manager = $manager;
45
    }
46
    
47
    public function setImageHelper(ImageHelperInterface $imageHelper)
48
    {
49
        $this->imageHelper = $imageHelper;
50
    }
51
    
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function transform($modelData)
56
    {
57
        $values = [];
58
        
59
        if ($modelData instanceof Collection) {
60
            $modelData->map(function (OrderProduct $orderProduct) use (&$values) {
61
                
62
                $variantId = $orderProduct->hasVariant() ? $orderProduct->getVariant()->getId() : 0;
63
                $photo     = $orderProduct->getProduct()->getPhoto();
64
                $photoPath = $photo instanceof ProductPhoto ? $photo->getPath() : '';
65
                $symbol    = $orderProduct->hasVariant() ? $orderProduct->getVariant()->getSymbol() : $orderProduct->getProduct()->getSku();
66
                
67
                $values[] = [
68
                    'id'               => $orderProduct->getId(),
69
                    'product_id'       => $orderProduct->getProduct()->getId(),
70
                    'product_name'     => $orderProduct->getProduct()->translate()->getName(),
0 ignored issues
show
It seems like getName() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
71
                    'gross_amount'     => $orderProduct->getSellPrice()->getGrossAmount(),
72
                    'quantity'         => $orderProduct->getQuantity(),
73
                    'ean'              => $symbol,
74
                    'previousquantity' => $orderProduct->getQuantity(),
75
                    'trackstock'       => $orderProduct->getProduct()->getTrackStock(),
76
                    'tax_rate'         => $orderProduct->getSellPrice()->getTaxRate(),
77
                    'tax_value'        => $orderProduct->getSellPrice()->getTaxAmount(),
78
                    'previousvariant'  => $variantId,
79
                    'variant'          => $variantId,
80
                    'variant_options'  => $this->getVariantOptions($orderProduct),
81
                    'weight'           => $orderProduct->getWeight(),
82
                    'stock'            => $orderProduct->getProduct()->getStock(),
83
                    'thumb'            => null !== $photoPath ? $this->imageHelper->getImage($photoPath, 'medium') : '',
84
                ];
85
            });
86
        }
87
        
88
        return $values;
89
    }
90
    
91
    protected function getVariantOptions(OrderProduct $orderProduct)
92
    {
93
        if ($orderProduct->hasVariant()) {
94
            $options = [];
95
            foreach ($orderProduct->getOptions() as $name => $option) {
96
                $options[] = $option;
97
            }
98
            
99
            return implode(', ', $options);
100
        }
101
        
102
        return '';
103
    }
104
    
105
    public function reverseTransform($modelData, PropertyPathInterface $propertyPath, $values)
106
    {
107
        $collection = new ArrayCollection();
108
        if ($modelData instanceof Order) {
109
            foreach ($values as $product) {
110
                $orderProduct = $this->manager->addUpdateOrderProduct($product, $modelData);
111
                $collection->add($orderProduct);
112
            }
113
            
114
            $this->setProducts($modelData, $collection);
115
        }
116
    }
117
    
118
    private function setProducts(Order $order, Collection $products)
119
    {
120
        $orderProducts = $order->getProducts();
121
        
122
        $orderProducts->map(function (OrderProduct $orderProduct) use ($products, $orderProducts) {
123
            if (false === $products->contains($orderProduct)) {
124
                $orderProducts->removeElement($orderProduct);
125
            }
126
        });
127
        
128
        $order->setProducts($products);
129
    }
130
}
131