Completed
Push — master ( 6634cb...f6cba5 )
by Kacper
06:10
created

Iq::setQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
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 Query $query
29
 */
30
class Iq extends Stanza
31
{
32
    /**
33
     * Stanza constructor.
34
     * @param string $type Iq query type
35
     * @param array  $options {
36
     *     @var Jid     $from      Jid representing "from" stanza attribute
37
     *     @var Jid     $to        Jid representing "to" stanza attribute
38
     *     @var string  $id        Unique id, will be generated if omitted
39
     *     @var string  $type      Stanza type
40
     *     @var mixed   $content   Stanza content
41
     *     @var array   $arguments Stanza arguments
42
     *     @var Query   $query     Query associated with stanza
43
     * }
44
     */
45 3
    public function __construct(string $type, array $options = [])
46
    {
47 3
        $this->type = $type;
48 3
        parent::__construct('iq', $options);
49 3
    }
50
51 3
    protected function appendChild($element)
52
    {
53 3
        if(count($this->children) > 0) {
54
            throw new \RuntimeException('Iq stanzas cannot have more than one child.');
55
        }
56
57 3
        return parent::appendChild($element);
58
    }
59
60
    #region Query
61
    /**
62
     * @return Query
63
     */
64 3
    public function getQuery()
65
    {
66 3
        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 66 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...
67
    }
68
69
    /**
70
     * @param Query $query
71
     */
72 3
    public function setQuery(Query $query)
73
    {
74 3
        $this->remove($this->query);
75 3
        $this->append($query);
76 3
    }
77
    #endregion
78
79
    public static function getXmlCollocations() : array
80
    {
81
        return array_merge(
82
            [[ Query::class, 'name' => pass(), 'uri' => pass() ]],
83
            parent::getXmlCollocations()
84
        );
85
    }
86
}
87