Passed
Push — php8 ( 3e2147...190cd5 )
by Matias
10:58 queued 08:41
created

Person   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 58.81%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 61
ccs 10
cts 17
cp 0.5881
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 8 1
A __construct() 0 4 1
A setIsValid() 0 7 2
1
<?php
2
/**
3
 * @copyright Copyright (c) 2020-2021, Matias De lellis <[email protected]>
4
 * @copyright Copyright (c) 2018, Branko Kokanovic <[email protected]>
5
 *
6
 * @author Branko Kokanovic <[email protected]>
7
 *
8
 * @license GNU AGPL version 3 or any later version
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License as
12
 * published by the Free Software Foundation, either version 3 of the
13
 * License, or (at your option) any later version.
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
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 *
23
 */
24
namespace OCA\FaceRecognition\Db;
25
26
use JsonSerializable;
27
28
use OCP\AppFramework\Db\Entity;
29
30
/**
31
 * Person represent one cluster, set of faces. It belongs to $user_id.
32
 *
33
 * @method string getName()
34
 * @method void setName(string $name)
35
 */
36
class Person extends Entity implements JsonSerializable {
37
	/**
38
	 * User this person belongs to
39
	 *
40
	 * @var string
41
	 * */
42
	protected $user;
43
44
	/**
45
	 * Name for this person/cluster. Must exists, even if linked user is set.
46
	 *
47
	 * @var string
48
	 */
49
	protected $name;
50
51
	/**
52
	 * Whether this person is still valid
53
	 *
54
	 * @var bool
55
	 */
56
	protected $isValid;
57
58
	/**
59
	 * Last timestamp when this person/cluster was created, or when it was refreshed
60
	 *
61
	 * @var \DateTime|null
62
	 */
63
	protected $lastGenerationTime;
64
65
	/**
66
	 * Foreign key to other user that this person belongs to (if it is on same Nextcloud instance).
67
	 * It is set by owner of this cluster. It is optional.
68
	 *
69
	 * @var string|null
70
	*/
71
	protected $linkedUser;
72
73 14
	public function __construct() {
74 14
		$this->addType('id', 'integer');
75 14
		$this->addType('user', 'string');
76 14
		$this->addType('isValid', 'bool');
77 14
	}
78
79
	public function jsonSerialize() {
80
		return [
81
			'id' => $this->id,
82
			'user' => $this->user,
83
			'name' => $this->name,
84
			'is_valid' => $this->isValid,
85
			'last_generation_time' => $this->lastGenerationTime,
86
			'linked_user' => $this->linkedUser
87
		];
88
	}
89
90 14
	public function setIsValid($isValid) {
91 14
		if (is_bool($isValid)) {
92 12
			$this->isValid = $isValid;
93
		} else {
94 12
			$this->isValid = filter_var($isValid, FILTER_VALIDATE_BOOLEAN);
95
		}
96 14
		$this->markFieldUpdated('isValid');
97 14
	}
98
}
99