Passed
Push — dependabot/npm_and_yarn/minimi... ( f33d6d )
by
unknown
11:45
created

Person   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Test Coverage

Coverage 60.87%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
c 1
b 0
f 0
dl 0
loc 79
ccs 14
cts 23
cp 0.6087
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
 * @method bool getIsVisible()
36
 */
37
class Person extends Entity implements JsonSerializable {
38
	/**
39
	 * User this person belongs to
40
	 *
41
	 * @var string
42
	 * */
43
	protected $user;
44
45
	/**
46
	 * Name for this person/cluster. Must exists, even if linked user is set.
47
	 *
48
	 * @var string
49
	 */
50
	protected $name;
51
52
	/**
53
	 * Whether this person is visible/relevant to user.
54
	 *
55
	 * @var bool
56
	 */
57
	protected $isVisible;
58
59
	/**
60
	 * Whether this person is still valid
61
	 *
62
	 * @var bool
63
	 */
64
	protected $isValid;
65
66
	/**
67
	 * Last timestamp when this person/cluster was created, or when it was refreshed
68
	 *
69
	 * @var \DateTime|null
70
	 */
71
	protected $lastGenerationTime;
72
73
	/**
74
	 * Foreign key to other user that this person belongs to (if it is on same Nextcloud instance).
75
	 * It is set by owner of this cluster. It is optional.
76
	 *
77
	 * @var string|null
78
	*/
79
	protected $linkedUser;
80
81 14
	public function __construct() {
82 14
		$this->addType('id', 'integer');
83 14
		$this->addType('user', 'string');
84 14
		$this->addType('isVisible', 'bool');
85 14
		$this->addType('isValid', 'bool');
86
	}
87
88
	public function jsonSerialize() {
89
		return [
90
			'id' => $this->id,
91
			'user' => $this->user,
92
			'name' => $this->name,
93
			'is_visible' => $this->isVisible,
94
			'is_valid' => $this->isValid,
95
			'last_generation_time' => $this->lastGenerationTime,
96
			'linked_user' => $this->linkedUser
97
		];
98
	}
99
100 5
	public function setIsVisible($isVisible): void {
101 5
		if (is_bool($isVisible)) {
102
			$this->isVisible = $isVisible;
103
		} else {
104 5
			$this->isVisible = filter_var($isVisible, FILTER_VALIDATE_BOOLEAN);
105
		}
106 5
		$this->markFieldUpdated('isVisible');
107
	}
108
109 14
	public function setIsValid($isValid): void {
110 14
		if (is_bool($isValid)) {
111 12
			$this->isValid = $isValid;
112
		} else {
113 12
			$this->isValid = filter_var($isValid, FILTER_VALIDATE_BOOLEAN);
114
		}
115 14
		$this->markFieldUpdated('isValid');
116
	}
117
}
118