Passed
Pull Request — master (#157)
by Rudger
03:17
created

ServiceOffering::getCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Ups\Entity;
4
5
use DOMDocument;
6
use DOMElement;
7
use Ups\NodeInterface;
8
9
class ServiceOffering implements NodeInterface
10
{
11
12
    const SO_DIRECT_TO_RETAIL = '001';
13
    const SO_NOT_IN_ONE_ADL = '002';
14
    const SO_CLICK_AND_COLLECT = '003';
15
    const SO_RETAIL_TO_RETAIL = '004';
16
    const SO_PICKUP = '005';
17
    const SO_DROP_OFF = '006';
18
    const SO_PUDO = '007';
19
    const SO_EARLY_PICKUP_DELIVERY_TIME = '008';
20
    const SO_ACCEPT_PREPAID_DROP_OFFS = '009';
21
    const SO_DCO_DCR_INTERCEPT_ACCEPTED = '010';
22
    const SO_ACCEPTS_PAYMENTS = '011';
23
    const SO_PAY_AT_STORE = '012';
24
    const SO_ACCEPTS_RESTRICTED_ARTICLES = '013';
25
26
    /**
27
     * @var array
28
     */
29
    private static $serviceOfferingNames = [
30
        '001' => 'Direct To Retail',
31
        '002' => 'Not In One ADL',
32
        '003' => 'Click and Collect',
33
        '004' => 'Retail to Retail',
34
        '005' => 'Pickup',
35
        '006' => 'Drop Off',
36
        '007' => 'PUDO',
37
        '008' => 'Early Pickup Delivery Time',
38
        '009' => 'Accept prepaid drop offs',
39
        '010' => 'DCO DCR intercept accepted',
40
        '011' => 'Accepts Payments',
41
        '012' => 'Pay At Store',
42
        '013' => 'Accepts Restricted Articles',
43
    ];
44
45
    /**
46
     * @var string
47
     */
48
    private $code;
49
50
    /**
51
     * @param null|object $serviceOfferingCode
52
     */
53 1
    public function __construct($serviceOfferingCode)
54
    {
55 1
        $this->code = $serviceOfferingCode;
0 ignored issues
show
Documentation Bug introduced by
It seems like $serviceOfferingCode can also be of type object. However, the property $code is declared as type string. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
56 1
    }
57
58
    /**
59
     * @return array
60
     */
61
    public static function getServiceOfferings()
62
    {
63
        return self::$serviceOfferingNames;
64
    }
65
66
    /**
67
     * @param null|DOMDocument $document
68
     *
69
     * @return DOMElement
70
     */
71 1
    public function toNode(DOMDocument $document = null)
72
    {
73 1
        if (null === $document) {
74
            $document = new DOMDocument();
75
        }
76
77 1
        $node = $document->createElement('ServiceOffering');
78 1
        $node->appendChild($document->createElement('Code', $this->getCode()));
79
80 1
        return $node;
81
    }
82
83
    /**
84
     * @return string
85
     */
86
    public function getName()
87
    {
88
        return self::$serviceOfferingNames[$this->getCode()];
89
    }
90
91
    /**
92
     * @return string
93
     */
94 1
    public function getCode()
95
    {
96 1
        return $this->code;
97
    }
98
99
    /**
100
     * @param string $code
101
     *
102
     * @return $this
103
     */
104
    public function setCode($code)
105
    {
106
        $this->code = $code;
107
108
        return $this;
109
    }
110
}
111