Completed
Push — master ( 4aee11...dd7177 )
by Kacper
04:24
created

Item::getGroups()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 1
nop 0
dl 0
loc 6
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\Iq\Query\Roster;
17
18
19
use Kadet\Xmpp\Jid;
20
use Kadet\Xmpp\Xml\XmlElement;
21
22
/**
23
 * Class Item
24
 * @package Kadet\Xmpp\Stanza\Iq\Query\Roster
25
 *
26
 * @property bool $approved
27
 * @property string $ask
28
 * @property Jid $jid
29
 * @property string $name
30
 * @property string $subscription
31
 * @property string[] $groups
32
 */
33
class Item extends XmlElement
34
{
35
    public function __construct(Jid $jid, array $options = [])
36
    {
37
        $this->jid = $jid;
38
        parent::__construct('item', null, $options);
39
    }
40
41
    #region Approved
42
    /**
43
     * @return bool
44
     */
45
    public function getApproved(): bool
46
    {
47
        return $this->getAttribute('approved') === 'true';
48
    }
49
50
    /**
51
     * @param bool $approved
52
     */
53
    public function setApproved(bool $approved)
54
    {
55
        $this->setAttribute('approved', $approved ? 'true' : 'false');
56
    }
57
    #endregion
58
59
    #region Ask
60
    /**
61
     * @return string
62
     */
63
    public function getAsk(): string
64
    {
65
        return $this->getAttribute('ask');
66
    }
67
68
    /**
69
     * @param string $ask
70
     */
71
    public function setAsk(string $ask)
72
    {
73
        $this->setAttribute('ask', $ask);
74
    }
75
    #endregion
76
77
    #region Jid
78
    /**
79
     * @return Jid
80
     */
81
    public function getJid(): Jid
82
    {
83
        return new Jid($this->getAttribute('jid'));
84
    }
85
86
    /**
87
     * @param Jid $jid
88
     */
89
    public function setJid(Jid $jid)
90
    {
91
        $this->setAttribute('jid', (string)$jid);
92
    }
93
    #endregion
94
95
    #region Name
96
    /**
97
     * @return string
98
     */
99
    public function getName(): string
100
    {
101
        return $this->getAttribute('name');
102
    }
103
104
    /**
105
     * @param string $name
106
     */
107
    public function setName(string $name)
108
    {
109
        $this->setAttribute('name', $name);
110
    }
111
    #endregion
112
113
    #region Subscription
114
    /**
115
     * @return string
116
     */
117
    public function getSubscription(): string
118
    {
119
        return $this->getAttribute('subscription');
120
    }
121
122
    /**
123
     * @param string $subscription
124
     */
125
    public function setSubscription(string $subscription)
126
    {
127
        $this->setAttribute('subscription', $subscription);
128
    }
129
    #endregion
130
131
    #region Groups
132
    /**
133
     * @return string[]
134
     */
135
    public function getGroups(): array
136
    {
137
        return array_map(function(XmlElement $element) {
138
            return $element->innerXml;
139
        }, $this->elements('group', null) ?: []);
140
    }
141
142
    public function setGroups(array $groups)
143
    {
144
        $this->remove(\Kadet\Xmpp\Utils\filter\element\name('group'));
145
        $this->append($groups);
0 ignored issues
show
Documentation introduced by
$groups is of type array, but the function expects a object<Kadet\Xmpp\Xml\XmlElement>|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
146
    }
147
    #endregion
148
}
149