Completed
Push — develop ( 1ee5f2...e137d9 )
by Dieter
04:46
created

Params::loadSessionHandlerParams()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.2
cc 4
eloc 6
nc 4
nop 1
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;
24
25
use Amadeus\Client\Params\AuthParams;
26
use Amadeus\Client\Params\RequestCreatorParams;
27
use Amadeus\Client\Params\SessionHandlerParams;
28
use Amadeus\Client\RequestCreator\RequestCreatorInterface;
29
use Amadeus\Client\ResponseHandler\ResponseHandlerInterface;
30
use Amadeus\Client\Session;
31
32
/**
33
 * Params
34
 *
35
 * @package Amadeus\Client
36
 * @author Dieter Devlieghere <[email protected]>
37
 */
38
class Params
39
{
40
    /**
41
     * For injecting a custom Request Creator
42
     *
43
     * @var RequestCreatorInterface
44
     */
45
    public $requestCreator;
46
47
    /**
48
     * For injecting a custom session handler
49
     *
50
     * @var Session\Handler\HandlerInterface
51
     */
52
    public $sessionHandler;
53
54
    /**
55
     * For injecting a custom response handler
56
     *
57
     * @var ResponseHandlerInterface
58
     */
59
    public $responseHandler;
60
61
    /**
62
     * Parameters for authenticating to the Amadeus Web Services
63
     *
64
     * @var Params\AuthParams
65
     */
66
    public $authParams;
67
68
    /**
69
     * Parameters required to create the Session Handler
70
     *
71
     * @var Params\SessionHandlerParams
72
     */
73
    public $sessionHandlerParams;
74
75
    /**
76
     * Parameters required to create the Request Creator
77
     *
78
     * @var Params\RequestCreatorParams
79
     */
80
    public $requestCreatorParams;
81
82
83
    /**
84
     * @param array $params
85
     */
86
    public function __construct($params = [])
87
    {
88
        $this->loadFromArray($params);
89
    }
90
91
    /**
92
     * Load parameters from an associative array
93
     *
94
     * @param array $params
95
     * @return void
96
     */
97
    protected function loadFromArray(array $params) {
98
        $this->loadRequestCreator($params);
99
        $this->loadSessionHandler($params);
100
        $this->loadResponseHandler($params);
101
102
        $this->loadAuthParams($params);
103
104
        $this->loadSessionHandlerParams($params);
105
        $this->loadRequestCreatorParams($params);
106
    }
107
108
    /**
109
     * Load Request Creator
110
     *
111
     * @param array $params
112
     * @return void
113
     */
114
    protected function loadRequestCreator($params)
115
    {
116
        if (isset($params['requestCreator']) && $params['requestCreator'] instanceof RequestCreatorInterface) {
117
            $this->requestCreator = $params['requestCreator'];
118
        }
119
    }
120
121
122
    /**
123
     * Load Session Handler
124
     *
125
     * @param array $params
126
     * @return void
127
     */
128
    protected function loadSessionHandler($params)
129
    {
130
        if (isset($params['sessionHandler']) && $params['sessionHandler'] instanceof Session\Handler\HandlerInterface) {
131
            $this->sessionHandler = $params['sessionHandler'];
132
        }
133
    }
134
135
    /**
136
     * Load Response Handler
137
     *
138
     * @param array $params
139
     * @return void
140
     */
141
    protected function loadResponseHandler($params)
142
    {
143
        if (isset($params['responseHandler']) && $params['responseHandler'] instanceof ResponseHandlerInterface) {
144
            $this->responseHandler = $params['responseHandler'];
145
        }
146
    }
147
148
    /**
149
     * Load Authentication Parameters
150
     *
151
     * @param array $params
152
     * @return void
153
     */
154 View Code Duplication
    protected function loadAuthParams($params)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
155
    {
156
        if (isset($params['authParams'])) {
157
            if ($params['authParams'] instanceof AuthParams) {
158
                $this->authParams = $params['authParams'];
159
            } elseif (is_array($params['authParams'])) {
160
                $this->authParams = new AuthParams($params['authParams']);
161
            }
162
        }
163
    }
164
165
    /**
166
     * Load Session Handler Parameters
167
     *
168
     * @param array $params
169
     * @return void
170
     */
171 View Code Duplication
    protected function loadSessionHandlerParams($params)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
172
    {
173
        if (isset($params['sessionHandlerParams'])) {
174
            if ($params['sessionHandlerParams'] instanceof SessionHandlerParams) {
175
                $this->sessionHandlerParams = $params['sessionHandlerParams'];
176
            } elseif (is_array($params['sessionHandlerParams'])) {
177
                $this->sessionHandlerParams = new SessionHandlerParams($params['sessionHandlerParams']);
178
            }
179
        }
180
    }
181
182
    /**
183
     * Load Request Creator Parameters
184
     *
185
     * @param array $params
186
     * @return void
187
     */
188 View Code Duplication
    protected function loadRequestCreatorParams($params)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
189
    {
190
        if (isset($params['requestCreatorParams'])) {
191
            if ($params['requestCreatorParams'] instanceof RequestCreatorParams) {
192
                $this->requestCreatorParams = $params['requestCreatorParams'];
193
            } elseif (is_array($params['requestCreatorParams'])) {
194
                $this->requestCreatorParams = new RequestCreatorParams($params['requestCreatorParams']);
195
            }
196
        }
197
    }
198
}
199