Completed
Push — master ( ec6e3a...a32d5d )
by Thomas
10:38
created

FutureFileZsync::isFutureFile()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 2
nop 0
dl 12
loc 12
rs 9.2
c 0
b 0
f 0
1
<?php
2
/*
3
 * Copyright (C) by Ahmed Ammar <[email protected]>
4
 *
5
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
 * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
7
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
8
 * permit persons to whom the Software is furnished to do so, subject to the following conditions:
9
 *
10
 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11
 * Software.
12
 *
13
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17
 *
18
 */
19
namespace OCA\DAV\Upload;
20
21
use OCA\DAV\Connector\Sabre\Directory;
22
use Sabre\DAV\Exception\Forbidden;
23
use Sabre\DAV\IFile;
24
25
/**
26
 * Class FutureFileZsync
27
 *
28
 * The FutureFileZsync is a SabreDav IFile which connects the chunked upload directory
29
 * with the AssemblyStreamZsync, who does the final assembly job
30
 *
31
 * @package OCA\DAV\Upload
32
 */
33
class FutureFileZsync extends FutureFile {
34
35
	/** @var IFile */
36
	private $backingFile = null;
37
	/** @var string */
38
	private $fileLength = 0;
39
40
	static public function getFutureFileName() {
41
		return '.file.zsync';
42
	}
43
44 View Code Duplication
	static public function isFutureFile() {
45
		$davUploadsTarget = '/dav/uploads';
46
47
		// Check if pathinfo starts with dav uploads target and basename is future file basename
48
		if (isset($_SERVER['PATH_INFO'])
49
			&& pathinfo($_SERVER['PATH_INFO'], PATHINFO_BASENAME) === FutureFileZsync::getFutureFileName()
50
			&& (strpos($_SERVER['PATH_INFO'], $davUploadsTarget) === 0)) {
51
			return true;
52
		}
53
54
		return false;
55
	}
56
57
	/**
58
	 * @inheritdoc
59
	 */
60
	function get() {
61
		$nodes = $this->root->getChildren();
62
		return $this->root->childExists('.zsync') && $this->backingFile && $this->fileLength ?
63
			AssemblyStreamZsync::wrap($nodes, $this->backingFile, $this->fileLength) :
0 ignored issues
show
Documentation introduced by
$nodes is of type array<integer,object<Sabre\DAV\INode>>, but the function expects a array<integer,object<Sabre\DAV\IFile>>.

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...
64
			AssemblyStream::wrap($nodes);
0 ignored issues
show
Documentation introduced by
$nodes is of type array<integer,object<Sabre\DAV\INode>>, but the function expects a array<integer,object<Sabre\DAV\IFile>>.

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...
65
	}
66
67
	/**
68
	 * @param IFile $file
69
	 */
70
	function setBackingFile(IFile $file) {
71
		$this->backingFile = $file;
72
	}
73
74
	/**
75
	 * @param string $fileLength
76
	 */
77
	function setFileLength($fileLength) {
78
		$this->fileLength = $fileLength;
79
	}
80
}
81