Passed
Push — master ( d05758...b44de9 )
by Joas
16:05 queued 13s
created

TooManyRequests::getHTTPCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 1
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * @copyright Copyright (c) 2023 Joas Schilling <[email protected]>
6
 *
7
 * @author Joas Schilling <[email protected]>
8
 *
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
namespace OCA\DAV\Connector\Sabre\Exception;
27
28
use DOMElement;
29
use Sabre\DAV\Exception\NotAuthenticated;
30
use Sabre\DAV\Server;
31
32
class TooManyRequests extends NotAuthenticated {
33
	public const NS_OWNCLOUD = 'http://owncloud.org/ns';
34
35
	public function getHTTPCode() {
36
		return 429;
37
	}
38
39
	/**
40
	 * This method allows the exception to include additional information
41
	 * into the WebDAV error response
42
	 *
43
	 * @param Server $server
44
	 * @param DOMElement $errorNode
45
	 * @return void
46
	 */
47
	public function serialize(Server $server, DOMElement $errorNode) {
48
49
		// set ownCloud namespace
50
		$errorNode->setAttribute('xmlns:o', self::NS_OWNCLOUD);
51
52
		$error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'too many requests');
0 ignored issues
show
Bug introduced by
The method createElementNS() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
		/** @scrutinizer ignore-call */ 
53
  $error = $errorNode->ownerDocument->createElementNS('o:', 'o:hint', 'too many requests');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
		$errorNode->appendChild($error);
54
	}
55
}
56