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.

MessageResponse::replaceKeys()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
namespace DexBarrett\ClockworkSms\Builders\Xml;
3
4
use SimpleXMLElement;
5
6
class MessageResponse extends XmlResponse
7
{
8
    protected $ignoredMessageKeys = ['errno', 'errdesc', 'messageid'];
9
    protected $smsKeys = ['To' => 'to'];
10
11
    public function parseResponse($xmlData)
12
    {
13
        $response = [];
14
15
        $messages = $xmlData->xpath('//SMS_Resp');
16
17
        foreach ($messages as $message) {
18
            $messageData = [];
19
            
20
            
21
            $errorNumber = $message->xpath('ErrNo');
22
            $errorDesc = $message->xpath('ErrDesc');
23
            $messageID = $message->xpath('MessageID');
24
25
            $messageData['success'] = (count($errorNumber) == 0);
26
            
27
            if (count($errorNumber) > 0) {
28
                $messageData['error_code'] = (string)$errorNumber[0];
29
            }
30
31
            if (count($errorDesc) > 0) {
32
                $messageData['error_message'] = (string)$errorDesc[0];
33
            }
34
35
            if (count($messageID) > 0) {
36
                $messageData['id'] = (string)$messageID[0];
37
            }
38
39
40
            $smsData = array_filter(
41
                (array)$message,
42
                [$this, 'isNotInIgnoredKeys'],
43
                ARRAY_FILTER_USE_BOTH
44
            );
45
46
            $messageData['sms'] = $this->replaceKeys($smsData);
47
48
            $response[] = $messageData;
49
        }
50
51
        return $response;
52
    }
53
54
    protected function isNotInIgnoredKeys($nodeValue, $nodeName)
55
    {
56
        return ! in_array(strtolower($nodeName), $this->ignoredMessageKeys);
57
    }
58
59
    protected function replaceKeys($smsData)
60
    {
61
        $newSmsData = [];
62
63
        foreach ($smsData as $key => $value) {
64
            $newSmsData[$this->getSmsKey($key)] = $value;
65
        }
66
67
        return $newSmsData;
68
    }
69
70
    protected function getSmsKey($key)
71
    {
72
        if (array_key_exists($key, $this->smsKeys)) {
73
            return $this->smsKeys[$key];
74
        }
75
76
        return $key;
77
    }
78
}
79