Passed
Push — master ( 3d1c78...1b4788 )
by Blizzz
20:40 queued 05:15
created

AccountProperty::setVerified()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @copyright Copyright (c) 2018 Julius Härtl <[email protected]>
7
 *
8
 * @author Julius Härtl <[email protected]>
9
 *
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
namespace OC\Accounts;
28
29
use OCP\Accounts\IAccountManager;
30
use OCP\Accounts\IAccountProperty;
31
32
class AccountProperty implements IAccountProperty {
33
34
	/** @var string */
35
	private $name;
36
	/** @var string */
37
	private $value;
38
	/** @var string */
39
	private $scope;
40
	/** @var string */
41
	private $verified;
42
	/** @var string */
43
	private $verificationData;
44
45
	public function __construct(string $name, string $value, string $scope, string $verified, string $verificationData) {
46
		$this->name = $name;
47
		$this->value = $value;
48
		$this->setScope($scope);
49
		$this->verified = $verified;
50
		$this->verificationData = $verificationData;
51
	}
52
53
	public function jsonSerialize() {
54
		return [
55
			'name' => $this->getName(),
56
			'value' => $this->getValue(),
57
			'scope' => $this->getScope(),
58
			'verified' => $this->getVerified(),
59
			'verificationData' => $this->getVerificationData(),
60
		];
61
	}
62
63
	/**
64
	 * Set the value of a property
65
	 *
66
	 * @since 15.0.0
67
	 *
68
	 * @param string $value
69
	 * @return IAccountProperty
70
	 */
71
	public function setValue(string $value): IAccountProperty {
72
		$this->value = $value;
73
		return $this;
74
	}
75
76
	/**
77
	 * Set the scope of a property
78
	 *
79
	 * @since 15.0.0
80
	 *
81
	 * @param string $scope
82
	 * @return IAccountProperty
83
	 */
84
	public function setScope(string $scope): IAccountProperty {
85
		$newScope = $this->mapScopeToV2($scope);
86
		if (!in_array($newScope, [
87
			IAccountManager::SCOPE_LOCAL,
88
			IAccountManager::SCOPE_FEDERATED,
89
			IAccountManager::SCOPE_PRIVATE,
90
			IAccountManager::SCOPE_PUBLISHED
91
		])) {
92
			throw new \InvalidArgumentException('Invalid scope');
93
		}
94
		$this->scope = $newScope;
95
		return $this;
96
	}
97
98
	/**
99
	 * Set the verification status of a property
100
	 *
101
	 * @since 15.0.0
102
	 *
103
	 * @param string $verified
104
	 * @return IAccountProperty
105
	 */
106
	public function setVerified(string $verified): IAccountProperty {
107
		$this->verified = $verified;
108
		return $this;
109
	}
110
111
	/**
112
	 * Get the name of a property
113
	 *
114
	 * @since 15.0.0
115
	 *
116
	 * @return string
117
	 */
118
	public function getName(): string {
119
		return $this->name;
120
	}
121
122
	/**
123
	 * Get the value of a property
124
	 *
125
	 * @since 15.0.0
126
	 *
127
	 * @return string
128
	 */
129
	public function getValue(): string {
130
		return $this->value;
131
	}
132
133
	/**
134
	 * Get the scope of a property
135
	 *
136
	 * @since 15.0.0
137
	 *
138
	 * @return string
139
	 */
140
	public function getScope(): string {
141
		return $this->scope;
142
	}
143
144
	public static function mapScopeToV2(string $scope): string {
145
		if (strpos($scope, 'v2-') === 0) {
146
			return $scope;
147
		}
148
149
		switch ($scope) {
150
			case IAccountManager::VISIBILITY_PRIVATE:
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\Accounts\IAccountManager::VISIBILITY_PRIVATE has been deprecated: 21.0.1 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

150
			case /** @scrutinizer ignore-deprecated */ IAccountManager::VISIBILITY_PRIVATE:

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
151
				return IAccountManager::SCOPE_LOCAL;
152
			case IAccountManager::VISIBILITY_CONTACTS_ONLY:
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\Accounts\IAccountMan...ISIBILITY_CONTACTS_ONLY has been deprecated: 21.0.1 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

152
			case /** @scrutinizer ignore-deprecated */ IAccountManager::VISIBILITY_CONTACTS_ONLY:

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
153
				return IAccountManager::SCOPE_FEDERATED;
154
			case IAccountManager::VISIBILITY_PUBLIC:
0 ignored issues
show
Deprecated Code introduced by
The constant OCP\Accounts\IAccountManager::VISIBILITY_PUBLIC has been deprecated: 21.0.1 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

154
			case /** @scrutinizer ignore-deprecated */ IAccountManager::VISIBILITY_PUBLIC:

This class constant has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.

Loading history...
155
				return IAccountManager::SCOPE_PUBLISHED;
156
			default:
157
				return $scope;
158
		}
159
	}
160
161
	/**
162
	 * Get the verification status of a property
163
	 *
164
	 * @since 15.0.0
165
	 *
166
	 * @return string
167
	 */
168
	public function getVerified(): string {
169
		return $this->verified;
170
	}
171
172
	public function setVerificationData(string $verificationData): IAccountProperty {
173
		$this->verificationData = $verificationData;
174
		return $this;
175
	}
176
177
	public function getVerificationData(): string {
178
		return $this->verificationData;
179
	}
180
}
181