AddressBook::getXml()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2
1
<?php
2
/**
3
 * Grandstream-XMLApp
4
 *
5
 * Copyright (c) 2017 pudelek.org.pl
6
 *
7
 * @license MIT License (MIT)
8
 *
9
 * For the full copyright and license information, please view source file
10
 * that is bundled with this package in the file LICENSE
11
 *
12
 * @author  Marcin Pudełek <[email protected]>
13
 */
14
15
namespace mrcnpdlk\Grandstream\XMLApp\AddressBook;
16
17
use mrcnpdlk\Grandstream\XMLApp\AddressBook\Model\Contact;
18
use mrcnpdlk\Grandstream\XMLApp\MyXML;
19
20
/**
21
 * Class AddressBook
22
 *
23
 * @package mrcnpdlk\Grandstream\XMLApp\AddressBook
24
 */
25
class AddressBook implements ModelInterface
26
{
27
28
    /**
29
     * @var Contact[]
30
     */
31
    private $tContacts = [];
32
33
34
    /**
35
     * @param Contact $oContact
36
     *
37
     * @return AddressBook
38
     */
39 2
    public function addContact(Contact $oContact)
40
    {
41 2
        $this->tContacts[] = $oContact;
42
43 2
        return $this;
44
    }
45
46
    /**
47
     * @return MyXML
48
     */
49 2
    public function getXml(): MyXML
50
    {
51 2
        $oXml = new MyXML('AddressBook');
52 2
        foreach ($this->tContacts as $oContact) {
53 2
            $oXml->insertChild($oContact->getXml()->asObject());
54
        }
55
56 2
        return $oXml;
57
    }
58
}
59