Conditions | 31 |
Paths | 9804 |
Total Lines | 130 |
Code Lines | 78 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
18 | public function Handle($commandCode) { |
||
19 | $requests = []; |
||
20 | |||
21 | if (!self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_MEETINGRESPONSE)) { |
||
22 | return false; |
||
23 | } |
||
24 | |||
25 | while (self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_REQUEST)) { |
||
26 | $req = []; |
||
27 | WBXMLDecoder::ResetInWhile("meetingResponseRequest"); |
||
28 | while (WBXMLDecoder::InWhile("meetingResponseRequest")) { |
||
29 | if (self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_USERRESPONSE)) { |
||
30 | $req["response"] = self::$decoder->getElementContent(); |
||
31 | if (!self::$decoder->getElementEndTag()) { |
||
32 | return false; |
||
33 | } |
||
34 | } |
||
35 | |||
36 | if (self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_FOLDERID)) { |
||
37 | $req["folderid"] = self::$decoder->getElementContent(); |
||
38 | if (!self::$decoder->getElementEndTag()) { |
||
39 | return false; |
||
40 | } |
||
41 | } |
||
42 | |||
43 | if (self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_REQUESTID)) { |
||
44 | $req["requestid"] = self::$decoder->getElementContent(); |
||
45 | if (!self::$decoder->getElementEndTag()) { |
||
46 | return false; |
||
47 | } |
||
48 | } |
||
49 | |||
50 | if (self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_INSTANCEID)) { |
||
51 | $req["instanceid"] = self::$decoder->getElementContent(); |
||
52 | if (!self::$decoder->getElementEndTag()) { |
||
53 | return false; |
||
54 | } |
||
55 | } |
||
56 | |||
57 | if (self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_SENDRESPONSE)) { |
||
58 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_BODY)) { |
||
59 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_TYPE)) { |
||
60 | $req["bodytype"] = self::$decoder->getElementContent(); |
||
61 | if (!self::$decoder->getElementEndTag()) { |
||
62 | return false; |
||
63 | } |
||
64 | } |
||
65 | if (self::$decoder->getElementStartTag(SYNC_AIRSYNCBASE_DATA)) { |
||
66 | $req["body"] = self::$decoder->getElementContent(); |
||
67 | if (!self::$decoder->getElementEndTag()) { |
||
68 | return false; |
||
69 | } |
||
70 | } |
||
71 | if (!self::$decoder->getElementEndTag()) { |
||
72 | return false; |
||
73 | } |
||
74 | } // end body |
||
75 | if (self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_PROPOSEDSTARTTIME)) { |
||
76 | $req["proposedstarttime"] = self::$decoder->getElementContent(); |
||
77 | if (!self::$decoder->getElementEndTag()) { |
||
78 | return false; |
||
79 | } |
||
80 | } |
||
81 | if (self::$decoder->getElementStartTag(SYNC_MEETINGRESPONSE_PROPOSEDENDTIME)) { |
||
82 | $req["proposedendtime"] = self::$decoder->getElementContent(); |
||
83 | if (!self::$decoder->getElementEndTag()) { |
||
84 | return false; |
||
85 | } |
||
86 | } |
||
87 | } // end send response |
||
88 | |||
89 | $e = self::$decoder->peek(); |
||
90 | if ($e[EN_TYPE] == EN_TYPE_ENDTAG) { |
||
91 | self::$decoder->getElementEndTag(); |
||
92 | |||
93 | break; |
||
94 | } |
||
95 | } |
||
96 | array_push($requests, $req); |
||
97 | } |
||
98 | |||
99 | if (!self::$decoder->getElementEndTag()) { |
||
100 | return false; |
||
101 | } |
||
102 | |||
103 | // output the error code, plus the ID of the calendar item that was generated by the |
||
104 | // accept of the meeting response |
||
105 | self::$encoder->StartWBXML(); |
||
106 | self::$encoder->startTag(SYNC_MEETINGRESPONSE_MEETINGRESPONSE); |
||
107 | |||
108 | foreach ($requests as $req) { |
||
109 | $status = SYNC_MEETRESPSTATUS_SUCCESS; |
||
110 | |||
111 | try { |
||
112 | $backendFolderId = self::$deviceManager->GetBackendIdForFolderId($req["folderid"]); |
||
113 | |||
114 | // if the source folder is an additional folder the backend has to be setup correctly |
||
115 | if (!self::$backend->Setup(GSync::GetAdditionalSyncFolderStore($backendFolderId))) { |
||
116 | throw new StatusException(sprintf("HandleMoveItems() could not Setup() the backend for folder id %s/%s", $req["folderid"], $backendFolderId), SYNC_MEETRESPSTATUS_SERVERERROR); |
||
117 | } |
||
118 | |||
119 | $calendarid = self::$backend->MeetingResponse($backendFolderId, $req); |
||
120 | if ($calendarid === false) { |
||
121 | throw new StatusException("HandleMeetingResponse() not possible", SYNC_MEETRESPSTATUS_SERVERERROR); |
||
122 | } |
||
123 | } |
||
124 | catch (StatusException $stex) { |
||
125 | $status = $stex->getCode(); |
||
126 | } |
||
127 | |||
128 | self::$encoder->startTag(SYNC_MEETINGRESPONSE_RESULT); |
||
129 | self::$encoder->startTag(SYNC_MEETINGRESPONSE_REQUESTID); |
||
130 | self::$encoder->content($req["requestid"]); |
||
131 | self::$encoder->endTag(); |
||
132 | |||
133 | self::$encoder->startTag(SYNC_MEETINGRESPONSE_STATUS); |
||
134 | self::$encoder->content($status); |
||
135 | self::$encoder->endTag(); |
||
136 | |||
137 | if ($status == SYNC_MEETRESPSTATUS_SUCCESS && !empty($calendarid)) { |
||
138 | self::$encoder->startTag(SYNC_MEETINGRESPONSE_CALENDARID); |
||
139 | self::$encoder->content($calendarid); |
||
140 | self::$encoder->endTag(); |
||
141 | } |
||
142 | self::$encoder->endTag(); |
||
143 | self::$topCollector->AnnounceInformation(sprintf("Operation status %d", $status), true); |
||
144 | } |
||
145 | self::$encoder->endTag(); |
||
146 | |||
147 | return true; |
||
148 | } |
||
150 |