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

DefaultToken::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
declare(strict_types=1);
3
/**
4
 * @copyright Copyright (c) 2016, ownCloud, Inc.
5
 *
6
 * @author Christoph Wurst <[email protected]>
7
 * @author Robin Appelman <[email protected]>
8
 *
9
 * @license AGPL-3.0
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
25
namespace OC\Authentication\Token;
26
27
use OCP\AppFramework\Db\Entity;
28
29
/**
30
 * @method void setId(int $id)
31
 * @method void setUid(string $uid);
32
 * @method void setLoginName(string $loginname)
33
 * @method string getToken()
34
 * @method void setType(int $type)
35
 * @method int getType()
36
 * @method void setRemember(int $remember)
37
 * @method void setLastActivity(int $lastactivity)
38
 * @method int getLastActivity()
39
 * @method void setVersion(int $version)
40
 */
41
class DefaultToken extends Entity implements INamedToken {
42
43
	const VERSION = 1;
44
45
	/** @var string user UID */
46
	protected $uid;
47
48
	/** @var string login name used for generating the token */
49
	protected $loginName;
50
51
	/** @var string encrypted user password */
52
	protected $password;
53
54
	/** @var string token name (e.g. browser/OS) */
55
	protected $name;
56
57
	/** @var string */
58
	protected $token;
59
60
	/** @var int */
61
	protected $type;
62
63
	/** @var int */
64
	protected $remember;
65
66
	/** @var int */
67
	protected $lastActivity;
68
69
	/** @var int */
70
	protected $lastCheck;
71
72
	/** @var string */
73
	protected $scope;
74
75
	/** @var int */
76
	protected $expires;
77
78
	/** @var int */
79
	protected $version;
80
81
	public function __construct() {
82
		$this->addType('uid', 'string');
83
		$this->addType('loginName', 'string');
84
		$this->addType('password', 'string');
85
		$this->addType('name', 'string');
86
		$this->addType('token', 'string');
87
		$this->addType('type', 'int');
88
		$this->addType('remember', 'int');
89
		$this->addType('lastActivity', 'int');
90
		$this->addType('lastCheck', 'int');
91
		$this->addType('scope', 'string');
92
		$this->addType('expires', 'int');
93
		$this->addType('version', 'int');
94
	}
95
96
	public function getId(): int {
97
		return $this->id;
98
	}
99
100
	public function getUID(): string {
101
		return $this->uid;
102
	}
103
104
	/**
105
	 * Get the login name used when generating the token
106
	 *
107
	 * @return string
108
	 */
109
	public function getLoginName(): string {
110
		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

110
		return parent::/** @scrutinizer ignore-call */ getLoginName();
Loading history...
111
	}
112
113
	/**
114
	 * Get the (encrypted) login password
115
	 *
116
	 * @return string|null
117
	 */
118
	public function getPassword() {
119
		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

119
		return parent::/** @scrutinizer ignore-call */ getPassword();
Loading history...
120
	}
121
122
	public function jsonSerialize() {
123
		return [
124
			'id' => $this->id,
125
			'name' => $this->name,
126
			'lastActivity' => $this->lastActivity,
127
			'type' => $this->type,
128
			'scope' => $this->getScopeAsArray()
129
		];
130
	}
131
132
	/**
133
	 * Get the timestamp of the last password check
134
	 *
135
	 * @return int
136
	 */
137
	public function getLastCheck(): int {
138
		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

138
		return parent::/** @scrutinizer ignore-call */ getLastCheck();
Loading history...
139
	}
140
141
	/**
142
	 * Get the timestamp of the last password check
143
	 *
144
	 * @param int $time
145
	 */
146
	public function setLastCheck(int $time) {
147
		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

147
		parent::/** @scrutinizer ignore-call */ 
148
          setLastCheck($time);
Loading history...
148
	}
149
150
	public function getScope(): string {
151
		$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

151
		/** @scrutinizer ignore-call */ 
152
  $scope = parent::getScope();
Loading history...
152
		if ($scope === null) {
0 ignored issues
show
introduced by
The condition $scope === null is always false.
Loading history...
153
			return '';
154
		}
155
156
		return $scope;
157
	}
158
159
	public function getScopeAsArray(): array {
160
		$scope = json_decode($this->getScope(), true);
161
		if (!$scope) {
162
			return [
163
				'filesystem'=> true
164
			];
165
		}
166
		return $scope;
167
	}
168
169
	public function setScope($scope) {
170
		if (\is_array($scope)) {
171
			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

171
			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

171
			parent::/** @scrutinizer ignore-call */ 
172
           setScope(json_encode($scope));
Loading history...
172
		} else {
173
			parent::setScope((string)$scope);
174
		}
175
	}
176
177
	public function getName(): string {
178
		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

178
		return parent::/** @scrutinizer ignore-call */ getName();
Loading history...
179
	}
180
181
	public function setName(string $name): void {
182
		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

182
		parent::/** @scrutinizer ignore-call */ 
183
          setName($name);
Loading history...
183
	}
184
185
	public function getRemember(): int {
186
		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

186
		return parent::/** @scrutinizer ignore-call */ getRemember();
Loading history...
187
	}
188
189
	public function setToken(string $token) {
190
		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

190
		parent::/** @scrutinizer ignore-call */ 
191
          setToken($token);
Loading history...
191
	}
192
193
	public function setPassword(string $password = null) {
194
		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

194
		parent::/** @scrutinizer ignore-call */ 
195
          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

194
		parent::setPassword(/** @scrutinizer ignore-type */ $password);
Loading history...
195
	}
196
197
	public function setExpires($expires) {
198
		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

198
		parent::/** @scrutinizer ignore-call */ 
199
          setExpires($expires);
Loading history...
199
	}
200
201
	/**
202
	 * @return int|null
203
	 */
204
	public function getExpires() {
205
		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

205
		return parent::/** @scrutinizer ignore-call */ getExpires();
Loading history...
206
	}
207
}
208