Completed
Pull Request — master (#76)
by
unknown
25:04
created

Options::isAuthenticated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 1
cts 1
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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 Fabiang\Xmpp;
38
39
use Fabiang\Xmpp\Connection\ConnectionInterface;
40
use Fabiang\Xmpp\Protocol\ImplementationInterface;
41
use Fabiang\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 = [];
119
120
    /**
121
     * Timeout for connection.
122
     *
123
     * @var integer
124
     */
125
    protected $timeout = 30;
126
127
    /**
128
     * SOCKS proxy address
129
     *
130
     * @var string
131
     */
132
    protected $socksProxyAddress;
133
134
    /**
135
     * Authentication methods.
136 3
     *
137
     * @var array
138 3
     */
139 3
    protected $authenticationClasses = [
140 3
        'digest-md5' => '\\Fabiang\\Xmpp\\EventListener\\Stream\\Authentication\\DigestMd5',
141 3
        'plain'      => '\\Fabiang\\Xmpp\\EventListener\\Stream\\Authentication\\Plain',
142
        'anonymous'  => '\\Fabiang\\Xmpp\\EventListener\\Stream\\Authentication\\Anonymous'
143
    ];
144
145
146
    /**
147
     * Options used to create a stream context
148 3
     *
149
     * @var array
150 3
     */
151 3
    protected $contextOptions = [];
152 3
153
154 3
    /**
155
     * Constructor.
156
     *
157
     * @param string $address Server address
158
     */
159
    public function __construct($address = null)
160
    {
161
        if (null !== $address) {
162
            $this->setAddress($address);
163 3
        }
164
    }
165 3
166 3
    /**
167
     * Get protocol implementation.
168
     *
169
     * @return ImplementationInterface
170
     */
171
    public function getImplementation()
172
    {
173
        if (null === $this->implementation) {
174 3
            $this->setImplementation(new DefaultImplementation());
175
        }
176 3
177
        return $this->implementation;
178
    }
179
180
    /**
181
     * Set protocol implementation.
182
     *
183
     * @param ImplementationInterface $implementation
184
     * @return $this
185
     */
186
    public function setImplementation(ImplementationInterface $implementation)
187 3
    {
188
        $this->implementation = $implementation;
189 3
        return $this;
190 3
    }
191 3
192 3
    /**
193 3
     * Get server address.
194
     *
195
     * @return string
196
     */
197
    public function getAddress()
198
    {
199
        return $this->address;
200
    }
201 3
202
    /**
203 3
     * Set server address.
204
     *
205
     * When a address is passed this setter also calls setTo with the hostname part of the address.
206
     *
207
     * @param string $address Server address
208
     * @return $this
209
     */
210
    public function setAddress($address)
211
    {
212 3
        $this->address = (string) $address;
213
        if (false !== ($host = parse_url($address, PHP_URL_HOST))) {
214 3
            $this->setTo($host);
215 3
        }
216
        return $this;
217
    }
218
219
    /**
220
     * Get connection object.
221
     *
222
     * @return ConnectionInterface
223 3
     */
224
    public function getConnection()
225 3
    {
226
        return $this->connection;
227
    }
228
229
    /**
230
     * Set connection object.
231
     *
232
     * @param ConnectionInterface $connection
233
     * @return $this
234 3
     */
235
    public function setConnection(ConnectionInterface $connection)
236 3
    {
237 3
        $this->connection = $connection;
238
        return $this;
239
    }
240
241
    /**
242
     * Get logger instance.
243
     *
244
     * @return LoggerInterface
245 3
     */
246
    public function getLogger()
247 3
    {
248
        return $this->logger;
249
    }
250
251
    /**
252
     * Set logger instance.
253
     *
254
     * @param \Psr\Log\LoggerInterface $logger PSR-3 Logger
255
     * @return $this
256
     */
257
    public function setLogger(LoggerInterface $logger)
258 3
    {
259
        $this->logger = $logger;
260 3
        return $this;
261 3
    }
262
263
    /**
264
     * Get server name.
265
     *
266
     * @return string
267
     */
268
    public function getTo()
269 3
    {
270
        return $this->to;
271 3
    }
272
273
    /**
274
     * Set server name.
275
     *
276
     * This value is send to the server in requests as to="" attribute.
277
     *
278
     * @param string $to
279
     * @return $this
280 3
     */
281
    public function setTo($to)
282 3
    {
283 3
        $this->to = (string) $to;
284
        return $this;
285
    }
286
287
    /**
288
     * Get username.
289
     *
290
     * @return string
291
     */
292
    public function getUsername()
293
    {
294
        return $this->username;
295
    }
296
297
    /**
298
     * Set username.
299
     *
300
     * @param string $username
301
     * @return $this
302
     */
303 3
    public function setUsername($username)
304
    {
305 3
        $this->username = (string) $username;
306
        return $this;
307
    }
308
309
    /**
310
     * Get resource.
311
     *
312
     * @return string
313
     */
314 3
    public function getResource()
315
    {
316 3
        $username = $this->getUsername();
317 3
        $username = explode('/', $username);
318
        return isset($username[1]) ? $username[1] : '';
319
    }
320
321
    /**
322
     * Get password.
323
     *
324
     * @return string
325 3
     */
326
    public function getPassword()
327 3
    {
328
        return $this->password;
329
    }
330
331
    /**
332
     * Set password.
333
     *
334
     * @param string $password
335
     * @return $this
336 3
     */
337
    public function setPassword($password)
338 3
    {
339 3
        $this->password = (string) $password;
340
        return $this;
341
    }
342
343
    /**
344
     * Get users jid.
345
     *
346
     * @return string
347 3
     */
348
    public function getJid()
349 3
    {
350
        return $this->jid;
351
    }
352
353
    /**
354
     * Set users jid.
355
     *
356
     * @param string $jid
357
     * @return $this
358 3
     */
359
    public function setJid($jid)
360 3
    {
361 3
        $this->jid = (string) $jid;
362
        return $this;
363
    }
364
365
    /**
366
     * Get users jid.
367
     *
368
     * @return string
369 3
     */
370
    public function getSid()
371 3
    {
372
        return $this->sid;
373
    }
374
375
    /**
376
     * Set users jid.
377
     *
378
     * @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...
379
     * @return $this
380 3
     */
381
    public function setSid($sid)
382 3
    {
383 3
        $this->sid = (string) $sid;
384
        return $this;
385
    }
386
387
    /**
388
     * Is user authenticated.
389
     *
390
     * @return boolean
391 3
     */
392
    public function isAuthenticated()
393 3
    {
394
        return $this->authenticated;
395
    }
396
397
    /**
398
     * Set authenticated.
399
     *
400
     * @param boolean $authenticated Flag
401 3
     * @return $this
402
     */
403 3
    public function setAuthenticated($authenticated)
404 3
    {
405
        $this->authenticated = (bool) $authenticated;
406
        return $this;
407
    }
408
409
    /**
410
     * Get users.
411
     *
412 3
     * @return Protocol\User\User[]
413
     */
414 3
    public function getUsers()
415
    {
416
        return $this->users;
417
    }
418
419
    /**
420
     * Set users.
421
     *
422
     * @param array $users User list
423 3
     * @return $this
424
     */
425 3
    public function setUsers(array $users)
426 3
    {
427
        $this->users = $users;
428
        return $this;
429
    }
430
431
    /**
432
     * Get authentication classes.
433
     *
434
     * @return array
435
     */
436
    public function getAuthenticationClasses()
437
    {
438
        return $this->authenticationClasses;
439
    }
440
441
    /**
442
     *
443
     * @param array $authenticationClasses Authentication classes
444
     * @return $this
445
     */
446
    public function setAuthenticationClasses(array $authenticationClasses)
447
    {
448
        $this->authenticationClasses = $authenticationClasses;
449
        return $this;
450
    }
451
452
    /**
453
     * Get timeout for connection.
454
     *
455
     * @return integer
456
     */
457
    public function getTimeout()
458
    {
459
        return $this->timeout;
460
    }
461
462
    /**
463
     * Set timeout for connection.
464
     *
465
     * @param integer $timeout Seconds
466
     * @return \Fabiang\Xmpp\Options
467
     */
468
    public function setTimeout($timeout)
469
    {
470
        $this->timeout = (int) $timeout;
471
        return $this;
472
    }
473
474
    /**
475
     * Get context options for connection
476
     *
477
     * @return array
478
     */
479
    public function getContextOptions()
480
    {
481
        return $this->contextOptions;
482
    }
483
484
    /**
485
     *  Set context options for connection
486
     *
487
     * @param array $contextOptions
488
     * @return \Fabiang\Xmpp\Options
489
     */
490
    public function setContextOptions($contextOptions)
491
    {
492
        $this->contextOptions = (array) $contextOptions;
493
        return $this;
494
    }
495
496
    /**
497
     * Get SOCKS proxy address
498
     *
499
     * @return string
500
     */
501
    public function getSocksProxyAddress()
502
    {
503
        return $this->socksProxyAddress;
504
    }
505
506
    /**
507
     * Set SOCKS proxy address
508
     *
509
     * @param string $socksProxyAddress
510
     * @return \Fabiang\Xmpp\Options
511
     */
512
    public function setSocksProxyAddress($socksProxyAddress)
513
    {
514
        $this->socksProxyAddress = $socksProxyAddress;
515
        return $this;
516
    }
517
}
518