Passed
Push — master ( dd9428...b40603 )
by Roeland
18:23 queued 08:05
created

PublicKeyToken::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/** @noinspection ALL */
3
declare(strict_types=1);
4
/**
5
 * @copyright Copyright (c) 2018 Roeland Jago Douma <[email protected]>
6
 *
7
 * @author Roeland Jago Douma <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
namespace OC\Authentication\Token;
27
28
use OCP\AppFramework\Db\Entity;
29
30
/**
31
 * @method void setId(int $id)
32
 * @method void setUid(string $uid);
33
 * @method void setLoginName(string $loginname)
34
 * @method string getToken()
35
 * @method void setType(int $type)
36
 * @method int getType()
37
 * @method void setRemember(int $remember)
38
 * @method void setLastActivity(int $lastactivity)
39
 * @method int getLastActivity()
40
 * @method string getPrivateKey()
41
 * @method void setPrivateKey(string $key)
42
 * @method string getPublicKey()
43
 * @method void setPublicKey(string $key)
44
 * @method void setVersion(int $version)
45
 * @method bool getPasswordInvalid()
46
 */
47
class PublicKeyToken extends Entity implements INamedToken {
48
49
	const VERSION = 2;
50
51
	/** @var string user UID */
52
	protected $uid;
53
54
	/** @var string login name used for generating the token */
55
	protected $loginName;
56
57
	/** @var string encrypted user password */
58
	protected $password;
59
60
	/** @var string token name (e.g. browser/OS) */
61
	protected $name;
62
63
	/** @var string */
64
	protected $token;
65
66
	/** @var int */
67
	protected $type;
68
69
	/** @var int */
70
	protected $remember;
71
72
	/** @var int */
73
	protected $lastActivity;
74
75
	/** @var int */
76
	protected $lastCheck;
77
78
	/** @var string */
79
	protected $scope;
80
81
	/** @var int */
82
	protected $expires;
83
84
	/** @var string */
85
	protected $privateKey;
86
87
	/** @var string */
88
	protected $publicKey;
89
90
	/** @var int */
91
	protected $version;
92
93
	/** @var bool */
94
	protected $passwordInvalid;
95
96
	public function __construct() {
97
		$this->addType('uid', 'string');
98
		$this->addType('loginName', 'string');
99
		$this->addType('password', 'string');
100
		$this->addType('name', 'string');
101
		$this->addType('token', 'string');
102
		$this->addType('type', 'int');
103
		$this->addType('remember', 'int');
104
		$this->addType('lastActivity', 'int');
105
		$this->addType('lastCheck', 'int');
106
		$this->addType('scope', 'string');
107
		$this->addType('expires', 'int');
108
		$this->addType('publicKey', 'string');
109
		$this->addType('privateKey', 'string');
110
		$this->addType('version', 'int');
111
		$this->addType('passwordInvalid', 'bool');
112
	}
113
114
	public function getId(): int {
115
		return $this->id;
116
	}
117
118
	public function getUID(): string {
119
		return $this->uid;
120
	}
121
122
	/**
123
	 * Get the login name used when generating the token
124
	 *
125
	 * @return string
126
	 */
127
	public function getLoginName(): string {
128
		return parent::getLoginName();
0 ignored issues
show
Bug introduced by
The method getLoginName() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

128
		return parent::/** @scrutinizer ignore-call */ getLoginName();
Loading history...
129
	}
130
131
	/**
132
	 * Get the (encrypted) login password
133
	 *
134
	 * @return string|null
135
	 */
136
	public function getPassword() {
137
		return parent::getPassword();
0 ignored issues
show
Bug introduced by
The method getPassword() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

137
		return parent::/** @scrutinizer ignore-call */ getPassword();
Loading history...
138
	}
139
140
	public function jsonSerialize() {
141
		return [
142
			'id' => $this->id,
143
			'name' => $this->name,
144
			'lastActivity' => $this->lastActivity,
145
			'type' => $this->type,
146
			'scope' => $this->getScopeAsArray()
147
		];
148
	}
149
150
	/**
151
	 * Get the timestamp of the last password check
152
	 *
153
	 * @return int
154
	 */
155
	public function getLastCheck(): int {
156
		return parent::getLastCheck();
0 ignored issues
show
Bug introduced by
The method getLastCheck() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

156
		return parent::/** @scrutinizer ignore-call */ getLastCheck();
Loading history...
157
	}
158
159
	/**
160
	 * Get the timestamp of the last password check
161
	 *
162
	 * @param int $time
163
	 */
164
	public function setLastCheck(int $time) {
165
		parent::setLastCheck($time);
0 ignored issues
show
Bug introduced by
The method setLastCheck() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

165
		parent::/** @scrutinizer ignore-call */ 
166
          setLastCheck($time);
Loading history...
166
	}
167
168
	public function getScope(): string {
169
		$scope = parent::getScope();
0 ignored issues
show
Bug introduced by
The method getScope() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

169
		/** @scrutinizer ignore-call */ 
170
  $scope = parent::getScope();
Loading history...
170
		if ($scope === null) {
0 ignored issues
show
introduced by
The condition $scope === null is always false.
Loading history...
171
			return '';
172
		}
173
174
		return $scope;
175
	}
176
177
	public function getScopeAsArray(): array {
178
		$scope = json_decode($this->getScope(), true);
179
		if (!$scope) {
180
			return [
181
				'filesystem'=> true
182
			];
183
		}
184
		return $scope;
185
	}
186
187
	public function setScope($scope) {
188
		if (is_array($scope)) {
189
			parent::setScope(json_encode($scope));
0 ignored issues
show
Bug introduced by
json_encode($scope) of type string is incompatible with the type array expected by parameter $scope of OC\Authentication\Token\IToken::setScope(). ( Ignorable by Annotation )

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

189
			parent::setScope(/** @scrutinizer ignore-type */ json_encode($scope));
Loading history...
Bug introduced by
The method setScope() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

189
			parent::/** @scrutinizer ignore-call */ 
190
           setScope(json_encode($scope));
Loading history...
190
		} else {
191
			parent::setScope((string)$scope);
192
		}
193
	}
194
195
	public function getName(): string {
196
		return parent::getName();
0 ignored issues
show
Bug introduced by
The method getName() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

196
		return parent::/** @scrutinizer ignore-call */ getName();
Loading history...
197
	}
198
199
	public function setName(string $name): void {
200
		parent::setName($name);
0 ignored issues
show
Bug introduced by
The method setName() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

200
		parent::/** @scrutinizer ignore-call */ 
201
          setName($name);
Loading history...
201
	}
202
203
	public function getRemember(): int {
204
		return parent::getRemember();
0 ignored issues
show
Bug introduced by
The method getRemember() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

204
		return parent::/** @scrutinizer ignore-call */ getRemember();
Loading history...
205
	}
206
207
	public function setToken(string $token) {
208
		parent::setToken($token);
0 ignored issues
show
Bug introduced by
The method setToken() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

208
		parent::/** @scrutinizer ignore-call */ 
209
          setToken($token);
Loading history...
209
	}
210
211
	public function setPassword(string $password = null) {
212
		parent::setPassword($password);
0 ignored issues
show
Bug introduced by
The method setPassword() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

212
		parent::/** @scrutinizer ignore-call */ 
213
          setPassword($password);
Loading history...
Bug introduced by
It seems like $password can also be of type null; however, parameter $password of OC\Authentication\Token\IToken::setPassword() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

212
		parent::setPassword(/** @scrutinizer ignore-type */ $password);
Loading history...
213
	}
214
215
	public function setExpires($expires) {
216
		parent::setExpires($expires);
0 ignored issues
show
Bug introduced by
The method setExpires() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

216
		parent::/** @scrutinizer ignore-call */ 
217
          setExpires($expires);
Loading history...
217
	}
218
219
	/**
220
	 * @return int|null
221
	 */
222
	public function getExpires() {
223
		return parent::getExpires();
0 ignored issues
show
Bug introduced by
The method getExpires() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

223
		return parent::/** @scrutinizer ignore-call */ getExpires();
Loading history...
224
	}
225
226
	public function setPasswordInvalid(bool $invalid) {
227
		parent::setPasswordInvalid($invalid);
0 ignored issues
show
Bug introduced by
The method setPasswordInvalid() does not exist on OCP\AppFramework\Db\Entity. Since it exists in all sub-types, consider adding an abstract or default implementation to OCP\AppFramework\Db\Entity. ( Ignorable by Annotation )

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

227
		parent::/** @scrutinizer ignore-call */ 
228
          setPasswordInvalid($invalid);
Loading history...
228
	}
229
}
230