Skip to content

Commit

Permalink
add mandatory type argument in iq's constructor
Browse files Browse the repository at this point in the history
according to RFC type attribute is mandatory, so it makes sense to make it mandatory argument when constructing query
  • Loading branch information
kadet1090 committed Sep 3, 2016
1 parent 356f1b0 commit 5d5add1
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Component/Binding.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function setClient(XmppClient $client)
public function bind(Features $features)
{
if($features->has(with\element('bind', self::XMLNS))) {
$stanza = new Iq(['type' => 'set']);
$stanza = new Iq('set');
$bind = $stanza->append(new Iq\Query(self::XMLNS, 'bind'));

if(!$this->_client->jid->isBare()) {
Expand Down
2 changes: 1 addition & 1 deletion Component/PingKeepAlive.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function disable()

private function keepAlive()
{
$ping = new Iq(['type' => 'get', 'query' => new Iq\Query('urn:xmpp:ping', 'ping')]);
$ping = new Iq('get', ['query' => new Iq\Query('urn:xmpp:ping', 'ping')]);

$this->_client->write($ping);
}
Expand Down
4 changes: 3 additions & 1 deletion Stanza/Iq.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Iq extends Stanza
{
/**
* Stanza constructor.
* @param string $type Iq query type
* @param array $options {
* @var Jid $from Jid representing "from" stanza attribute
* @var Jid $to Jid representing "to" stanza attribute
Expand All @@ -41,8 +42,9 @@ class Iq extends Stanza
* @var Query $query Query associated with stanza
* }
*/
public function __construct(array $options)
public function __construct(string $type, array $options = [])
{
$this->type = $type;
parent::__construct('iq', $options);
}

Expand Down
7 changes: 3 additions & 4 deletions Tests/Modules/BindingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ public function testBindingInitiationWithResourceFailure()
public function success($id, $resource = 'generated')
{
$jid = "[email protected]/$resource";
$result = new Iq([
'type' => 'result',
'id' => $id,
$result = new Iq('result', [
'id' => $id,
'query' => new Iq\Query('urn:ietf:params:xml:ns:xmpp-bind', 'bind', [
'content' => new XmlElement('jid', null, ['content' => $jid])
])
Expand All @@ -120,7 +119,7 @@ public function success($id, $resource = 'generated')

public function failure($id, Error $error)
{
$result = new Iq(['type' => 'error', 'id' => $id, 'content' => $error]);
$result = new Iq('error', ['id' => $id, 'content' => $error]);
$this->_client->emit('element', [ $result ]);
}

Expand Down
20 changes: 20 additions & 0 deletions Xml/XmlElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,4 +594,24 @@ public static function cast(XmlElement $element)

return $return;
}

/**
* When an object is cloned, PHP 5 will perform a shallow copy of all of the object's properties.
* Any properties that are references to other variables, will remain references.
* Once the cloning is complete, if a __clone() method is defined,
* then the newly created object's __clone() method will be called, to allow any necessary properties that need to be changed.
* NOT CALLABLE DIRECTLY.
*
* @link http://php.net/manual/en/language.oop5.cloning.php
*/
public function __clone()
{
$children = $this->_children;
$this->_children = [];
$this->_parent = null;

foreach ($children as $child) {
$this->append(is_object($child) ? clone $child : $child);
}
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"evenement/evenement": "2.0.*",
"psr/log": "1.0.*",
"kadet/keylighter": "^0.8",
"fabiang/sasl": "dev-rspauth",
"fabiang/sasl": "dev-rspauth@dev",
"php-di/php-di": "^5.3"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</rule>
<rule ref="rulesets/naming.xml/ShortMethodName">
<properties>
<property name="exceptions" value="id,on,is" />
<property name="exceptions" value="id,on,is,to,as" />
</properties>
</rule>

Expand Down

0 comments on commit 5d5add1

Please sign in to comment.