Contact   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 75
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setAddress() 0 4 1
A getXml() 0 20 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\Model;
16
17
use mrcnpdlk\Grandstream\XMLApp\AddressBook\ModelInterface;
18
use mrcnpdlk\Grandstream\XMLApp\MyXML;
19
20
21
/**
22
 * Class Contact
23
 *
24
 * @package mrcnpdlk\Grandstream\XMLApp\AddressBook\Model
25
 */
26
class Contact implements ModelInterface
27
{
28
    /**
29
     * @var string
30
     */
31
    private $lastName;
32
    /**
33
     * @var string|null
34
     */
35
    private $firstName = null;
36
    /**
37
     * @var Address|null
38
     */
39
    private $oAddress = null;
40
    /**
41
     * @var Phone
42
     */
43
    private $oPhone;
44
    /**
45
     * @var string|null
46
     */
47
    private $email = null;
48
    /**
49
     * @var string|null
50
     */
51
    private $department = null;
52
    /**
53
     * @var string|null
54
     */
55
    private $company = null;
56
    /**
57
     * Base64 string
58
     *
59
     * @var string|null
60
     */
61
    private $icon = null;
62
63 2
    public function __construct(string $lastName, Phone $oPhone, string $firstName = null)
64
    {
65 2
        $this->lastName  = $lastName;
66 2
        $this->oPhone    = $oPhone;
67 2
        $this->firstName = $firstName;
68 2
    }
69
70 1
    public function setAddress(Address $oAddress)
71
    {
72 1
        $this->oAddress = $oAddress;
73 1
    }
74
75
    /**
76
     * @return MyXML
77
     */
78 2
    public function getXml(): MyXML
79
    {
80 2
        $oXml = new MyXML('Contact');
81 2
        $oXml->asObject()->addChild('LastName', $this->lastName);
82 2
        $oXml->asObject()->addChild('FirstName', $this->firstName);
83 2
        $oXml->asObject()->addChild('Email', $this->email);
84 2
        $oXml->asObject()->addChild('Department', $this->department);
85 2
        $oXml->asObject()->addChild('Company', $this->company);
86 2
        $oXml->asObject()->addChild('Icon', $this->icon);
87
88
89 2
        $oXml->insertChild($this->oPhone->getXml()->asObject());
90
91 2
        if ($this->oAddress) {
92 1
            $oXml->insertChild($this->oAddress->getXml()->asObject());
93
        }
94
95
96 2
        return $oXml;
97
    }
98
99
100
}
101