| Total Complexity | 8 |
| Total Lines | 81 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 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() |
||
| 90 | } |
||
| 91 | } |