OutputEntry::toDMN()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 2
nop 0
dl 0
loc 15
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace SteffenBrand\DmnDecisionTables\Model;
4
5
use SteffenBrand\DmnDecisionTables\Constant\ExpressionLanguage;
6
7
/**
8
 * Class OutputEntry
9
 * @package SteffenBrand\DmnDecisionTables\Model
10
 */
11
class OutputEntry implements DmnConvertibleInterface
12
{
13
    /**
14
     * @var string
15
     */
16
    private $expression;
17
18
    /**
19
     * @var string
20
     */
21
    private $expressionLanguage;
22
23
    /**
24
     * OutputEntry constructor.
25
     * @param string $expression
26
     * @param string $expressionLanguage
27
     */
28
    public function __construct($expression, $expressionLanguage = ExpressionLanguage::JUEL_LANGUAGE)
29
    {
30
        $this->expression = $expression;
31
        $this->expressionLanguage = $expressionLanguage;
32
    }
33
34
    /**
35
     * Returns an XML representation of an output entry.
36
     *
37
     * @return string
38
     */
39
    public function toDMN()
40
    {
41
        $xml = '';
42
43
        if (isset($this->expression) === false || trim($this->expression) === '') {
44
            $xml .=
45
                '<outputEntry id="' . uniqid('outputEntry') . '"><text/></outputEntry>';
46
        } else {
47
            $xml .=
48
                '<outputEntry id="' . uniqid('outputEntry') . '" expressionLanguage="' . $this->expressionLanguage . '">' .
49
                    '<text><![CDATA[' . $this->expression . ']]></text>' .
50
                '</outputEntry>';
51
        }
52
53
        return $xml;
54
    }
55
56
    /**
57
     * @return string
58
     */
59
    public function getExpression()
60
    {
61
        return $this->expression;
62
    }
63
64
    /**
65
     * @return string
66
     */
67
    public function getExpressionLanguage()
68
    {
69
        return $this->expressionLanguage;
70
    }
71
}