Features::getMechanisms()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 2
cp 0
crap 2
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\Stream;
17
18
use Kadet\Xmpp\Stream\Features\StartTls;
19
use Kadet\Xmpp\Utils\Accessors;
20
use Kadet\Xmpp\Xml\XmlElement;
21
use Kadet\Xmpp\Xml\XmlStream;
22
use Kadet\Xmpp\Utils\filter;
23
24
/**
25
 * Class Features
26
 * @package Kadet\Xmpp\Stream
27
 *
28
 * @property-read false|StartTls $startTls
29
 * @property-read string[]       $mechanisms
30
 */
31
class Features extends XmlElement
32
{
33
    use Accessors;
34
35
    /**
36
     * XmlElement constructor
37
     *
38
     * @param array $features
39
     */
40
    public function __construct(array $features = [])
41
    {
42
        parent::__construct('stream:features', XmlStream::NAMESPACE_URI, [ 'content' => $features ]);
43
    }
44
45
    /**
46
     * @return false|StartTls
47
     */
48
    public function getStartTls()
49
    {
50
        return $this->get(StartTls::class);
51
    }
52
53
    public function getMechanisms()
54
    {
55
        return array_map(function (XmlElement $element) {
56
            return $element->innerXml;
57
        }, $this->get(filter\element\name('mechanisms'))->children ?? []);
58
    }
59
}
60