Completed
Pull Request — master (#34)
by Ghitu
21:00
created

Options::getPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * Copyright 2014 Fabian Grutschus. All rights reserved.
5
 *
6
 * Redistribution and use in source and binary forms, with or without modification,
7
 * are permitted provided that the following conditions are met:
8
 *
9
 * 1. Redistributions of source code must retain the above copyright notice, this
10
 *   list of conditions and the following disclaimer.
11
 *
12
 * 2. Redistributions in binary form must reproduce the above copyright notice,
13
 *   this list of conditions and the following disclaimer in the documentation
14
 *   and/or other materials provided with the distribution.
15
 *
16
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 *
27
 * The views and conclusions contained in the software and documentation are those
28
 * of the authors and should not be interpreted as representing official policies,
29
 * either expressed or implied, of the copyright holders.
30
 *
31
 * @author    Fabian Grutschus <[email protected]>
32
 * @copyright 2014 Fabian Grutschus. All rights reserved.
33
 * @license   BSD
34
 * @link      http://github.com/fabiang/xmpp
35
 */
36
37
namespace Updivision\Xmpp;
38
39
use Updivision\Xmpp\Connection\ConnectionInterface;
40
use Updivision\Xmpp\Protocol\ImplementationInterface;
41
use Updivision\Xmpp\Protocol\DefaultImplementation;
42
use Psr\Log\LoggerInterface;
43
44
/**
45
 * Xmpp connection options.
46
 *
47
 * @package Xmpp
48
 */
49
class Options
50
{
51
52
    /**
53
     *
54
     * @var ImplementationInterface
55
     */
56
    protected $implementation;
57
58
    /**
59
     *
60
     * @var string
61
     */
62
    protected $address;
63
64
    /**
65
     * Connection object.
66
     *
67
     * @var ConnectionInterface
68
     */
69
    protected $connection;
70
71
    /**
72
     * PSR-3 Logger interface.
73
     *
74
     * @var LoggerInterface
75
     */
76
    protected $logger;
77
78
    /**
79
     *
80
     * @var string
81
     */
82
    protected $to;
83
84
    /**
85
     *
86
     * @var string
87
     */
88
    protected $username;
89
90
    /**
91
     *
92
     * @var string
93
     */
94
    protected $password;
95
96
    /**
97
     *
98
     * @var string
99
     */
100
    protected $jid;
101
102
    /**
103
     *
104
     * @var string
105
     */
106
    protected $sid;
107
108
    /**
109
     *
110
     * @var boolean
111
     */
112
    protected $authenticated = false;
113
114
    /**
115
     *
116
     * @var array
117
     */
118
    protected $users = array();
119
120
    /**
121
     * Timeout for connection.
122
     *
123
     * @var integer
124
     */
125
    protected $timeout = 30;
126
127
    /**
128
     * Authentication methods.
129
     *
130
     * @var array
131
     */
132
    protected $authenticationClasses = array(
133
        'digest-md5' => '\\Updivision\\Xmpp\\EventListener\\Stream\\Authentication\\DigestMd5',
134
        'plain'      => '\\Updivision\\Xmpp\\EventListener\\Stream\\Authentication\\Plain'
135
    );
136 3
137
    /**
138 3
     * Constructor.
139 3
     *
140 3
     * @param string $address Server address
141 3
     */
142
    public function __construct($address = null)
143
    {
144
        if (null !== $address) {
145
            $this->setAddress($address);
146
        }
147
    }
148 3
149
    /**
150 3
     * Get protocol implementation.
151 3
     *
152 3
     * @return ImplementationInterface
153
     */
154 3
    public function getImplementation()
155
    {
156
        if (null === $this->implementation) {
157
            $this->setImplementation(new DefaultImplementation());
158
        }
159
160
        return $this->implementation;
161
    }
162
163 3
    /**
164
     * Set protocol implementation.
165 3
     *
166 3
     * @param ImplementationInterface $implementation
167
     * @return $this
168
     */
169
    public function setImplementation(ImplementationInterface $implementation)
170
    {
171
        $this->implementation = $implementation;
172
        return $this;
173
    }
174 3
175
    /**
176 3
     * Get server address.
177
     *
178
     * @return string
179
     */
180
    public function getAddress()
181
    {
182
        return $this->address;
183
    }
184
185
    /**
186
     * Set server address.
187 3
     *
188
     * When a address is passed this setter also calls setTo with the hostname part of the address.
189 3
     *
190 3
     * @param string $address Server address
191 3
     * @return $this
192 3
     */
193 3
    public function setAddress($address)
194
    {
195
        $this->address = (string) $address;
196
        if (false !== ($host = parse_url($address, PHP_URL_HOST))) {
197
            $this->setTo($host);
198
        }
199
        return $this;
200
    }
201 3
202
    /**
203 3
     * Get connection object.
204
     *
205
     * @return ConnectionInterface
206
     */
207
    public function getConnection()
208
    {
209
        return $this->connection;
210
    }
211
212 3
    /**
213
     * Set connection object.
214 3
     *
215 3
     * @param ConnectionInterface $connection
216
     * @return $this
217
     */
218
    public function setConnection(ConnectionInterface $connection)
219
    {
220
        $this->connection = $connection;
221
        return $this;
222
    }
223 3
224
    /**
225 3
     * Get logger instance.
226
     *
227
     * @return LoggerInterface
228
     */
229
    public function getLogger()
230
    {
231
        return $this->logger;
232
    }
233
234 3
    /**
235
     * Set logger instance.
236 3
     *
237 3
     * @param \Psr\Log\LoggerInterface $logger PSR-3 Logger
238
     * @return $this
239
     */
240
    public function setLogger(LoggerInterface $logger)
241
    {
242
        $this->logger = $logger;
243
        return $this;
244
    }
245 3
246
    /**
247 3
     * Get server name.
248
     *
249
     * @return string
250
     */
251
    public function getTo()
252
    {
253
        return $this->to;
254
    }
255
256
    /**
257
     * Set server name.
258 3
     *
259
     * This value is send to the server in requests as to="" attribute.
260 3
     *
261 3
     * @param string $to
262
     * @return $this
263
     */
264
    public function setTo($to)
265
    {
266
        $this->to = (string) $to;
267
        return $this;
268
    }
269 3
270
    /**
271 3
     * Get username.
272
     *
273
     * @return string
274
     */
275
    public function getUsername()
276
    {
277
        return $this->username;
278
    }
279
280 3
    /**
281
     * Set username.
282 3
     *
283 3
     * @param string $username
284
     * @return $this
285
     */
286
    public function setUsername($username)
287
    {
288
        $this->username = (string) $username;
289
        return $this;
290
    }
291
292
    /**
293
     * Get resource.
294
     *
295
     * @return string
296
     */
297
    public function getResource()
298
    {
299
        $username = $this->getUsername();
300
        $username = explode('/', $username);
301
        return isset($username[1]) ? $username[1] : '';
302
    }
303 3
304
    /**
305 3
     * Get password.
306
     *
307
     * @return string
308
     */
309
    public function getPassword()
310
    {
311
        return $this->password;
312
    }
313
314 3
    /**
315
     * Set password.
316 3
     *
317 3
     * @param string $password
318
     * @return $this
319
     */
320
    public function setPassword($password)
321
    {
322
        $this->password = (string) $password;
323
        return $this;
324
    }
325 3
326
    /**
327 3
     * Get users jid.
328
     *
329
     * @return string
330
     */
331
    public function getJid()
332
    {
333
        return $this->jid;
334
    }
335
336 3
    /**
337
     * Set users jid.
338 3
     *
339 3
     * @param string $jid
340
     * @return $this
341
     */
342
    public function setJid($jid)
343
    {
344
        $this->jid = (string) $jid;
345
        return $this;
346
    }
347 3
348
    /**
349 3
     * Get users jid.
350
     *
351
     * @return string
352
     */
353
    public function getSid()
354
    {
355
        return $this->sid;
356
    }
357
358 3
    /**
359
     * Set users jid.
360 3
     *
361 3
     * @param string $jid
0 ignored issues
show
Bug introduced by
There is no parameter named $jid. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
362
     * @return $this
363
     */
364
    public function setSid($sid)
365
    {
366
        $this->sid = (string) $sid;
367
        return $this;
368
    }
369 3
370
    /**
371 3
     * Is user authenticated.
372
     *
373
     * @return boolean
374
     */
375
    public function isAuthenticated()
376
    {
377
        return $this->authenticated;
378
    }
379
380 3
    /**
381
     * Set authenticated.
382 3
     *
383 3
     * @param boolean $authenticated Flag
384
     * @return $this
385
     */
386
    public function setAuthenticated($authenticated)
387
    {
388
        $this->authenticated = (bool) $authenticated;
389
        return $this;
390
    }
391 3
392
    /**
393 3
     * Get users.
394
     *
395
     * @return Protocol\User\User[]
396
     */
397
    public function getUsers()
398
    {
399
        return $this->users;
400
    }
401 3
402
    /**
403 3
     * Set users.
404 3
     *
405
     * @param array $users User list
406
     * @return $this
407
     */
408
    public function setUsers(array $users)
409
    {
410
        $this->users = $users;
411
        return $this;
412 3
    }
413
414 3
    /**
415
     * Get authentication classes.
416
     *
417
     * @return array
418
     */
419
    public function getAuthenticationClasses()
420
    {
421
        return $this->authenticationClasses;
422
    }
423 3
424
    /**
425 3
     *
426 3
     * @param array $authenticationClasses Authentication classes
427
     * @return $this
428
     */
429
    public function setAuthenticationClasses(array $authenticationClasses)
430
    {
431
        $this->authenticationClasses = $authenticationClasses;
432
        return $this;
433
    }
434
435
    /**
436
     * Get timeout for connection.
437
     *
438
     * @return integer
439
     */
440
    public function getTimeout()
441
    {
442
        return $this->timeout;
443
    }
444
445
    /**
446
     * Set timeout for connection.
447
     *
448
     * @param integer $timeout Seconds
449
     * @return \Updivision\Xmpp\Options
450
     */
451
    public function setTimeout($timeout)
452
    {
453
        $this->timeout = (int) $timeout;
454
        return $this;
455
    }
456
}
457