HandlerTravel::analyze()   C
last analyzed

Complexity

Conditions 12
Paths 120

Size

Total Lines 35
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 35
rs 6.8
cc 12
nc 120
nop 1

How to fix   Complexity   

Long Method

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:

1
<?php
2
/**
3
 * amadeus-ws-client
4
 *
5
 * Copyright 2015 Amadeus Benelux NV
6
 *
7
 * Licensed under the Apache License, Version 2.0 (the "License");
8
 * you may not use this file except in compliance with the License.
9
 * You may obtain a copy of the License at
10
 *
11
 * http://www.apache.org/licenses/LICENSE-2.0
12
 *
13
 * Unless required by applicable law or agreed to in writing, software
14
 * distributed under the License is distributed on an "AS IS" BASIS,
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
 * See the License for the specific language governing permissions and
17
 * limitations under the License.
18
 *
19
 * @package Amadeus
20
 * @license https://opensource.org/licenses/Apache-2.0 Apache 2.0
21
 */
22
23
namespace Amadeus\Client\ResponseHandler\Travel;
24
25
use Amadeus\Client\ResponseHandler\StandardResponseHandler;
26
use Amadeus\Client\Result;
27
use Amadeus\Client\Result\NotOk;
28
use Amadeus\Client\Session\Handler\SendResult;
29
30
/**
31
 * HandlerTravel
32
 *
33
 * @package Amadeus\Client\ResponseHandler\Travel
34
 * @author Artem Zakharchenko <[email protected]>
35
 */
36
class HandlerTravel extends StandardResponseHandler
37
{
38
    public function analyze(SendResult $response)
39
    {
40
        $result = $this->analyzeSimpleResponseErrorCodeAndMessageStatusCode($response);
41
42
        $error = isset($response->responseObject->Error) ? $response->responseObject->Error : null;
43
        $rawErrors = [];
44
45
        if ($error === null) {
46
            $rawErrors = isset($response->responseObject->Errors->Error)
47
                ? $response->responseObject->Errors->Error
48
                : [];
49
            if (!is_array($rawErrors)) {
50
                $rawErrors = [$rawErrors];
51
            }
52
        }
53
54
        if (is_array($error)) {
55
            $rawErrors = array_merge($rawErrors, $error);
56
        } elseif ($error !== null) {
57
            $rawErrors[] = $error;
58
        }
59
60
        foreach ($rawErrors as $rawError) {
61
            $result->setStatus(Result::STATUS_ERROR);
62
            $result->messages[] = new NotOk(
63
                isset($rawError->Code) ? $rawError->Code : '',
64
                isset($rawError->DescText) ? $rawError->DescText : ''
65
            );
66
        }
67
68
        if ($response = isset($result->response->Response) ? $result->response->Response : null) {
69
            $result->response = $response;
70
        }
71
72
        return $result;
73
    }
74
}
75