Passed
Pull Request — master (#151)
by
unknown
05:33 queued 02:22
created

BillShipper   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 14.81%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 1
dl 0
loc 83
ccs 4
cts 27
cp 0.1481
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A toNode() 0 13 3
A getAccountNumber() 0 4 1
A setAccountNumber() 0 6 1
A getCreditCard() 0 4 1
A setCreditCard() 0 6 1
1
<?php
2
3
namespace Ups\Entity;
4
5
use DOMDocument;
6
7
/**
8
 * @author Eduard Sukharev <[email protected]>
9
 */
10
class BillShipper
11
{
12
    /**
13
     * @var string
14
     */
15
    private $accountNumber;
16
17
    /**
18
     * @var CreditCard
19
     */
20
    private $creditCard;
21
22
    /**
23
     * @param \stdClass|null $attributes
24
     */
25 3
    public function __construct(\stdClass $attributes = null)
26
    {
27 3
        if (isset($attributes->AccountNumber)) {
28
            $this->setAccountNumber($attributes->AccountNumber);
29
        }
30 3
        if (isset($attributes->CreditCard)) {
31
            $this->setAccountNumber(new CreditCard($attributes->CreditCard));
0 ignored issues
show
Documentation introduced by
new \Ups\Entity\CreditCa...attributes->CreditCard) is of type object<Ups\Entity\CreditCard>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
        }
33 3
    }
34
35
    /**
36
     * @param null|DOMDocument $document
37
     *
38
     * @return DOMElement
39
     */
40
    public function toNode(DOMDocument $document = null)
41
    {
42
        if (is_null($document)) {
43
            $document = new DOMDocument();
44
        }
45
46
        $node = $document->createElement('BillShipper');
47
        if ($this->getAccountNumber()) {
48
            $node->appendChild($document->createElement('AccountNumber', $this->getAccountNumber()));
49
        }
50
51
        return $node;
52
    }
53
54
    /**
55
     * @return string
56
     */
57
    public function getAccountNumber()
58
    {
59
        return $this->accountNumber;
60
    }
61
62
    /**
63
     * @param string $accountNumber
64
     *
65
     * @return BillShipper
66
     */
67
    public function setAccountNumber($accountNumber)
68
    {
69
        $this->accountNumber = $accountNumber;
70
71
        return $this;
72
    }
73
74
    /**
75
     * @return CreditCard
76
     */
77
    public function getCreditCard()
78
    {
79
        return $this->creditCard;
80
    }
81
82
    /**
83
     * @param CreditCard $creditCard
84
     * @return BillShipper
85
     */
86
    public function setCreditCard(CreditCard $creditCard)
87
    {
88
        $this->creditCard = $creditCard;
89
90
        return $this;
91
    }
92
}
93