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

ElemString::getXml()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 0
cts 14
cp 0
rs 9.0856
c 0
b 0
f 0
cc 3
eloc 14
nc 4
nop 0
crap 12
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\Application\Model\Components;
16
17
use mrcnpdlk\Grandstream\XMLApp\Application\ModelInterface;
18
use mrcnpdlk\Grandstream\XMLApp\Helper\Font;
19
use mrcnpdlk\Grandstream\XMLApp\Helper\Point;
20
use mrcnpdlk\Grandstream\XMLApp\Helper\Rectangle;
21
use mrcnpdlk\Grandstream\XMLApp\MyXML;
22
23
/**
24
 * Class ElemString
25
 *
26
 * This element is used for displaying string information on the screen
27
 *
28
 * <ElemString font="unifont" width="width of the string" height="height of the string" halign="center/left/right" color="color of the string" bgcolor="color of the background" >
29
 * <X>X location</X>
30
 * <Y>Y location </Y>
31
 * <DisplayStr>Display String</DisplayStr>
32
 * </ElemString>
33
 *
34
 * @package mrcnpdlk\Grandstream\XMLApp\CustomScreen\Model
35
 */
36
class ElemString extends ElemAbstract implements ModelInterface, ElemInterface
37
{
38
39
    /**
40
     * @var string
41
     */
42
    private $sString;
43
    /**
44
     * Font type
45
     *
46
     * @var Font
47
     */
48
    private $oFont;
49
50
    /**
51
     * ElemString constructor.
52
     *
53
     * @param string    $sString
54
     * @param Rectangle $oRectangle
55
     */
56
    public function __construct(string $sString, Rectangle $oRectangle = null)
57
    {
58
        parent::__construct(new Point(0, 0), $oRectangle);
59
        $this->sString = $sString;
60
        $this->setFont();
61
62
    }
63
64
    /**
65
     * @param \mrcnpdlk\Grandstream\XMLApp\Helper\Font|null $oFont
66
     *
67
     * @return \mrcnpdlk\Grandstream\XMLApp\Application\Model\Components\ElemString
68
     */
69
    public function setFont(Font $oFont = null)
70
    {
71
        $this->oFont = $oFont ?? new Font();
72
73
        return $this;
74
    }
75
76
    /**
77
     * @return MyXML
78
     */
79
    public function getXml(): MyXML
80
    {
81
        $oXml = new MyXML('DisplayString');
82
83
        $oXml->asObject()->addAttribute('font', $this->getFont()->getType());
84
        if ($this->getRectangle()->getWidth()) {
85
            $oXml->asObject()->addAttribute('width', $this->getRectangle()->getWidth());
86
        }
87
        if ($this->getRectangle()->getHeight()) {
88
            $oXml->asObject()->addAttribute('height', $this->getRectangle()->getHeight());
89
        }
90
91
        $oXml->asObject()->addAttribute('halign', $this->getFont()->getHorizontalAlign());
92
        $oXml->asObject()->addAttribute('color', $this->getFont()->getColor()->get());
93
        $oXml->asObject()->addAttribute('bgcolor', $this->getColorBg()->get());
94
        //$oXml->asObject()->addAttribute('renew-rate', 'second');
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
95
        //$oXml->asObject()->addAttribute('isrenew', 'true');
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
96
        $oXml->asObject()->addChild('X', $this->getPoint()->getX());
97
        $oXml->asObject()->addChild('Y', $this->getPoint()->getY());
98
        $oXml->asObject()->addChild('DisplayStr', $this->sString);
99
100
        return $oXml;
101
    }
102
103
    /**
104
     * @return \mrcnpdlk\Grandstream\XMLApp\Helper\Font
105
     */
106
    public function getFont()
107
    {
108
        return $this->oFont;
109
    }
110
}
111