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

DecryptPaymentDataRequest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A attachData() 0 6 1
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