Passed
Push — master ( b552da...09c1d8 )
by Roeland
12:09 queued 12s
created

ICSExportPlugin::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 * @copyright 2019, Georg Ehrke <[email protected]>
4
 *
5
 * @author Georg Ehrke <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
namespace OCA\DAV\CalDAV\ICSExportPlugin;
24
25
use OCP\IConfig;
26
use OCP\ILogger;
27
use Sabre\HTTP\ResponseInterface;
28
use Sabre\VObject\DateTimeParser;
29
use Sabre\VObject\InvalidDataException;
30
use Sabre\VObject\Property\ICalendar\Duration;
31
32
/**
33
 * Class ICSExportPlugin
34
 *
35
 * @package OCA\DAV\CalDAV\ICSExportPlugin
36
 */
37
class ICSExportPlugin extends \Sabre\CalDAV\ICSExportPlugin {
38
39
	/** @var IConfig */
40
	private $config;
41
42
	/** @var ILogger */
43
	private $logger;
44
45
	/** @var string */
46
	private const DEFAULT_REFRESH_INTERVAL = 'PT4H';
47
48
	/**
49
	 * ICSExportPlugin constructor.
50
	 *
51
	 * @param IConfig $config
52
	 */
53
	public function __construct(IConfig $config, ILogger $logger) {
54
		$this->config = $config;
55
		$this->logger = $logger;
56
	}
57
58
	/**
59
	 * @inheritDoc
60
	 */
61
	protected function generateResponse($path, $start, $end, $expand, $componentType, $format, $properties, ResponseInterface $response) {
62
		if (!isset($properties['{http://nextcloud.com/ns}refresh-interval'])) {
63
			$value = $this->config->getAppValue('dav', 'defaultRefreshIntervalExportedCalendars', self::DEFAULT_REFRESH_INTERVAL);
64
			$properties['{http://nextcloud.com/ns}refresh-interval'] = $value;
65
		}
66
67
		return parent::generateResponse($path, $start, $end, $expand, $componentType, $format, $properties, $response);
0 ignored issues
show
Bug introduced by
Are you sure the usage of parent::generateResponse...$properties, $response) targeting Sabre\CalDAV\ICSExportPlugin::generateResponse() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
68
	}
69
70
	/**
71
	 * @inheritDoc
72
	 */
73
	public function mergeObjects(array $properties, array $inputObjects) {
74
		$vcalendar = parent::mergeObjects($properties, $inputObjects);
75
76
		if (isset($properties['{http://nextcloud.com/ns}refresh-interval'])) {
77
			$refreshIntervalValue = $properties['{http://nextcloud.com/ns}refresh-interval'];
78
			try {
79
				DateTimeParser::parseDuration($refreshIntervalValue);
80
			} catch (InvalidDataException $ex) {
81
				$this->logger->debug('Invalid refresh interval for exported calendar, falling back to default value ...');
82
				$refreshIntervalValue = self::DEFAULT_REFRESH_INTERVAL;
83
			}
84
85
			// https://tools.ietf.org/html/rfc7986#section-5.7
86
			$refreshInterval = new Duration($vcalendar, 'REFRESH-INTERVAL', $refreshIntervalValue);
87
			$refreshInterval->add('VALUE', 'DURATION');
88
			$vcalendar->add($refreshInterval);
89
90
			// Legacy property for compatibility
91
			$vcalendar->{'X-PUBLISHED-TTL'} = $refreshIntervalValue;
92
		}
93
94
		return $vcalendar;
95
	}
96
97
}
98