Passed
Push — master ( 058135...a4d511 )
by John
13:28 queued 12s
created

File::hasPreview()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Andrew Brown <[email protected]>
6
 * @author Christoph Wurst <[email protected]>
7
 * @author Jörn Friedrich Dreyer <[email protected]>
8
 * @author Lukas Reschke <[email protected]>
9
 * @author Morris Jobke <[email protected]>
10
 *
11
 * @license AGPL-3.0
12
 *
13
 * This code is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License, version 3,
15
 * as published by the Free Software Foundation.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License, version 3,
23
 * along with this program. If not, see <http://www.gnu.org/licenses/>
24
 *
25
 */
26
27
namespace OC\Search\Result;
28
29
use OCP\Files\FileInfo;
30
use OCP\Files\Folder;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, OC\Search\Result\Folder. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
31
use OCP\IPreview;
32
use OCP\IUserSession;
33
34
/**
35
 * A found file
36
 * @deprecated 20.0.0
37
 */
38
class File extends \OCP\Search\Result {
0 ignored issues
show
Deprecated Code introduced by
The class OCP\Search\Result has been deprecated: 20.0.0 ( Ignorable by Annotation )

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

38
class File extends /** @scrutinizer ignore-deprecated */ \OCP\Search\Result {
Loading history...
39
40
	/**
41
	 * Type name; translated in templates
42
	 * @var string
43
	 * @deprecated 20.0.0
44
	 */
45
	public $type = 'file';
46
47
	/**
48
	 * Path to file
49
	 * @var string
50
	 * @deprecated 20.0.0
51
	 */
52
	public $path;
53
54
	/**
55
	 * Size, in bytes
56
	 * @var int
57
	 * @deprecated 20.0.0
58
	 */
59
	public $size;
60
61
	/**
62
	 * Date modified, in human readable form
63
	 * @var string
64
	 * @deprecated 20.0.0
65
	 */
66
	public $modified;
67
68
	/**
69
	 * File mime type
70
	 * @var string
71
	 * @deprecated 20.0.0
72
	 */
73
	public $mime_type;
74
75
	/**
76
	 * File permissions:
77
	 *
78
	 * @var string
79
	 * @deprecated 20.0.0
80
	 */
81
	public $permissions;
82
83
	/**
84
	 * Has a preview
85
	 *
86
	 * @var string
87
	 * @deprecated 20.0.0
88
	 */
89
	public $has_preview;
90
91
	/**
92
	 * Create a new file search result
93
	 * @param FileInfo $data file data given by provider
94
	 * @deprecated 20.0.0
95
	 */
96
	public function __construct(FileInfo $data) {
97
		$path = $this->getRelativePath($data->getPath());
98
99
		$info = pathinfo($path);
100
		$this->id = $data->getId();
0 ignored issues
show
Deprecated Code introduced by
The property OCP\Search\Result::$id has been deprecated: 20.0.0 ( Ignorable by Annotation )

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

100
		/** @scrutinizer ignore-deprecated */ $this->id = $data->getId();

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
101
		$this->name = $info['basename'];
0 ignored issues
show
Deprecated Code introduced by
The property OCP\Search\Result::$name has been deprecated: 20.0.0 ( Ignorable by Annotation )

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

101
		/** @scrutinizer ignore-deprecated */ $this->name = $info['basename'];

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
102
		$this->link = \OC::$server->getURLGenerator()->linkToRoute(
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getURLGenerator() has been deprecated. ( Ignorable by Annotation )

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

102
		$this->link = /** @scrutinizer ignore-deprecated */ \OC::$server->getURLGenerator()->linkToRoute(
Loading history...
Deprecated Code introduced by
The property OCP\Search\Result::$link has been deprecated: 20.0.0 ( Ignorable by Annotation )

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

102
		/** @scrutinizer ignore-deprecated */ $this->link = \OC::$server->getURLGenerator()->linkToRoute(

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
103
			'files.view.index',
104
			[
105
				'dir' => $info['dirname'],
106
				'scrollto' => $info['basename'],
107
			]
108
		);
109
		$this->permissions = $data->getPermissions();
0 ignored issues
show
Deprecated Code introduced by
The property OC\Search\Result\File::$permissions has been deprecated: 20.0.0 ( Ignorable by Annotation )

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

109
		/** @scrutinizer ignore-deprecated */ $this->permissions = $data->getPermissions();

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
110
		$this->path = $path;
0 ignored issues
show
Deprecated Code introduced by
The property OC\Search\Result\File::$path has been deprecated: 20.0.0 ( Ignorable by Annotation )

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

110
		/** @scrutinizer ignore-deprecated */ $this->path = $path;

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
111
		$this->size = $data->getSize();
0 ignored issues
show
Deprecated Code introduced by
The property OC\Search\Result\File::$size has been deprecated: 20.0.0 ( Ignorable by Annotation )

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

111
		/** @scrutinizer ignore-deprecated */ $this->size = $data->getSize();

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
112
		$this->modified = $data->getMtime();
0 ignored issues
show
Deprecated Code introduced by
The property OC\Search\Result\File::$modified has been deprecated: 20.0.0 ( Ignorable by Annotation )

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

112
		/** @scrutinizer ignore-deprecated */ $this->modified = $data->getMtime();

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
113
		$this->mime_type = $data->getMimetype();
0 ignored issues
show
Deprecated Code introduced by
The property OC\Search\Result\File::$mime_type has been deprecated: 20.0.0 ( Ignorable by Annotation )

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

113
		/** @scrutinizer ignore-deprecated */ $this->mime_type = $data->getMimetype();

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
114
		$this->has_preview = $this->hasPreview($data);
0 ignored issues
show
Deprecated Code introduced by
The property OC\Search\Result\File::$has_preview has been deprecated: 20.0.0 ( Ignorable by Annotation )

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

114
		/** @scrutinizer ignore-deprecated */ $this->has_preview = $this->hasPreview($data);

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Documentation Bug introduced by
The property $has_preview was declared of type string, but $this->hasPreview($data) is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
115
	}
116
117
	/**
118
	 * @var Folder $userFolderCache
119
	 * @deprecated 20.0.0
120
	 */
121
	protected static $userFolderCache = null;
122
123
	/**
124
	 * converts a path relative to the users files folder
125
	 * eg /user/files/foo.txt -> /foo.txt
126
	 * @param string $path
127
	 * @return string relative path
128
	 * @deprecated 20.0.0
129
	 */
130
	protected function getRelativePath($path) {
131
		if (!isset(self::$userFolderCache)) {
132
			$userSession = \OC::$server->get(IUserSession::class);
133
			$userID = $userSession->getUser()->getUID();
0 ignored issues
show
Bug introduced by
The method getUser() does not exist on stdClass. ( Ignorable by Annotation )

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

133
			$userID = $userSession->/** @scrutinizer ignore-call */ getUser()->getUID();

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...
134
			self::$userFolderCache = \OC::$server->getUserFolder($userID);
0 ignored issues
show
Deprecated Code introduced by
The function OC\Server::getUserFolder() has been deprecated. ( Ignorable by Annotation )

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

134
			self::$userFolderCache = /** @scrutinizer ignore-deprecated */ \OC::$server->getUserFolder($userID);
Loading history...
135
		}
136
		return self::$userFolderCache->getRelativePath($path);
137
	}
138
139
	/**
140
	 * Is the preview available
141
	 * @param FileInfo $data
142
	 * @return bool
143
	 * @deprecated 20.0.0
144
	 */
145
	protected function hasPreview($data) {
146
		$previewManager = \OC::$server->get(IPreview::class);
147
		return $previewManager->isAvailable($data);
0 ignored issues
show
Bug introduced by
The method isAvailable() does not exist on stdClass. ( Ignorable by Annotation )

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

147
		return $previewManager->/** @scrutinizer ignore-call */ isAvailable($data);

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...
148
	}
149
}
150