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

ARBCreateSubscriptionRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 28
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A setSubscription() 0 5 1
A attachData() 0 4 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