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/CustomerService.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
 * 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\Entities\Customer;
18
use Kevin92dev\MailChimpEcommerceBundle\Entities\Address;
19
use Kevin92dev\MailChimpEcommerceBundle\Exceptions\CustomerNotFoundException;
20
use Kevin92dev\MailChimpEcommerceBundle\RequestTypes;
21
22
/**
23
 * CustomerService
24
 *
25
 * @author Kevin Murillo <[email protected]>
26
 */
27
class CustomerService
28
{
29
    /**
30
     * @var MailChimp
31
     */
32
    private $mailChimp;
33
34
    /**
35
     * Initializes CustomerService
36
     *
37
     * @param MailChimp $mailChimp
38
     */
39
    public function __construct(MailChimp $mailChimp)
40
    {
41
        $this->mailChimp = $mailChimp;
42
    }
43
44
    /**
45
     * Create a new customer in MailChimp
46
     *
47
     * @var Customer $customer
48
     */
49
    public function create(Customer $customer)
50
    {
51
        $method = RequestTypes::$POST;
52
        $resource = '/customers';
53
54
        $body = [
55
            'id' => strval($customer->getId()),
56
            'email_address' => strval($customer->getEmail()),
57
            'opt_in_status' => boolval($customer->isOptInStatus()),
58
            'company' => strval($customer->getCompany()),
59
            'first_name' => strval($customer->getFirstname()),
60
            'last_name' => strval($customer->getLastname()),
61
            'orders_count' => intval($customer->getOrdersCount()),
62
            'total_spent' => floatval($customer->getTotalSpent()),
63
        ];
64
65
        if ($customer->getAddress() instanceof Address) {
66
            $this->addAddress($customer, $body);
67
        }
68
69
        $this->mailChimp->doRequest($method, $body, $resource);
70
    }
71
72
    /**
73
     * Edit a customer in MailChimp
74
     *
75
     * @var Customer $customer
76
     */
77
    public function edit(Customer $customer)
78
    {
79
        $method = RequestTypes::$PATCH;
80
        $resource = '/customers/'.$customer->getId();
81
82
        $body = [
83
            'opt_in_status' => boolval($customer->isOptInStatus()),
84
            'company' => strval($customer->getCompany()),
85
            'first_name' => strval($customer->getFirstname()),
86
            'last_name' => strval($customer->getLastname()),
87
            'orders_count' => intval($customer->getOrdersCount()),
88
            'total_spent' => floatval($customer->getTotalSpent())
89
        ];
90
91
        if ($customer->getAddress() instanceof Address) {
92
            $this->addAddress($customer, $body);
93
        }
94
95
        $this->mailChimp->doRequest($method, $body, $resource);
96
    }
97
98
    /**
99
     * Read customers from MailChimp
100
     *
101
     * @param Customer $customer
102
     * @param int $count
103
     * @param int $offset
104
     *
105
     * @return null|string
106
     */
107 View Code Duplication
    public function read(Customer $customer = null, $count = 50, $offset = 0)
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
108
    {
109
        $method = RequestTypes::$GET;
110
111
        if ($customer instanceof Customer) {
112
            $resource = '/customers/'.$customer->getId();
113
        } else {
114
            $resource = '/customers';
115
        }
116
117
        $resource .= '?count='.$count.'&offset='.$offset;
118
119
        $data = [];
120
121
        try {
122
            $request = $this->mailChimp->doRequest($method, $data, $resource);
123
        } catch (CustomerNotFoundException $e) {
124
            return null;
125
        }
126
127
        return $request->getBody()->getContents();
128
    }
129
130
    /**
131
     * Delete a customer from MailChimp
132
     *
133
     * @var Customer $customer
134
     */
135
    public function delete(Customer $customer)
136
    {
137
        $method = RequestTypes::$DELETE;
138
        $resource = '/customers/'.$customer->getId();
139
140
        $this->mailChimp->doRequest($method, null, $resource);
0 ignored issues
show
null is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
141
    }
142
143
    /**
144
     * Add address to a customer
145
     *
146
     * @param Customer $customer
147
     * @param array    $body
148
     */
149
    public function addAddress(Customer $customer, &$body)
150
    {
151
        $address = $customer->getAddress();
152
153
        $body['address'] = [
154
            'address1' => strval($address->getAddress1()),
155
            'address2' => strval($address->getAddress2()),
156
            'city' => strval($address->getCity()),
157
            'province' => strval($address->getProvince()),
158
            'province_code' => strval($address->getProvinceCode()),
159
            'postal_code' => strval($address->getPostalCode()),
160
            'country' => strval($address->getCountry()),
161
            'country_code' => strval($address->getCountryCode())
162
        ];
163
    }
164
}