Passed
Push — master ( 920a4b...b6be85 )
by
unknown
03:45
created

DecryptPaymentDataRequest::attachData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 2
1
<?php
2
3
namespace CommerceGuys\AuthNet;
4
5
use GuzzleHttp\Client;
6
use CommerceGuys\AuthNet\Request\RequestInterface;
7
use CommerceGuys\AuthNet\DataTypes\OpaqueData;
8
9
/**
10
 * Use this method to decrypt the VISA Checkout data.
11
 *
12
 * @link http://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-credit-card
13
 */
14
class DecryptPaymentDataRequest extends BaseApiRequest
15
{
16
    protected $opaqueData;
17
    protected $refId = '';
18
    protected $callId = '';
19
20
    public function __construct(
21
        Configuration $configuration,
22
        Client $client,
23
        OpaqueData $opaqueData = null,
24
        $refId,
25
        $callId
26
    ) {
27
          parent::__construct($configuration, $client);
28
          $this->opaqueData = $opaqueData;
29
          $this->refId = $refId;
30
          $this->callId = $callId;
31
    }
32
33
    protected function attachData(RequestInterface $request)
34
    {
35
      $request->addDataType($this->opaqueData);
0 ignored issues
show
Bug introduced by
It seems like $this->opaqueData 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...
36
      $request->addData('refId', $this->refId);
37
      $request->addData('callId', $this->callId);
38
    }
39
}
40