Completed
Push — master ( 1b5410...64fdd0 )
by Jean C.
28s
created

EscrowTest::testShouldReleaseEscrow()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 14
rs 9.4285
1
<?php
2
3
namespace Moip\Tests\Resource;
4
5
use Moip\Tests\TestCase;
6
7
class EscrowTest extends TestCase
8
{
9
    public function testShouldReleaseEscrow()
10
    {
11
        $this->mockHttpSession($this->body_order);
12
        $order = $this->createOrder()->create();
13
        $cc = '5555666677778884';
14
        $this->mockHttpSession($this->body_cc_pay_pci_escrow);
15
        $payment = $order->payments()
0 ignored issues
show
Bug introduced by
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...
16
            ->setCreditCard(5, 2018, $cc, 123, $this->createCustomer(), false)
17
            ->setEscrow('teste de descricao')
18
            ->execute();
19
        $this->mockHttpSession($this->body_release_escrow);
20
        $escrow = $payment->escrows()->release();
21
        $this->assertEquals('RELEASED', $escrow->getStatus());
22
    }
23
}
24