Issues (7)

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/Clients/AmazonPriceClient.php (3 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 namespace Packback\Prices\Clients;
2
3
use Packback\Prices\PriceClient;
4
use ApaiIO\Configuration\GenericConfiguration;
5
use ApaiIO\Operations\Search;
6
use ApaiIO\ApaiIO;
7
8
class AmazonPriceClient extends PriceClient
9
{
10
    const RETAILER = 'amazon';
11
12
    public $conf;
13
    public $container;
14
    public $search;
15
16 16
    public function __construct($config = [])
17
    {
18 16
        $this->conf = new GenericConfiguration();
19 16
        $this->setConfiguration($config);
20 16
        $this->container = new ApaiIO($this->conf);
21 16
        $this->search = new Search();
22 16
    }
23
24 16
    public function setConfiguration($config = [])
25
    {
26 16
        $this->conf
27 16
            ->setCountry('com')
28 16
            ->setAccessKey($config['access_key'])
29 16
            ->setSecretKey($config['secret_key'])
30 16
            ->setAssociateTag($config['associate_tag']);
31 16
        $this->conf->setResponseTransformer('\ApaiIO\ResponseTransformer\XmlToSimpleXmlObject');
32 16
    }
33
34 6
    public function getPricesForIsbns($isbns = [])
35
    {
36 6
        $isbn_groups = [];
37
38 6
        if (count($isbns) > 10) {
39 2
            $isbn_groups = array_chunk($isbns, 10);
40 2
        } else {
41 4
            array_push($isbn_groups, $isbns);
42
        }
43 6
        foreach ($isbn_groups as $isbn_group) {
44 6
            $response = $this->addParam('Condition', 'New')
0 ignored issues
show
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
45 6
                ->addParam('IdType', 'ISBN')
46 6
                ->addParam('ItemId', $isbn_group)
47 6
                ->addParam('Condition', 'All')
48 6
                ->addParam('SearchIndex', 'Books')
49 6
                ->addParam('Operation', 'ItemLookup')
50 6
                ->addParam('Version', '2011-08-01')
51 6
                ->addParam('ResponseGroup', ['Large'])
52 6
                ->addParam('Service', 'AWSECommerceService');
53
54
            // Get response for Marketplace books
55 6
            $response = $this->send();
56
            // If there is an error with the API key, throw an exception
57 6
            if (isset($response->Error)) {
58
                throw new \Exception($response->Error->Code.': '.$response->Error->Message);
59
            }
60 6
            $this->addPricesToCollection($response);
61
            // Get response for only Amazon books
62 6
            $response = $this->addParam('MerchantId', 'Amazon')->send();
63 6
            $this->addPricesToCollection($response);
64 6
        }
65
66 6
        return $this->collection;
67
    }
68
69 6
    public function addPricesToCollection($response)
70
    {
71 6
        if (isset($response->Items->Request->IsValid) && $response->Items->Request->IsValid) {
72 6
            if (isset($response->Items->Item)) {
73 6
                $items = $response->Items->Item;
74 6
                foreach ($items as $key => $item) {
75
                    // Create price objects for each offer
76 6
                    if (isset($item->Offers->Offer)) {
77 6
                        if (is_array($item->Offers->Offer)) {
78 2
                            foreach ($item->Offers->Offer as $offer) {
79 2
                                $this->collection[] = $this->populatePriceData($offer, $item, self::RETAILER);
80 2
                            }
81 2
                        } else {
82 4
                            $this->collection[] = $this->populatePriceData($item->Offers->Offer, $item, self::RETAILER);
83
                        }
84 6
                    }
85 6
                }
86 6
            }
87 6
        }
88 6
        return $this->collection;
89
    }
90
91 10
    public function populatePriceData($offer, $item, $merchant_id)
92
    {
93
        // New price model object
94 8
        $price = $this->createNewPrice();
95
        // Set retailer
96 8
        $price->retailer = $merchant_id;
97
        // Populate ISBN 13
98 8
        if (isset($item->ItemAttributes->EAN)) {
99 6
            $price->isbn13 = $item->ItemAttributes->EAN;
100 8
        } elseif (isset($item->ItemAttributes->EISBN)) {
101 2
            $price->isbn13 = $item->ItemAttributes->EISBN;
102 2
        }
103
        // Populate URL
104 10
        if (isset($item->DetailPageURL)) {
105 8
            $price->url = $item->DetailPageURL;
106 8
        }
107
        // Populate condition
108 8
        $price->condition = parent::getConditionFromString($offer->OfferAttributes->Condition);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getConditionFromString() instead of populatePriceData()). Are you sure this is correct? If so, you might want to change this to $this->getConditionFromString().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
109
        // Populate term
110 8
        $price->term = parent::TERM_PERPETUAL;
111
        // Populate Price
112 8
        $price->price = ((float)$offer->OfferListing->Price->Amount)/100;
0 ignored issues
show
Documentation Bug introduced by
The property $price was declared of type string, but (double) $offer->OfferLi...ng->Price->Amount / 100 is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
113 8
        return $price;
114
    }
115
116 6
    public function addParam($key, $value)
117
    {
118 6
        $this->search->{'set'.$key}($value);
119 6
        return $this;
120
    }
121
122 10
    public function send()
123
    {
124 10
        $response = $this->container->runOperation($this->search);
125 8
        return json_decode(json_encode($response));
126
    }
127
}
128