Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
64 / 64 |
|
100.00% |
26 / 26 |
CRAP | |
100.00% |
1 / 1 |
| ResolvedPolicy | |
100.00% |
64 / 64 |
|
100.00% |
26 / 26 |
32 | |
100.00% |
1 / 1 |
| setPolicyKey | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getPolicyKey | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setEffectiveValue | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getEffectiveValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getEffectiveValueAsBool | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
6 | |||
| setInheritedValue | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getInheritedValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setSourceScope | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getSourceScope | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setVisible | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| isVisible | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setEditableByCurrentActor | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| isEditableByCurrentActor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setAllowedValues | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getAllowedValues | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setCanSaveAsUserDefault | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| canSaveAsUserDefault | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setCanUseAsRequestOverride | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| canUseAsRequestOverride | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setPreferenceWasCleared | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| wasPreferenceCleared | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setBlockedBy | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getBlockedBy | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| setMeta | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getMeta | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
16 / 16 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | /** |
| 5 | * SPDX-FileCopyrightText: 2026 LibreCode coop and contributors |
| 6 | * SPDX-License-Identifier: AGPL-3.0-or-later |
| 7 | */ |
| 8 | |
| 9 | namespace OCA\Libresign\Service\Policy\Model; |
| 10 | |
| 11 | final class ResolvedPolicy { |
| 12 | private string $policyKey = ''; |
| 13 | private mixed $effectiveValue = null; |
| 14 | private mixed $inheritedValue = null; |
| 15 | private string $sourceScope = ''; |
| 16 | private bool $visible = false; |
| 17 | private bool $editableByCurrentActor = false; |
| 18 | /** @var list<mixed> */ |
| 19 | private array $allowedValues = []; |
| 20 | private bool $canSaveAsUserDefault = false; |
| 21 | private bool $canUseAsRequestOverride = false; |
| 22 | private bool $preferenceWasCleared = false; |
| 23 | private ?string $blockedBy = null; |
| 24 | /** @var array<string, mixed> */ |
| 25 | private array $meta = []; |
| 26 | |
| 27 | public function setPolicyKey(string $policyKey): self { |
| 28 | $this->policyKey = $policyKey; |
| 29 | return $this; |
| 30 | } |
| 31 | |
| 32 | public function getPolicyKey(): string { |
| 33 | return $this->policyKey; |
| 34 | } |
| 35 | |
| 36 | public function setEffectiveValue(mixed $effectiveValue): self { |
| 37 | $this->effectiveValue = $effectiveValue; |
| 38 | return $this; |
| 39 | } |
| 40 | |
| 41 | public function getEffectiveValue(): mixed { |
| 42 | return $this->effectiveValue; |
| 43 | } |
| 44 | |
| 45 | public function getEffectiveValueAsBool(bool $default = false): bool { |
| 46 | if (is_bool($this->effectiveValue)) { |
| 47 | return $this->effectiveValue; |
| 48 | } |
| 49 | |
| 50 | if ($this->effectiveValue === null) { |
| 51 | return $default; |
| 52 | } |
| 53 | |
| 54 | if (is_int($this->effectiveValue)) { |
| 55 | return $this->effectiveValue !== 0; |
| 56 | } |
| 57 | |
| 58 | if (is_float($this->effectiveValue)) { |
| 59 | return $this->effectiveValue !== 0.0; |
| 60 | } |
| 61 | |
| 62 | if (is_string($this->effectiveValue)) { |
| 63 | $parsed = filter_var($this->effectiveValue, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE); |
| 64 | return $parsed ?? $default; |
| 65 | } |
| 66 | |
| 67 | return $default; |
| 68 | } |
| 69 | |
| 70 | public function setInheritedValue(mixed $inheritedValue): self { |
| 71 | $this->inheritedValue = $inheritedValue; |
| 72 | return $this; |
| 73 | } |
| 74 | |
| 75 | public function getInheritedValue(): mixed { |
| 76 | return $this->inheritedValue; |
| 77 | } |
| 78 | |
| 79 | public function setSourceScope(string $sourceScope): self { |
| 80 | $this->sourceScope = $sourceScope; |
| 81 | return $this; |
| 82 | } |
| 83 | |
| 84 | public function getSourceScope(): string { |
| 85 | return $this->sourceScope; |
| 86 | } |
| 87 | |
| 88 | public function setVisible(bool $visible): self { |
| 89 | $this->visible = $visible; |
| 90 | return $this; |
| 91 | } |
| 92 | |
| 93 | public function isVisible(): bool { |
| 94 | return $this->visible; |
| 95 | } |
| 96 | |
| 97 | public function setEditableByCurrentActor(bool $editableByCurrentActor): self { |
| 98 | $this->editableByCurrentActor = $editableByCurrentActor; |
| 99 | return $this; |
| 100 | } |
| 101 | |
| 102 | public function isEditableByCurrentActor(): bool { |
| 103 | return $this->editableByCurrentActor; |
| 104 | } |
| 105 | |
| 106 | /** @param list<mixed> $allowedValues */ |
| 107 | public function setAllowedValues(array $allowedValues): self { |
| 108 | $this->allowedValues = $allowedValues; |
| 109 | return $this; |
| 110 | } |
| 111 | |
| 112 | /** @return list<mixed> */ |
| 113 | public function getAllowedValues(): array { |
| 114 | return $this->allowedValues; |
| 115 | } |
| 116 | |
| 117 | public function setCanSaveAsUserDefault(bool $canSaveAsUserDefault): self { |
| 118 | $this->canSaveAsUserDefault = $canSaveAsUserDefault; |
| 119 | return $this; |
| 120 | } |
| 121 | |
| 122 | public function canSaveAsUserDefault(): bool { |
| 123 | return $this->canSaveAsUserDefault; |
| 124 | } |
| 125 | |
| 126 | public function setCanUseAsRequestOverride(bool $canUseAsRequestOverride): self { |
| 127 | $this->canUseAsRequestOverride = $canUseAsRequestOverride; |
| 128 | return $this; |
| 129 | } |
| 130 | |
| 131 | public function canUseAsRequestOverride(): bool { |
| 132 | return $this->canUseAsRequestOverride; |
| 133 | } |
| 134 | |
| 135 | public function setPreferenceWasCleared(bool $preferenceWasCleared): self { |
| 136 | $this->preferenceWasCleared = $preferenceWasCleared; |
| 137 | return $this; |
| 138 | } |
| 139 | |
| 140 | public function wasPreferenceCleared(): bool { |
| 141 | return $this->preferenceWasCleared; |
| 142 | } |
| 143 | |
| 144 | public function setBlockedBy(?string $blockedBy): self { |
| 145 | $this->blockedBy = $blockedBy; |
| 146 | return $this; |
| 147 | } |
| 148 | |
| 149 | public function getBlockedBy(): ?string { |
| 150 | return $this->blockedBy; |
| 151 | } |
| 152 | |
| 153 | /** @param array<string, mixed> $meta */ |
| 154 | public function setMeta(array $meta): self { |
| 155 | $this->meta = $meta; |
| 156 | return $this; |
| 157 | } |
| 158 | |
| 159 | /** @return array<string, mixed> */ |
| 160 | public function getMeta(): array { |
| 161 | return $this->meta; |
| 162 | } |
| 163 | |
| 164 | /** @return array<string, mixed> */ |
| 165 | public function toArray(): array { |
| 166 | $payload = [ |
| 167 | 'policyKey' => $this->getPolicyKey(), |
| 168 | 'effectiveValue' => $this->getEffectiveValue(), |
| 169 | 'inheritedValue' => $this->getInheritedValue(), |
| 170 | 'sourceScope' => $this->getSourceScope(), |
| 171 | 'visible' => $this->isVisible(), |
| 172 | 'editableByCurrentActor' => $this->isEditableByCurrentActor(), |
| 173 | 'allowedValues' => $this->getAllowedValues(), |
| 174 | 'canSaveAsUserDefault' => $this->canSaveAsUserDefault(), |
| 175 | 'canUseAsRequestOverride' => $this->canUseAsRequestOverride(), |
| 176 | 'preferenceWasCleared' => $this->wasPreferenceCleared(), |
| 177 | 'blockedBy' => $this->getBlockedBy(), |
| 178 | ]; |
| 179 | |
| 180 | if ($this->getMeta() !== []) { |
| 181 | $payload['meta'] = $this->getMeta(); |
| 182 | } |
| 183 | |
| 184 | return $payload; |
| 185 | } |
| 186 | } |