Completed
Push — master ( ba72ef...999b9c )
by Milan
02:31
created

FileResponseFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
1
<?php
2
3
namespace h4kuna\Upload;
4
5
use Nette\Application,
6
	Nette\Http;
7
8
class FileResponseFactory
9
{
10
11
	/** @var Http\Request */
12
	private $request;
13
14
	/** @var Http\Response */
15
	private $response;
16
17
	/** @var DocumentRoot */
18
	private $documentRoot;
19
20
	public function __construct(Http\Request $request, Http\Response $response, DocumentRoot $documentRoot)
21
	{
22
		$this->request = $request;
23
		$this->response = $response;
24
		$this->documentRoot = $documentRoot;
25
	}
26
27
	/**
28
	 * @param IStoreFile $file
29
	 * @param bool $forceDownload
30
	 * @return Application\Responses\FileResponse
31
	 */
32
	public function create(IStoreFile $file, $forceDownload = TRUE)
33
	{
34
		return new Application\Responses\FileResponse($this->documentRoot->createAbsolutePath($file), $file->getName(), $file->getContentType(), $forceDownload);
35
	}
36
37
	/**
38
	 * @param IStoreFile $file
39
	 * @param bool $forceDownload
40
	 * @return bool
41
	 */
42
	public function send(IStoreFile $file, $forceDownload = TRUE)
43
	{
44
		try {
45
			$this->create($file, $forceDownload)->send($this->request, $this->response);
46
		} catch (Application\BadRequestException $e) {
0 ignored issues
show
Bug introduced by
The class Nette\Application\BadRequestException 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...
47
			return FALSE;
48
		}
49
		return TRUE;
50
	}
51
52
}
53