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.

src/Domain/Charge.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
2
3
/*
4
 * This file is part of the PhpMob package.
5
 *
6
 * (c) Ishmael Doss <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpMob\Omise\Domain;
15
16
use PhpMob\Omise\Country;
17
use PhpMob\Omise\Currency;
18
use PhpMob\Omise\Exception\InvalidRequestArgumentException;
19
use PhpMob\Omise\Model;
20
21
/**
22
 * @author Ishmael Doss <[email protected]>
23
 *
24
 * @property string id
25
 * @property string object
26
 * @property bool livemode
27
 * @property string location
28
 * @property string status
29
 * @property int amount
30
 * @property string currency
31
 * @property string description
32
 * @property string metadata
33
 * @property bool capture
34
 * @property bool authorized
35
 * @property bool reversed
36
 * @property bool paid
37
 * @property string transaction
38
 * @property Card card
39
 * @property int refunded
40
 * @property Pagination refunds
41
 * @property string failureCode
42
 * @property string failureMessage
43
 * @property Customer customer
44
 * @property string ip
45
 * @property Dispute dispute
46
 * @property string created
47
 * @property string returnUri
48
 * @property string authorizeUri
49
 * @property string $cardToken
50
 * @property Source $source
51
 */
52
class Charge extends Model
53
{
54
    const STATUS_FAILED = 'failed';
55
    const STATUS_EXPIRED = 'expired';
56
    const STATUS_PENDING = 'pending';
57
    const STATUS_REVERSED = 'reversed';
58
    const STATUS_SUCCESSFUL = 'successful';
59
60
    const EVENT_CREATE = 'charge.create';
61
    const EVENT_UPDATE = 'charge.update';
62
    const EVENT_CAPTURE = 'charge.capture';
63
    const EVENT_REVERSE = 'charge.reverse';
64
    const EVENT_COMPLETE = 'charge.complete';
65
66
    /**
67
     * {@inheritdoc}
68 6
     */
69
    public function __set($name, $value)
70 6
    {
71 4
        if ('currency' === $name) {
72
            $value = strtolower($value);
73
        }
74 6
75 6
        parent::__set($name, $value);
76
    }
77
78
    /**
79
     * @param string $countryCode
80
     *
81
     * @return array
82 4
     */
83
    public function getCreateData($countryCode = Country::TH)
84 4
    {
85 View Code Duplication
        if (!in_array($this->currency, Currency::getSupporteds($countryCode))) {
0 ignored issues
show
This code seems to be duplicated across 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...
86
            throw new InvalidRequestArgumentException(
87
                sprintf('The currency `%s` is not supported in your country `%s`.', $this->currency, $countryCode)
88
            );
89
        }
90
91 4
        return [
92 4
            'customer' => (string)($this->customer),
93 4
            'card' => $this->card,
94 4
            'amount' => intval($this->amount * Currency::getDivisionOffset($this->currency)),
95 4
            'currency' => $this->currency,
96 4
            'description' => $this->description,
97 4
            'metadata' => $this->metadata,
98 4
            'capture' => $this->capture,
99
            'return_uri' => $this->returnUri,
100
        ];
101
    }
102
103
    /**
104
     * @param string $countryCode
105
     *
106
     * @return array
107
     */
108 View Code Duplication
    public function getCreateUsingTokenData($countryCode = Country::TH)
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...
109
    {
110
        $data = $this->getCreateData($countryCode);
111
        $data['card'] = $this->cardToken;
112
113
        unset($data['customer']);
114
115
        return $data;
116
    }
117
118
    /**
119
     * @param string $countryCode
120 1
     *
121
     * @return array
122
     */
123 1 View Code Duplication
    public function getCreateUsingSourceData($countryCode = Country::TH)
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...
124 1
    {
125
        $data = $this->getCreateData($countryCode);
126
        $data['source'] = $this->source->id;
127
128
        unset($data['card'], $data['customer']);
129
130
        return $data;
131
    }
132
133
    /**
134
     * @return array
135
     */
136
    public function getUpdateData()
137
    {
138
        return [
139
            'description' => $this->description,
140
            'metadata' => $this->metadata,
141
        ];
142
    }
143
144
    /**
145
     * @return array|Refund[]
146
     */
147
    public function getRefunds()
148
    {
149
        if (count($this->refunds)) {
150
            return $this->refunds->data;
151
        }
152
153
        return [];
154
    }
155
156
    /**
157
     * @param $id
158
     *
159
     * @return Refund|null
160
     */
161
    public function findRefunds($id)
162
    {
163
        $charge = array_filter(
164
            $this->getRefunds(),
165
            function (Refund $charge) use ($id) {
166
                return $charge->id === $id;
167
            }
168
        );
169
170
        if (empty($charge)) {
171
            return null;
172
        }
173
174
        return $charge[0];
175
    }
176
}
177