Completed
Pull Request — master (#226)
by Victor
21:57 queued 20:26
created

AntivirusPlugin::beforeMove()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 17
ccs 0
cts 17
cp 0
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 11
nc 2
nop 2
crap 6
1
<?php
2
/**
3
 * ownCloud - Files_antivirus
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Viktar Dubiniuk <[email protected]>
9
 *
10
 * @copyright Viktar Dubiniuk 2018
11
 * @license AGPL-3.0
12
 */
13
14
namespace OCA\Files_Antivirus\Dav;
15
16
use OCA\DAV\Upload\FutureFile;
17
use OCP\IUserSession;
18
use Sabre\DAV\Server;
19
use Sabre\DAV\ServerPlugin;
20
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
21
use Symfony\Component\EventDispatcher\GenericEvent;
22
23
/**
24
 * Sabre plugin for the the antivirus
25
 */
26
class AntivirusPlugin extends ServerPlugin {
27
	const NS_OWNCLOUD = 'http://owncloud.org/ns';
28
29
	/**
30
	 * @var \Sabre\DAV\Server $server
31
	 */
32
	private $server;
33
34
	/**
35
	 * @var EventDispatcherInterface
36
	 */
37
	private $dispatcher;
38
39
	/**
40
	 * Constructor
41
	 *
42
	 * @param IUserSession $userSession
43
	 */
44
	public function __construct(
45
		IUserSession $userSession, EventDispatcherInterface $dispatcher
46
	) {
47
		$this->userSession = $userSession;
48
		$this->dispatcher = $dispatcher;
49
	}
50
51
	/**
52
	 * This initializes the plugin.
53
	 *
54
	 * This function is called by Sabre\DAV\Server, after
55
	 * addPlugin is called.
56
	 *
57
	 * This method should set up the required event subscriptions.
58
	 *
59
	 * @param Server $server
60
	 *
61
	 * @return void
62
	 */
63
	public function initialize(Server $server) {
64
		$this->server = $server;
65
		$this->server->on('beforeMove', [$this, 'beforeMove'], 1);
66
	}
67
68
	/**
69
	 * @param string $source
70
	 * @param string $destination
71
	 *
72
	 * @return bool|void
73
	 * @throws \Sabre\DAV\Exception\NotFound
74
	 */
75
	public function beforeMove($source, $destination) {
76
		$sourceNode = $this->server->tree->getNodeForPath($source);
77
		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...
78
			$finalSize = $sourceNode->getSize();
79
			$this->dispatcher->dispatch(
80
				'\OCA\Files_Antivirus\Dav\AntivirusPlugin::beforeMove',
81
				new GenericEvent(
82
					null,
83
					[
84
						'path' => $destination,
85
						'finalSize' => $finalSize
86
					]
87
				)
88
			);
89
		}
90
		return true;
91
	}
92
}
93