| Total Complexity | 15 |
| Total Lines | 106 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | class ChooseIf implements Rendering, HasParent |
||
| 30 | { |
||
| 31 | |||
| 32 | /** |
||
|
1 ignored issue
–
show
|
|||
| 33 | * @var ArrayList<ConstraintInterface> |
||
| 34 | */ |
||
| 35 | private $constraints; |
||
| 36 | |||
| 37 | /** |
||
|
1 ignored issue
–
show
|
|||
| 38 | * @var ConstraintInterface |
||
| 39 | */ |
||
| 40 | private $constraint; |
||
| 41 | |||
| 42 | /** |
||
|
1 ignored issue
–
show
|
|||
| 43 | * @var ArrayList |
||
| 44 | */ |
||
| 45 | protected $children; |
||
| 46 | |||
| 47 | private $match; |
||
| 48 | |||
| 49 | /** |
||
|
1 ignored issue
–
show
|
|||
| 50 | * @var |
||
| 51 | */ |
||
| 52 | protected $parent; |
||
| 53 | |||
| 54 | /** |
||
|
1 ignored issue
–
show
|
|||
| 55 | * @param SimpleXMLElement $node |
||
|
2 ignored issues
–
show
|
|||
| 56 | * @param Choose $parent |
||
|
3 ignored issues
–
show
|
|||
| 57 | * @throws InvalidStylesheetException |
||
|
1 ignored issue
–
show
|
|||
| 58 | * @throws ClassNotFoundException |
||
|
1 ignored issue
–
show
|
|||
| 59 | */ |
||
| 60 | public function __construct(SimpleXMLElement $node, $parent) |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
|
1 ignored issue
–
show
|
|||
| 83 | * @param array|DataList $data |
||
|
2 ignored issues
–
show
|
|||
| 84 | * @param null|int $citationNumber |
||
|
3 ignored issues
–
show
|
|||
| 85 | * @return string |
||
|
1 ignored issue
–
show
|
|||
| 86 | */ |
||
| 87 | public function render($data, $citationNumber = null) |
||
| 88 | { |
||
| 89 | $ret = []; |
||
| 90 | /** @var Rendering $child */ |
||
|
3 ignored issues
–
show
|
|||
| 91 | foreach ($this->children as $child) { |
||
| 92 | $ret[] = $child->render($data, $citationNumber); |
||
| 93 | } |
||
| 94 | return implode("", $ret); |
||
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
|
1 ignored issue
–
show
|
|||
| 98 | * @param $data |
||
|
1 ignored issue
–
show
|
|||
| 99 | * @param null|int $citationNumber |
||
|
2 ignored issues
–
show
|
|||
| 100 | * @return bool |
||
|
1 ignored issue
–
show
|
|||
| 101 | */ |
||
| 102 | public function match($data, $citationNumber = null) |
||
| 103 | { |
||
| 104 | if (isset($this->constraint)) { |
||
| 105 | return $this->constraint->validate($data); |
||
| 106 | } |
||
| 107 | |||
| 108 | $result = true; |
||
| 109 | |||
| 110 | /** @var ConstraintInterface $constraint */ |
||
|
3 ignored issues
–
show
|
|||
| 111 | foreach ($this->constraints as $constraint) { |
||
| 112 | if ($this->match === "any") { |
||
| 113 | if ($constraint->validate($data, $citationNumber)) { |
||
| 114 | return true; |
||
| 115 | } |
||
| 116 | } else { |
||
| 117 | $result &= $constraint->validate($data, $citationNumber); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | if ($this->match === "all") { |
||
| 122 | return (bool) $result; |
||
| 123 | } else if ($this->match === "none") { |
||
| 124 | return !$result; |
||
| 125 | } |
||
| 126 | return false; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
|
1 ignored issue
–
show
|
|||
| 130 | * @return Choose |
||
| 131 | */ |
||
| 132 | public function getParent() |
||
| 135 | } |
||
| 136 | |||
| 137 | } |
||
| 138 |