Passed
Push — davplugin ( c34882...1d877a )
by Matias
06:20
created

PersonsList::xmlSerialize()   B

Complexity

Conditions 9
Paths 129

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 90

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 18
c 1
b 0
f 0
nc 129
nop 1
dl 0
loc 27
ccs 0
cts 19
cp 0
crap 90
rs 7.8138
1
<?php
2
/**
3
 * @copyright Copyright (c) 2021 Matias De lellis <[email protected]>
4
 *
5
 * @author Matias De lellis <[email protected]>
6
 *
7
 * @license AGPL-3.0
8
 *
9
 * This code is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License, version 3,
11
 * as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Affero General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Affero General Public License, version 3,
19
 * along with this program. If not, see <http://www.gnu.org/licenses/>
20
 *
21
 */
22
namespace OCA\FaceRecognition\Dav;
23
24
use OCA\FaceRecognition\AppInfo\Application;
25
26
use Sabre\Xml\Writer;
0 ignored issues
show
Bug introduced by
The type Sabre\Xml\Writer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
27
use Sabre\Xml\XmlSerializable;
0 ignored issues
show
Bug introduced by
The type Sabre\Xml\XmlSerializable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
28
29
/**
30
 * Persons property
31
 *
32
 * This property encodes the list of 'persons' property.
33
 */
34
class PersonsList implements XmlSerializable {
35
36
	/**
37
	 * The list of persons
38
	 *
39
	 * @var array
40
	 */
41
	protected $persons;
42
43
	/**
44
	 * Creates the property.
45
	 *
46
	 * Persons is an array. Each element of the array has the following
47
	 * properties:
48
	 *
49
	 *   * name - Optional, name of person.
50
	 *   * id - Optional, id of person cluster.
51
	 *   * count - Optional count of images of that person
52
	 *   * top - Optional top position of the face in some image
53
	 *   * left - Optional left position of the face in some image.
54
	 *   * width - Optional width of the face in some image
55
	 *   * height - Optional height of the face in some image.
56
	 *
57
	 * @param array $persons
58
	 */
59
	public function __construct(array $persons) {
60
		$this->persons = $persons;
61
	}
62
63
	/**
64
	 * Returns the list of person, as it was passed to the constructor.
65
	 *
66
	 * @return array
67
	 */
68
	public function getValue() {
69
		return $this->persons;
70
	}
71
72
	/**
73
	 * The xmlSerialize metod is called during xml writing.
74
	 *
75
	 * Use the $writer argument to write its own xml serialization.
76
	 *
77
	 * An important note: do _not_ create a parent element. Any element
78
	 * implementing XmlSerializble should only ever write what's considered
79
	 * its 'inner xml'.
80
	 *
81
	 * The parent of the current element is responsible for writing a
82
	 * containing element.
83
	 *
84
	 * This allows serializers to be re-used for different element names.
85
	 *
86
	 * If you are opening new elements, you must also close them again.
87
	 *
88
	 * @param Writer $writer
89
	 * @return void
90
	 */
91
	public function xmlSerialize(Writer $writer) {
92
		$cs = '{' . Application::DAV_NS_FACE_RECOGNITION . '}';
93
94
		foreach ($this->persons as $person) {
95
			$writer->startElement($cs . 'person');
96
			if (isset($person['id'])) {
97
				$writer->writeElement($cs . 'id', $person['id']);
98
			}
99
			if (isset($person['name'])) {
100
				$writer->writeElement($cs . 'name', $person['name']);
101
			}
102
			if (isset($person['count'])) {
103
				$writer->writeElement($cs . 'count', $person['count']);
104
			}
105
			if (isset($person['top'])) {
106
				$writer->writeElement($cs . 'top', $person['top']);
107
			}
108
			if (isset($person['left'])) {
109
				$writer->writeElement($cs . 'left', $person['left']);
110
			}
111
			if (isset($person['width'])) {
112
				$writer->writeElement($cs . 'width', $person['width']);
113
			}
114
			if (isset($person['height'])) {
115
				$writer->writeElement($cs . 'height', $person['height']);
116
			}
117
			$writer->endElement();
118
		}
119
	}
120
121
}
122