Issues (158)

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.

tests/Resource/RefundTest.php (28 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
namespace Moip\Tests\Resource;
4
5
use Moip\Tests\TestCase;
6
7
class RefundTest extends TestCase
8
{
9
    public function testRefundOrderCreditCardFull()
10
    {
11
        $order = $this->paymentCreditCard(false);
12
13
        $this->mockHttpSession($this->body_order_refund_full_cc);
0 ignored issues
show
The property body_order_refund_full_cc does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
14
        $refund = $order->refunds()->creditCardFull();
15
16
        $this->assertNotEmpty($refund->getId());
17
        $this->assertEquals('FULL', $refund->getType());
18
    }
19
20
    public function testRefundOrderCreditCardPartial()
21
    {
22
        $order = $this->paymentCreditCard(false);
23
24
        $this->mockHttpSession($this->body_order_refund_partial_cc);
0 ignored issues
show
The property body_order_refund_partial_cc does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
25
        $refund = $order->refunds()->creditCardPartial(5000);
26
27
        $this->assertNotEmpty($refund->getId());
28
        $this->assertEquals('PARTIAL', $refund->getType());
29
    }
30
31 View Code Duplication
    public function testRefundOrderBankAccountFull()
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...
32
    {
33
        $order = $this->paymentBoleto(false);
34
35
        $this->mockHttpSession($this->body_order_refund_full_bankaccount);
0 ignored issues
show
The property body_order_refund_full_bankaccount does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
36
        $refund = $order->refunds()
37
            ->bankAccountFull('CHECKING', '001', '1584', '9', '00210169', '6', $order->getCustomer());
38
39
        $this->assertNotEmpty($refund->getId());
40
        $this->assertEquals('FULL', $refund->getType());
41
    }
42
43 View Code Duplication
    public function testRefundOrderBankAccountPartial()
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...
44
    {
45
        $order = $this->paymentBoleto(false);
46
47
        $this->mockHttpSession($this->body_payment_refund_partial_bankaccount);
0 ignored issues
show
The property body_payment_refund_partial_bankaccount does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
48
        $refund = $order->refunds()
49
            ->bankAccountPartial(20000, 'SAVING', '001', '1584', '9', '00210169', '6', $order->getCustomer());
50
51
        $this->assertNotEmpty($refund->getId());
52
        $this->assertEquals('PARTIAL', $refund->getType());
53
    }
54
55 View Code Duplication
    public function testRefundPaymentCreditCardFull()
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...
56
    {
57
        $payment = $this->paymentCreditCard();
58
59
        $this->mockHttpSession($this->body_payment_refund_full_cc);
0 ignored issues
show
The property body_payment_refund_full_cc does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
60
        $refund = $payment->refunds()->creditCardFull();
61
62
        $this->assertNotEmpty($refund->getId());
63
        $this->assertEquals('FULL', $refund->getType());
64
    }
65
66
    public function testRefundPaymentCreditCardPartial()
67
    {
68
        $payment = $this->paymentCreditCard();
69
70
        $this->mockHttpSession($this->body_payment_refund_partial_cc);
0 ignored issues
show
The property body_payment_refund_partial_cc does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
71
        $refund = $payment->refunds()->creditCardPartial(5000);
72
73
        $this->assertNotEmpty($refund->getId());
74
        $this->assertEquals('PARTIAL', $refund->getType());
75
    }
76
77 View Code Duplication
    public function testRefundPaymentBankAccountFull()
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...
78
    {
79
        $payment = $this->paymentBoleto();
80
81
        $this->mockHttpSession($this->body_payment_refund_full_bankaccount);
0 ignored issues
show
The property body_payment_refund_full_bankaccount does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
82
        $refund = $payment->refunds()
83
            ->bankAccountFull('CHECKING', '001', '1584', '9', '00210169', '6', $payment->getOrder()->getCustomer());
84
85
        $this->assertNotEmpty($refund->getId());
86
        $this->assertEquals('FULL', $refund->getType());
87
    }
88
89 View Code Duplication
    public function testRefundPaymentBankAccountPartial()
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...
90
    {
91
        $payment = $this->paymentBoleto();
92
93
        $this->mockHttpSession($this->body_payment_refund_partial_bankaccount);
94
        $refund = $payment->refunds()
95
            ->bankAccountPartial(20000, 'SAVING', '001', '1584', '9', '00210169', '6', $payment->getOrder()->getCustomer());
96
97
        $this->assertNotEmpty($refund->getId());
98
        $this->assertEquals('PARTIAL', $refund->getType());
99
    }
100
101 View Code Duplication
    public function testRefundCCFullWithResourceId()
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...
102
    {
103
        $payment = $this->paymentCreditCard();
104
105
        $this->mockHttpSession($this->body_payment_refund_full_cc);
106
        $refund = $this->moip->refunds()->creditCard($payment->getId());
107
108
        $this->assertNotEmpty($refund->getId());
109
        $this->assertEquals('FULL', $refund->getType());
110
    }
111
112 View Code Duplication
    public function testRefundCCPartialWithResourceId()
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...
113
    {
114
        $payment = $this->paymentCreditCard();
115
116
        $this->mockHttpSession($this->body_payment_refund_partial_cc);
117
        $refund = $this->moip->refunds()->creditCard($payment->getId(), 5000);
118
119
        $this->assertNotEmpty($refund->getId());
120
        $this->assertEquals('PARTIAL', $refund->getType());
121
    }
122
123 View Code Duplication
    public function testRefundBankAccountFullWithResourceId()
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
    {
125
        $payment = $this->paymentBoleto();
126
127
        $this->mockHttpSession($this->body_payment_refund_full_bankaccount);
128
        $refund = $this->moip->refunds()->bankAccount($payment->getId(), $this->bankAccount());
129
130
        $this->assertNotEmpty($refund->getId());
131
        $this->assertEquals('FULL', $refund->getType());
132
    }
133
134 View Code Duplication
    public function testRefundBankAccountPartialWithResourceId()
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...
135
    {
136
        $payment = $this->paymentBoleto();
137
138
        $this->mockHttpSession($this->body_payment_refund_partial_bankaccount);
139
        $refund = $this->moip->refunds()->bankAccount($payment->getId(), $this->bankAccount(), 5000);
140
141
        $this->assertNotEmpty($refund->getId());
142
        $this->assertEquals('PARTIAL', $refund->getType());
143
    }
144
145 View Code Duplication
    public function testRefundOrderCCFullWithResourceId()
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...
146
    {
147
        $order = $this->paymentCreditCard(false);
148
149
        $this->mockHttpSession($this->body_order_refund_full_cc);
0 ignored issues
show
The property body_order_refund_full_cc does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
150
        $refund = $this->moip->refunds()->creditCard($order->getId());
151
152
        $this->assertNotEmpty($refund->getId());
153
        $this->assertEquals('FULL', $refund->getType());
154
    }
155
156 View Code Duplication
    public function testRefundOrderCCPartialWithResourceId()
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...
157
    {
158
        $order = $this->paymentCreditCard(false);
159
160
        $this->mockHttpSession($this->body_order_refund_partial_cc);
0 ignored issues
show
The property body_order_refund_partial_cc does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
161
        $refund = $this->moip->refunds()->creditCard($order->getId(), 5000);
162
163
        $this->assertNotEmpty($refund->getId());
164
        $this->assertEquals('PARTIAL', $refund->getType());
165
    }
166
167 View Code Duplication
    public function testRefundOrderBankAccountFullWithResourceId()
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...
168
    {
169
        $order = $this->paymentBoleto(false);
170
171
        $this->mockHttpSession($this->body_order_refund_full_bankaccount);
0 ignored issues
show
The property body_order_refund_full_bankaccount does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
172
        $refund = $this->moip->refunds()->bankAccount($order->getId(), $this->bankAccount());
173
174
        $this->assertNotEmpty($refund->getId());
175
        $this->assertEquals('FULL', $refund->getType());
176
    }
177
178 View Code Duplication
    public function testRefundOrderBankAccountPartialWithResourceId()
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...
179
    {
180
        $order = $this->paymentBoleto(false);
181
182
        $this->mockHttpSession($this->body_order_refund_partial_bankaccount);
0 ignored issues
show
The property body_order_refund_partial_bankaccount does not seem to exist. Did you mean body_order?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
183
        $refund = $this->moip->refunds()->bankAccount($order->getId(), $this->bankAccount(), 5000);
184
185
        $this->assertNotEmpty($refund->getId());
186
        $this->assertEquals('PARTIAL', $refund->getType());
187
    }
188
189
    public function testShouldGetRefund()
190
    {
191
        $payment = $this->paymentCreditCard();
192
193
        $this->mockHttpSession($this->body_payment_refund_full_cc);
194
        $refund_id = $payment->refunds()->creditCardFull()->getId();
195
196
        $this->mockHttpSession($this->body_payment_refund_full_cc);
197
        $refund = $payment->refunds()->get($refund_id);
198
199
        $this->assertEquals($refund_id, $refund->getId());
200
        $this->assertEquals('FULL', $refund->getType());
201
        $this->assertEquals('COMPLETED', $refund->getStatus());
202
    }
203
204
    private function bankAccount()
205
    {
206
        return $this->moip->bankaccount()
207
            ->setType('CHECKING')
208
            ->setBankNumber('237')
209
            ->setAgencyNumber('12346')
210
            ->setAgencyCheckNumber('0')
211
            ->setAccountNumber('12345679')
212
            ->setAccountCheckNumber('7')
213
            ->setHolder('Jose Silva', '22222222222', 'CPF');
214
    }
215
216 View Code Duplication
    private function paymentBoleto($returnPayment = true)
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...
217
    {
218
        $this->mockHttpSession($this->body_order);
219
        $order = $this->createOrder()->create();
220
        $this->mockHttpSession($this->body_billet_pay);
221
        $payment = $order->payments()
0 ignored issues
show
The method payments does only exist in Moip\Resource\Orders, but not in stdClass.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
222
            ->setBoleto(new \DateTime('today +1day'), 'http://dev.moip.com.br/images/logo-header-moip.png')
223
            ->execute();
224
        $this->mockHttpSession('');
225
        $payment->authorize();
226
227
        return $returnPayment ? $payment : $order;
228
    }
229
230 View Code Duplication
    private function paymentCreditCard($returnPayment = true)
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...
231
    {
232
        $this->mockHttpSession($this->body_order);
233
        $order = $this->createOrder()->create();
234
        $this->mockHttpSession($this->body_cc_pay_pci);
235
        $payment = ($order->payments()->setCreditCard(5, 2018, '5555666677778884', 123, $this->createHolder())->execute());
0 ignored issues
show
The method payments does only exist in Moip\Resource\Orders, but not in stdClass.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
236
237
        return $returnPayment ? $payment : $order;
238
    }
239
}
240