Issues (15)

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.

Services/MailChimp.php (1 issue)

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
 * This file is part of the MailChimpEcommerceBundle package.
4
 *
5
 * Copyright (c) 2017 kevin92dev.es
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * Feel free to edit as you please, and have fun.
11
 *
12
 * @author Kevin Murillo <[email protected]>
13
 */
14
15
namespace Kevin92dev\MailChimpEcommerceBundle\Services;
16
17
use Kevin92dev\MailChimpEcommerceBundle\Exceptions\CustomerNotFoundException;
18
use Kevin92dev\MailChimpEcommerceBundle\Exceptions\OrderNotFoundException;
19
use Kevin92dev\MailChimpEcommerceBundle\Exceptions\ProductNotFoundException;
20
use Kevin92dev\MailChimpEcommerceBundle\RequestTypes;
21
use GuzzleHttp\Client;
22
use GuzzleHttp\Exception\RequestException;
23
24
/**
25
 * Mailchimp
26
 *
27
 * @author Kevin Murillo <[email protected]>
28
 */
29
class MailChimp
30
{
31
    /**
32
     * @var string
33
     */
34
    private $apiKey;
35
36
    /**
37
     * @var string
38
     */
39
    private $storeId;
40
41
    /**
42
     * @var Client
43
     */
44
    private $httpClient;
45
46
    /**
47
     * @var string
48
     */
49
    private $endPoint;
50
51
    /**
52
     * Initializes MailChimp
53
     *
54
     * @param string $apiKey Mailchimp api key
55
     * @param string $storeId
56
     * @param Client $httpClient The HTTP Guzzle Client
57
     * @param bool   $ssl Enable secure connectionss
58
     */
59
    public function __construct($apiKey, $storeId, Client $httpClient, $ssl = true)
60
    {
61
        $this->apiKey = $apiKey;
62
        $this->storeId = $storeId;
63
        $this->httpClient = $httpClient;
64
65
        $key = preg_split("/-/", $this->apiKey);
66
67
        if ($ssl) {
68
            $this->endPoint = 'https://'.$key[1].'.api.mailchimp.com/3.0/ecommerce/stores/'.$storeId;
69
        } else {
70
            $this->endPoint = 'http://'.$key[1].'.api.mailchimp.com/3.0/ecommerce/stores'.$storeId;
71
        }
72
    }
73
74
    /**
75
     * MailChimp Requests
76
     *
77
     * @param string $method
78
     * @param array $body
79
     * @param string $resource
80
     *
81
     * @return \Psr\Http\Message\ResponseInterface|null
82
     * @throws CustomerNotFoundException
83
     * @throws ProductNotFoundException
84
     * @throws \Exception
85
     */
86
    public function doRequest($method, $body, $resource = '')
87
    {
88
        $url = $this->endPoint.$resource;
89
90
        // Set auth
91
        $data['auth'] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
92
            'user', $this->apiKey
93
        ];
94
95
        // .. and body
96
        if ($method != RequestTypes::$GET) {
97
            $data['json'] = $body;
98
        }
99
100
        try {
101
            return $this->httpClient->request($method, $url, $data);
102
        } catch (RequestException $e) {
103
            $statusCode = $e->getResponse()->getStatusCode();
104
105
            switch ($statusCode) {
106
                case 404:
107
                    if (strpos($resource, 'products') !== false) {
108
                        throw new ProductNotFoundException();
109
                    } elseif (strpos($resource, 'customers') !== false) {
110
                        throw new CustomerNotFoundException();
111
                    } elseif (strpos($resource, 'orders') !== false) {
112
                        throw new OrderNotFoundException();
113
                    }
114
                    break;
115
                default:
116
                    throw new \Exception($e->getResponse()->getBody());
117
            }
118
        }
119
    }
120
}
121