Passed
Push — visibilities ( e779e2...5173e6 )
by Matias
11:47
created

Person   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 64%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 79
ccs 16
cts 25
cp 0.64
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A jsonSerialize() 0 9 1
A __construct() 0 5 1
A setIsValid() 0 7 2
A setIsVisible() 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 visible/relevant to user.
53
	 *
54
	 * @var bool
55
	 */
56
	protected $isVisible;
57
58
	/**
59
	 * Whether this person is still valid
60
	 *
61
	 * @var bool
62
	 */
63
	protected $isValid;
64
65
	/**
66
	 * Last timestamp when this person/cluster was created, or when it was refreshed
67
	 *
68
	 * @var \DateTime|null
69
	 */
70
	protected $lastGenerationTime;
71
72
	/**
73
	 * Foreign key to other user that this person belongs to (if it is on same Nextcloud instance).
74
	 * It is set by owner of this cluster. It is optional.
75
	 *
76
	 * @var string|null
77
	*/
78
	protected $linkedUser;
79
80 14
	public function __construct() {
81 14
		$this->addType('id', 'integer');
82 14
		$this->addType('user', 'string');
83 14
		$this->addType('isVisible', 'bool');
84 14
		$this->addType('isValid', 'bool');
85 14
	}
86
87
	public function jsonSerialize() {
88
		return [
89
			'id' => $this->id,
90
			'user' => $this->user,
91
			'name' => $this->name,
92
			'is_visible' => $this->isVisible,
93
			'is_valid' => $this->isValid,
94
			'last_generation_time' => $this->lastGenerationTime,
95
			'linked_user' => $this->linkedUser
96
		];
97
	}
98
99 5
	public function setIsVisible($isVisible): void {
100 5
		if (is_bool($isVisible)) {
101
			$this->isVisible = $isVisible;
102
		} else {
103 5
			$this->isVisible = filter_var($isVisible, FILTER_VALIDATE_BOOLEAN);
104
		}
105 5
		$this->markFieldUpdated('isVisible');
106 5
	}
107
108 14
	public function setIsValid($isValid): void {
109 14
		if (is_bool($isValid)) {
110 12
			$this->isValid = $isValid;
111
		} else {
112 12
			$this->isValid = filter_var($isValid, FILTER_VALIDATE_BOOLEAN);
113
		}
114 14
		$this->markFieldUpdated('isValid');
115 14
	}
116
}
117