Completed
Push — master ( e6cea0...5c122a )
by Marcin
01:53
created

Event   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 44
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getXml() 0 11 1
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
16
namespace mrcnpdlk\Grandstream\XMLApp\Application\Model;
17
18
use mrcnpdlk\Grandstream\XMLApp\Application\ModelInterface;
19
use mrcnpdlk\Grandstream\XMLApp\MyXML;
20
21
/**
22
 * Class Event
23
 *
24
 * In one XML document, multiple <Event> elements could be used. However, the state for each event must
25
 * be different so that the action is unique for that state.
26
 *
27
 * @package mrcnpdlk\Grandstream\XMLApp\Application\Model
28
 */
29
class Event implements ModelInterface
30
{
31
32
33
    const ACTION_DIAL             = 'Dial';
34
    const ACTION_USE_URL          = 'UseURL';
35
    const ACTION_APPEND_INPUT_URL = 'AppendInputURL';
36
    const ACTION_QUIT_APP         = 'QuitApp';
37
38
    /**
39
     * @var string
40
     */
41
    private $sState;
42
    /**
43
     * @var string
44
     */
45
    private $sAction;
46
    /**
47
     * @var string|null
48
     */
49
    private $sCommandArgs;
50
51
    public function __construct(string $sState, string $sAction, string $sCommandArgs = null)
52
    {
53
        $this->sState       = $sState;
54
        $this->sAction      = $sAction;
55
        $this->sCommandArgs = $sCommandArgs;
56
    }
57
58
    /**
59
     * @return MyXML
60
     */
61
    public function getXml(): MyXML
62
    {
63
        $oXml = new MyXML('Event');
64
        $oXml->asObject()->addAttribute('state', $this->sState);
65
        $oAction = new MyXML('Action');
66
        $oAction->asObject()->addAttribute('action', $this->sAction);
67
        $oAction->asObject()->addAttribute('commandArgs', $this->sCommandArgs);
68
        $oXml->insertChild($oAction->asObject());
69
70
        return $oXml;
71
    }
72
}
73