Completed
Push — master ( 8024bc...f8f0d2 )
by Vitor
14s
created

Settings::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7
 * SPDX-License-Identifier: AGPL-3.0-or-later
8
 */
9
10
namespace OCA\TwoFactorGateway\Provider;
11
12
use JsonSerializable;
13
14
class Settings implements JsonSerializable {
15 8
	public function __construct(
16
		public string $name,
17
		public ?string $id = null,
18
		public bool $allowMarkdown = false,
19
		public string $instructions = '',
20
		/**
21
		 * List of fields to be filled by system administrators when configuring the gateway.
22
		 *
23
		 * @var FieldDefinition[]
24
		 */
25
		public array $fields = [],
26
	) {
27 8
	}
28
29
	#[\Override]
30
	public function jsonSerialize(): mixed {
31
		return [
32
			'name' => $this->name,
33
			'id' => $this->id,
34
			'allow_markdown' => $this->allowMarkdown,
35
			'instructions' => $this->instructions,
36
			'fields' => $this->fields,
37
		];
38
	}
39
40
	protected function resolveId(): string {
41
		if (!empty($this->id)) {
42
			return $this->id;
43
		}
44
		return strtolower((new \ReflectionClass($this))->getShortName());
45
	}
46
}
47