Completed
Push — master ( f7d62f...5e8002 )
by Matt
02:53
created

ARBCreateSubscriptionRequest::attachData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace CommerceGuys\AuthNet;
4
5
use GuzzleHttp\Client;
6
use CommerceGuys\AuthNet\DataTypes\Subscription;
7
use CommerceGuys\AuthNet\Request\RequestInterface;
8
9
/**
10
 * Use this method to create subscriptions using Automated Recurring Billing.
11
 */
12
class ARBCreateSubscriptionRequest extends ARBSubscriptionRequest
13
{
14
    protected $subscription;
15
16 1
    public function __construct(
17
        Configuration $configuration,
18
        Client $client,
19
        Subscription $subscription = null
20
    ) {
21 1
        parent::__construct($configuration, $client);
22 1
        $this->subscription = $subscription;
23 1
    }
24
25
    /**
26
     * @param \CommerceGuys\AuthNet\DataTypes\Subscription $subscription
27
     * @return $this
28
     */
29 1
    public function setSubscription(Subscription $subscription)
30
    {
31 1
        $this->subscription = $subscription;
32 1
        return $this;
33
    }
34
35 1
    protected function attachData(RequestInterface $request)
36 1
    {
37 1
        $request->addDataType($this->subscription);
0 ignored issues
show
Bug introduced by
It seems like $this->subscription can be null; however, addDataType() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
38 1
    }
39
}
40