Request::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 9.4285
1
<?php namespace SimpleUPS\Track\SmallPackage;
2
3
use \SimpleUPS\Api\MissingParameterException;
4
use \SimpleUPS\UPS;
5
6
/**
7
 * @internal
8
 */
9
class Request extends \SimpleUPS\Track\Request
10
{
11
12
    private
13
        /* @var string $trackingNumber */
14
        $trackingNumber;
15
16
    public function __construct($debug = null)
17
    {
18
        parent::__construct($debug);
19
20
        $this->responseClass = '\SimpleUPS\Track\SmallPackage\Response';
21
    }
22
23
    /**
24
     * Build the validate address request
25
     * @return string
26
     * @throws \SimpleUPS\Api\MissingParameterException
27
     */
28
    public function buildXml()
29
    {
30
        if ($this->getTrackingNumber() === null) {
31
            throw new MissingParameterException('Tracking lookup requires either a tracking number');
32
        }
33
34
        $dom = new \DomDocument('1.0');
35
        $dom->formatOutput = $this->getDebug();
36
        $dom->appendChild($trackingRequest = $dom->createElement('TrackRequest'));
37
        $addressRequestLang = $dom->createAttribute('xml:lang');
38
        $addressRequestLang->value = parent::getXmlLang();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getXmlLang() instead of buildXml()). Are you sure this is correct? If so, you might want to change this to $this->getXmlLang().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
39
        $trackingRequest->appendChild($request = $dom->createElement('Request'));
40
        $request->appendChild($transactionReference = $dom->createElement('TransactionReference'));
41
        $transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext()));
42
43
        $request->appendChild($dom->createElement('RequestAction', 'Track'));
44
        $request->appendChild($dom->createElement('RequestOption', '1'));
45
46
        $trackingRequest->appendChild($shipmentType = $dom->createElement('ShipmentType'));
47
        $shipmentType->appendChild(
48
            $shipmentType = $dom->createElement('Code', \SimpleUPS\Track\Request::TYPE_SMALL_PACKAGE)
49
        );
50
51
        if ($this->getTrackingNumber() !== null) {
52
            $trackingRequest->appendChild($dom->createElement('TrackingNumber', $this->getTrackingNumber()));
53
        }
54
55
        $xml = parent::buildAuthenticationXml() . $dom->saveXML();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (buildAuthenticationXml() instead of buildXml()). Are you sure this is correct? If so, you might want to change this to $this->buildAuthenticationXml().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
56
57
        return $xml;
58
    }
59
60
    /**
61
     * @param string $trackingNumber
62
     */
63
    public function setTrackingNumber($trackingNumber)
64
    {
65
        $this->trackingNumber = $trackingNumber;
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getTrackingNumber()
72
    {
73
        return $this->trackingNumber;
74
    }
75
}