Passed
Push — develop ( f83164...45f12e )
by Daniel
11:29
created

file::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 *
5
 * @package sitemaker
6
 * @copyright (c) 2021 Daniel A. (blitze)
7
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
8
 *
9
 */
10
11
namespace blitze\sitemaker\controller;
12
13
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
0 ignored issues
show
Bug introduced by
The type Symfony\Bundle\Framework...e\Controller\Controller was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Symfony\Component\HttpFoundation\BinaryFileResponse;
15
use phpbb\exception\http_exception;
16
17
class file
18
{
19
	/** @var \blitze\sitemaker\services\filemanager */
20
	protected $filemanager;
21
22
	/** @var string */
23
	protected $phpbb_root_path;
24
25
	/**
26
	 * Constructor
27
	 *
28
	 * @param \blitze\sitemaker\services\filemanager		$filemanager		Filemanager object
29
	 * @param string										$phpbb_root_path	phpBB root path
30
	 */
31
	public function __construct(\blitze\sitemaker\services\filemanager $filemanager, $phpbb_root_path)
32
	{
33
		$this->filemanager = $filemanager;
34
		$this->phpbb_root_path = $phpbb_root_path;
35
	}
36
37
	/**
38
	 * @param string $file
39
	 * @return BinaryFileResponse
40
	 */
41
	public function handle($file)
42
	{
43
		$upload_path = $this->filemanager->get_upload_destination();
44
		$file = $this->phpbb_root_path . $upload_path . $file;
45
46
		if (!file_exists($file))
47
		{
48
			throw new http_exception(404, 'URL_NOT_FOUND');
49
		}
50
51
		return new BinaryFileResponse($file, 200);
52
	}
53
}
54