LinksTest::testGetCheckoutLink()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Moip\Tests\Helper;
4
5
use Moip\Tests\TestCase;
6
7
class LinksTest extends TestCase
8
{
9
    public function testGetLinkWithoutCheckout()
10
    {
11
        $this->sandbox_mock = self::MOCK;
12
        $this->mockHttpSession($this->body_order);
13
        $order = $this->createOrder()->create();
14
        $this->mockHttpSession($this->body_billet_pay);
15
        $payment = $order->payments()->setBoleto(new \DateTime('today +1day'), 'http://dev.moip.com.br/images/logo-header-moip.png')->execute();
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
17
        $this->assertEquals('https://checkout-sandbox.moip.com.br/boleto/PAY-XNVIBO5MIQ9S', $payment->getLinks()->getLink('payBoleto'));
18
    }
19
20
    public function testGetCheckoutLink()
21
    {
22
        $this->sandbox_mock = self::MOCK;
23
        $this->mockHttpSession($this->body_order);
24
        $order = $this->createOrder()->create();
25
26
        $this->assertEquals('https://checkout-sandbox.moip.com.br/creditcard/ORD-HG479ZEIB7LV', $order->getLinks()->getCheckout('payCreditCard'));
0 ignored issues
show
Bug introduced by
The method getLinks 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...
27
    }
28
29
    public function testGetAllCheckoutLinks()
30
    {
31
        $this->mockHttpSession($this->body_order);
32
        $order = $this->createOrder()->create();
33
34
        $this->assertNotEmpty($order->getLinks()->getAllCheckout());
0 ignored issues
show
Bug introduced by
The method getLinks 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...
35
    }
36
}
37