Passed
Push — master ( 36b01e...018343 )
by John
11:43
created

HasPhotoPlugin::getPluginName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
declare (strict_types = 1);
3
/**
4
 * @copyright Copyright (c) 2019 John Molakvoæ <[email protected]>
5
 *
6
 * @author John Molakvoæ <[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
25
namespace OCA\DAV\CardDAV;
26
27
use Sabre\CardDAV\Card;
28
use Sabre\DAV\INode;
29
use Sabre\DAV\PropFind;
30
use Sabre\DAV\Server;
31
use Sabre\VObject\Component\VCard;
32
use Sabre\VObject\Reader;
33
34
class HasPhotoPlugin extends \Sabre\CardDAV\Plugin {
35
36
	/** @var Server */
37
	protected $server;
38
39
	/**
40
	 * Initializes the plugin and registers event handlers
41
	 *
42
	 * @param Server $server
43
	 * @return void
44
	 */
45
	function initialize(Server $server) {
46
		$server->on('propFind', [$this, 'propFind']);
47
		parent::initialize($server);
48
	}
49
50
	/**
51
	 * Adds all CardDAV-specific properties
52
	 *
53
	 * @param PropFind $propFind
54
	 * @param INode $node
55
	 * @return void
56
	 */
57
	function propFind(PropFind $propFind, INode $node) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
58
59
		$ns = '{http://nextcloud.com/ns}';
60
61
		if ($node instanceof Card) {
62
			$propFind->handle($ns . 'has-photo', function () use ($node) {
63
				$vcard = Reader::read($node->get());
64
				return ($vcard instanceof VCard && $vcard->PHOTO);
65
			});
66
		}
67
	}
68
69
	/**
70
	 * Returns a plugin name.
71
	 *
72
	 * Using this name other plugins will be able to access other plugins
73
	 * using \Sabre\DAV\Server::getPlugin
74
	 *
75
	 * @return string
76
	 */
77
	public function getPluginName() {
78
		return 'vcard-has-photo';
79
	}
80
81
	/**
82
	 * Returns a bunch of meta-data about the plugin.
83
	 *
84
	 * Providing this information is optional, and is mainly displayed by the
85
	 * Browser plugin.
86
	 *
87
	 * The description key in the returned array may contain html and will not
88
	 * be sanitized.
89
	 *
90
	 * @return array
91
	 */
92
	public function getPluginInfo() {
93
		return [
94
			'name'        => $this->getPluginName(),
95
			'description' => 'Return a boolean stating if the vcard have a photo property set or not.'
96
		];
97
98
	}
99
100
}
101