Completed
Pull Request — master (#97)
by Thomas
05:56 queued 02:11
created

ImportController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: tcit
5
 * Date: 27/09/16
6
 * Time: 12:23
7
 */
8
9
namespace OCA\calendar\controller;
10
11
12
use OCP\AppFramework\Controller;
13
use OCP\AppFramework\Http\JSONResponse;
14
use OCP\Files\File;
15
use OCP\Files\Folder;
16
use OCP\Files\NotFoundException;
17
use OCP\IRequest;
18
19
class ImportController extends Controller {
20
21
	private $folder;
22
23
	/**
24
	 * ImportController constructor.
25
	 *
26
	 * @param string $appName
27
	 * @param IRequest $request
28
	 * @param Folder $folder
29
	 */
30
	public function __construct($appName, IRequest $request, Folder $folder) {
31
		parent::__construct($appName, $request);
32
		$this->folder = $folder;
33
	}
34
35
	/**
36
	 * @param integer $fileid
37
	 * @return JSONResponse
38
	 * @throws \Exception
39
	 */
40
	public function import($fileid) {
41
		try {
42
			$file = $this->folder->getById($fileid);
43
			if($file[0] instanceof File) {
0 ignored issues
show
Bug introduced by
The class OCP\Files\File 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...
44
				return new JSONResponse([
45
						'body' => $file[0]->getContent(),
46
						'name' => $file[0]->getName(),
47
				]);
48
			} else {
49
				throw new \Exception('Can not read from folder');
50
			}
51
		} catch(NotFoundException $e) {
0 ignored issues
show
Bug introduced by
The class OCP\Files\NotFoundException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
52
			throw new \Exception('File does not exist');
53
		}
54
	}
55
}