PropfindPlugin::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * @copyright 2018, Roeland Jago Douma <[email protected]>
4
 *
5
 * @author Roeland Jago Douma <[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
24
namespace OCA\Files_Antivirus\Sabre;
25
26
use OCA\DAV\Upload\FutureFile;
27
use OCA\Files_Antivirus\AppConfig;
28
use OCA\Files_Antivirus\Event\ScanStateEvent;
29
use Sabre\DAV\Server;
30
use Sabre\DAV\ServerPlugin;
31
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
32
33
class PropfindPlugin extends ServerPlugin {
34
35
	/** @var Server */
36
	private $server;
37
38
	/** @var AppConfig */
39
	private $appConfig;
40
41
	/** @var EventDispatcherInterface */
42
	private $eventDispatcher;
43
44
45
	public function __construct(AppConfig $appConfig, EventDispatcherInterface $eventDispatcher) {
46
		$this->appConfig = $appConfig;
47
		$this->eventDispatcher = $eventDispatcher;
48
	}
49
50
	public function initialize(Server $server) {
51
		$server->on('beforeMove', [$this, 'beforeMove'], 90);
52
		$this->server = $server;
53
	}
54
55
	/**
56
	 * @param string $sourcePath source path
57
	 * @param string $destination destination path
58
	 */
59
	public function beforeMove($sourcePath, $destination) {
60
		$sourceNode = $this->server->tree->getNodeForPath($sourcePath);
61
		if (!$sourceNode instanceof FutureFile) {
0 ignored issues
show
Bug introduced by
The class OCA\DAV\Upload\FutureFile does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
62
			// skip handling as the source is not a chunked FutureFile
63
			return;
64
		}
65
66
		if ($sourceNode->getSize() > $this->appConfig->getAvMaxFileSize()) {
67
			$this->eventDispatcher->dispatch(
68
				ScanStateEvent::class,
69
				new ScanStateEvent(false)
0 ignored issues
show
Documentation introduced by
new \OCA\Files_Antivirus...t\ScanStateEvent(false) is of type object<OCA\Files_Antivirus\Event\ScanStateEvent>, but the function expects a null|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
			);
71
		}
72
	}
73
}
74