Completed
Push — master ( 145757...1e1718 )
by
unknown
19:37 queued 07:09
created

SearchRequest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B xmlDeserialize() 0 39 8
1
<?php
2
/**
3
 * @author Juan Pablo Villafañez <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2018, ownCloud GmbH
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace OCA\DAV\Files\Xml;
23
24
use Sabre\Xml\Element\Base;
25
use Sabre\Xml\Element\KeyValue;
26
use Sabre\Xml\Reader;
27
use Sabre\Xml\XmlDeserializable;
28
29
class SearchRequest implements XmlDeserializable {
30
	/**
31
	 * An array with requested properties.
32
	 *
33
	 * @var array
34
	 */
35
	public $properties;
36
37
	/**
38
	 * @var array
39
	 */
40
	public $searchInfo;
41
42
	public static function xmlDeserialize(Reader $reader) {
43
		$newProps = [
44
			'properties' => [],
45
			'searchInfo' => null,
46
		];
47
48
		$elems = (array)$reader->parseInnerTree([
49
			'{DAV:}prop' => KeyValue::class,
50
			'{http://owncloud.org/ns}search' => KeyValue::class,
51
		]);
52
53
		if (!\is_array($elems)) {
54
			$elems = [];
55
		}
56
57
		foreach ($elems as $elem) {
58
			switch ($elem['name']) {
59
				case '{DAV:}prop':
60
					$newProps['properties'] = \array_keys($elem['value']);
61
					break;
62
				case '{http://owncloud.org/ns}search':
63
					$value = $elem['value'];
64
					if (isset($value['{http://owncloud.org/ns}pattern'])) {
65
						$newProps['searchInfo']['pattern'] = $value['{http://owncloud.org/ns}pattern'];
66
					}
67
					if (isset($value['{http://owncloud.org/ns}limit'])) {
68
						$newProps['searchInfo']['limit'] = (int)$value['{http://owncloud.org/ns}limit'];
69
					}
70
					break;
71
			}
72
		}
73
74
		$obj = new self();
75
		foreach ($newProps as $key => $value) {
76
			$obj->$key = $value;
77
		}
78
79
		return $obj;
80
	}
81
}
82