Completed
Branch master (f94168)
by Steffen
03:41 queued 01:40
created

Rule::toDMN()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SteffenBrand\DmnDecisionTables\Model;
4
5
/**
6
 * Class Rule
7
 * @package SteffenBrand\DmnDecisionTables\Model
8
 */
9
class Rule implements DmnConvertibleInterface
10
{
11
    use ArrayToDmnTrait;
12
13
    /**
14
     * @var string
15
     */
16
    private $description;
17
18
    /**
19
     * @var InputEntry[]
20
     */
21
    private $inputEntries;
22
23
    /**
24
     * @var OutputEntry[]
25
     */
26
    private $outputEntries;
27
28
    /**
29
     * Rule constructor.
30
     * @see https://docs.camunda.org/manual/latest/reference/dmn11/feel/
31
     * @param InputEntry[] $inputEntries
32
     * @param OutputEntry[] $outputEntries
33
     * @param string|null $description
34
     */
35
    public function __construct($inputEntries, $outputEntries, $description = null)
36
    {
37
        $this->inputEntries = $inputEntries;
38
        $this->outputEntries = $outputEntries;
39
        $this->description = $description;
40
    }
41
42
    /**
43
     * Returns an XML representation of a rule.
44
     *
45
     * @return string
46
     */
47
    public function toDMN()
48
    {
49
        return
50
            '<rule id="' . uniqid('rule') . '">' .
51
                $this->getDescriptionXml() .
52
                $this->getDmnFromArray($this->inputEntries) .
53
                $this->getDmnFromArray($this->outputEntries) .
54
            '</rule>';
55
    }
56
57
    /**
58
     * @return string
59
     */
60
    private function getDescriptionXml()
61
    {
62
        if (isset($this->description) === false || trim($this->description) === '') {
63
            return '';
64
        }
65
        return '<description>' . $this->description . '</description>';
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getDescription()
72
    {
73
        return $this->description;
74
    }
75
76
    /**
77
     * @return InputEntry[]
78
     */
79
    public function getInputEntries()
80
    {
81
        return $this->inputEntries;
82
    }
83
84
    /**
85
     * @return OutputEntry[]
86
     */
87
    public function getOutputEntries()
88
    {
89
        return $this->outputEntries;
90
    }
91
}