GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( d04245...65c2b5 )
by Michael
45:19 queued 37:26
created

TOrderContext::serializeTdlOrderTimestamp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
rs 9.4286
cc 2
eloc 9
nc 2
nop 0
1
<?php
2
/**
3
 * Copyright (c) 2013-2014 eBay Enterprise, Inc.
4
 *
5
 * NOTICE OF LICENSE
6
 *
7
 * This source file is subject to the Open Software License (OSL 3.0)
8
 * that is bundled with this package in the file LICENSE.md.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * @copyright   Copyright (c) 2013-2015 eBay Enterprise, Inc. (http://www.ebayenterprise.com/)
13
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
14
 */
15
16
namespace eBayEnterprise\RetailOrderManagement\Payload\Order;
17
18
use DateInterval;
19
use DateTime;
20
use DOMXPath;
21
22
trait TOrderContext
23
{
24
    use TBrowserData, TCustomerSessionInfo, TPayPalPayerInfo, TOrderContextCustomAttributeContainer;
25
26
    /** @var DateTime */
27
    protected $tdlOrderTimestamp;
28
29
    public function getTdlOrderTimestamp()
30
    {
31
        return $this->tdlOrderTimestamp;
32
    }
33
34
    /**
35
     * The fraud system requires millisecond precision.
36
     *
37
     * @param DateTime
38
     * @return self
39
     */
40
    public function setTdlOrderTimestamp(DateTime $tdlOrderTimestamp)
41
    {
42
        $this->tdlOrderTimestamp = $tdlOrderTimestamp;
43
        return $this;
44
    }
45
46
    /**
47
     * Get property => XPath mapping for properties to be extracted from
48
     * serialized payloads for Order Context properties.
49
     *
50
     * @return array
51
     */
52
    protected function getOrderContextExtractionPaths()
53
    {
54
        return [
55
            'hostname' => 'string(x:Context/x:BrowserData/x:HostName)',
56
            'ipAddress' => 'string(x:Context/x:BrowserData/x:IPAddress)',
57
            'sessionId' => 'string(x:Context/x:BrowserData/x:SessionId)',
58
            'userAgent' => 'string(x:Context/x:BrowserData/x:UserAgent)',
59
            'javascriptData' => 'string(x:Context/x:BrowserData/x:JavascriptData)',
60
            'referrer' => 'string(x:Context/x:BrowserData/x:Referrer)',
61
            'contentTypes' => 'string(x:Context/x:BrowserData/x:HTTPAcceptData/x:ContentTypes)',
62
            'encoding' => 'string(x:Context/x:BrowserData/x:HTTPAcceptData/x:Encoding)',
63
            'language' => 'string(x:Context/x:BrowserData/x:HTTPAcceptData/x:Language)',
64
            'charSet' => 'string(x:Context/x:BrowserData/x:HTTPAcceptData/x:CharSet)',
65
        ];
66
    }
67
68
    /**
69
     * Get property => XPath mapping for optional properties to be extracted from
70
     * serialized payloads for Order Context properties.
71
     *
72
     * @return array
73
     */
74
    protected function getOrderContextOptionalExtractionPaths()
75
    {
76
        return [
77
            'connection' => 'x:Context/x:BrowserData/x:Connection',
78
            'cookies' => 'x:Context/x:BrowserData/x:Cookies',
79
            'userCookie' => 'x:Context/x:BrowserData/x:UserCookie',
80
            'userAgentOs' => 'x:Context/x:BrowserData/x:UserAgentOS',
81
            'userAgentCpu' => 'x:Context/x:BrowserData/x:UserAgentCPU',
82
            'headerFrom' => 'x:Context/x:BrowserData/x:HeaderFrom',
83
            'webBrowserName' => 'x:Context/x:BrowserData/x:EmbeddedWebBrowserFrom',
84
            'userPassword' => 'x:Context/x:SessionInfo/x:UserPassword',
85
            'timeOnFile' => 'x:Context/x:SessionInfo/x:TimeOnFile',
86
            'rtcTransactionResponseCode' => 'x:Context/x:SessionInfo/x:RTCTransactionResponseCode',
87
            'rtcReasonCode' => 'x:Context/x:SessionInfo/x:RTCReasonCodes',
88
            'authorizationAttempts' => 'x:Context/x:SessionInfo/x:AuthorizationAttempts',
89
            'payPalPayerId' => 'x:Context/x:PayPalPayerInfo/x:PayPalPayerID',
90
            'payPalPayerStatus' => 'x:Context/x:PayPalPayerInfo/x:PayPalPayerStatus',
91
            'payPalAddressStatus' => 'x:Context/x:PayPalPayerInfo/x:PayPalAddressStatus',
92
        ];
93
    }
94
95
    /**
96
     * Get property => XPath mapping for subpayload properties to be extracted from
97
     * serialized payloads for Order Context properties.
98
     *
99
     * @return array
100
     */
101
    protected function getOrderContextSubpayloadExtractionPaths()
102
    {
103
        return [
104
            'orderContextCustomAttributes' => 'x:Context/x:CustomAttributes',
105
        ];
106
    }
107
108
    /**
109
     * Build an XML serialization of the order context - browser data, tdl order
110
     * timestamp, session info, PayPal payer info and custom attributes.
111
     *
112
     * @return string
113
     */
114
    protected function serializeOrderContext()
115
    {
116
        return '<Context>'
117
            . $this->serializeBrowserData()
118
            . $this->serializeTdlOrderTimestamp()
119
            . $this->serializeCustomerSessionInfo()
120
            . $this->serializePayPalPayerInfo()
121
            . $this->getOrderContextCustomAttributes()->serialize()
122
            . '</Context>';
123
    }
124
125
    /**
126
     * Serialize the TDL order timestamp into an XML node with an ISO8601 time format with millisecond precision.
127
     *
128
     * @return string
129
     */
130
    protected function serializeTdlOrderTimestamp()
131
    {
132
        $timestamp = $this->getTdlOrderTimestamp();
133
        if (!$timestamp) {
134
            return '';
135
        }
136
        $date = $timestamp->format('Y-m-d');
137
        $time = $timestamp->format('H:i:s');
138
        $milliseconds = sprintf('%03d', $timestamp->format('u'));
139
        $zone = $timestamp->format('P');
140
        return "<TdlOrderTimestamp>{$date}T{$time}.{$milliseconds}{$zone}</TdlOrderTimestamp>";
141
    }
142
143
    /**
144
     * Deserialize order context data that is not represented by primitive types,
145
     * e.g. DateTime objects, DateInterval objects.
146
     *
147
     * @param DOMXPath
148
     * @return self
149
     */
150
    protected function deserializeExtraOrderContext(DOMXPath $xpath)
151
    {
152
        $dateTimeProperties = [
153
            'tdlOrderTimestamp' => 'string(x:Context/x:TdlOrderTimestamp)',
154
            'lastLogin' => 'string(x:Context/x:SessionInfo/x:LastLogin)',
155
        ];
156
        foreach ($dateTimeProperties as $property => $extractPath) {
157
            $value = $xpath->evaluate($extractPath);
158
            $this->$property = $value ? new DateTime($value) : null;
159
        }
160
        $timeOnSiteValue = $xpath->evaluate('string(x:Context/x:SessionInfo/x:TimeSpentOnSite)');
161
        $this->timeSpentOnSite = $timeOnSiteValue
162
            ? new DateInterval($this->convertHMSToDateInterval($timeOnSiteValue))
163
            : null;
164
        return $this;
165
    }
166
167
    /**
168
     * Convert a string of HH:MM:SS to a date interval spec string.
169
     *
170
     * @param string
171
     * @return string
172
     */
173
    protected function convertHMSToDateInterval($hmsTime)
174
    {
175
        $parts = explode(':', $hmsTime);
176
        return 'PT' . $parts[0] . 'H' . $parts[1] . 'M' . $parts[2] . 'S';
177
    }
178
}
179