Completed
Push — master ( 939cef...4aee11 )
by Kacper
03:59
created

Iq::getXmlCollocations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
cc 1
eloc 4
nc 1
nop 0
ccs 0
cts 4
cp 0
crap 2
rs 9.4285
1
<?php
2
/**
3
 * Nucleus - XMPP Library for PHP
4
 *
5
 * Copyright (C) 2016, Some rights reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Xmpp\Stanza;
17
18
19
use Kadet\Xmpp\Jid;
20
use Kadet\Xmpp\Stanza\Iq\Query;
21
use function Kadet\Xmpp\Utils\filter\pass;
22
use Kadet\Xmpp\Xml\XmlElement;
23
24
/**
25
 * Represents IQ Stanza
26
 * @package Kadet\Xmpp\Stanza
27
 *
28
 * @property XmlElement $query
29
 */
30
class Iq extends Stanza
31
{
32
    /**
33
     * Stanza constructor.
34
     * @param array  $options {
35
     *     @var Jid     $from      Jid representing "from" stanza attribute
36
     *     @var Jid     $to        Jid representing "to" stanza attribute
37
     *     @var string  $id        Unique id, will be generated if omitted
38
     *     @var string  $type      Stanza type
39
     *     @var mixed   $content   Stanza content
40
     *     @var array   $arguments Stanza arguments
41
     *     @var Query   $query     Query associated with stanza
42
     * }
43
     */
44
    public function __construct(array $options)
45
    {
46
        parent::__construct('iq', $options);
47
    }
48
49
    protected function appendChild($element)
50
    {
51
        if(count($this->children) > 0) {
52
            throw new \RuntimeException('Iq stanzas cannot have more than one child.');
53
        }
54
55
        return parent::appendChild($element);
56
    }
57
58
    #region Query
59
    /**
60
     * @return Query
61
     */
62
    public function getQuery()
63
    {
64
        return $this->get(Query::class);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The expression $this->get(\Kadet\Xmpp\Stanza\Iq\Query::class); of type Kadet\Xmpp\Xml\XmlElement|false adds false to the return on line 64 which is incompatible with the return type documented by Kadet\Xmpp\Stanza\Iq::getQuery of type Kadet\Xmpp\Stanza\Iq\Query. It seems like you forgot to handle an error condition.
Loading history...
65
    }
66
67
    /**
68
     * @param Query $query
69
     */
70
    public function setQuery(Query $query)
71
    {
72
        $this->remove($this->query);
73
        $this->append($query);
74
    }
75
    #endregion
76
77
    public static function getXmlCollocations() : array
78
    {
79
        return array_merge(
80
            [[ Query::class, 'name' => pass(), 'uri' => pass() ]],
81
            parent::getXmlCollocations()
82
        );
83
    }
84
}
85