Passed
Push — navbar ( b4d43e )
by Daniel
20:10
created

navbar::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 7
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 *
4
 * @package sitemaker
5
 * @copyright (c) 2020 Daniel A. (blitze)
6
 * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
 *
8
 */
9
10
namespace blitze\sitemaker\controller;
11
12
use Symfony\Component\HttpFoundation\Response;
13
14
class navbar
15
{
16
	/** @var \phpbb\auth\auth */
17
	protected $auth;
18
19
	/** @var \phpbb\config\config */
20
	protected $config;
21
22
	/** @var \phpbb\config\db_text */
23
	protected $config_text;
24
25
	/** @var \phpbb\request\request_interface */
26
	protected $request;
27
28
	/* @var symfony_request */
0 ignored issues
show
Bug introduced by
The type blitze\sitemaker\controller\symfony_request 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...
29
	protected $symfony_request;
30
31
	/** @var \phpbb\language\language */
32
	protected $translator;
33
34
	/** @var \phpbb\user */
35
	protected $user;
36
37
	/**
38
	 * Constructor
39
	 *
40
	 * @param \phpbb\auth\auth							$auth					Auth object
41
	 * @param \phpbb\config\config						$config					Config object
42
	 * @param \phpbb\config\db_text						$config_text			Config text object
43
	 * @param \phpbb\request\request_interface			$request				Request object
44
	 * @param \phpbb\symfony_request					$symfony_request		Symfony Request object
45
	 * @param \phpbb\language\language					$translator				Language object
46
	 * @param \phpbb\user								$user					User object
47
	 */
48
	public function __construct(\phpbb\auth\auth $auth, \phpbb\config\config $config, \phpbb\config\db_text $config_text, \phpbb\request\request_interface $request, \phpbb\symfony_request $symfony_request, \phpbb\language\language $translator, \phpbb\user $user)
49
	{
50
		$this->auth = $auth;
51
		$this->config = $config;
52
		$this->config_text = $config_text;
53
		$this->request = $request;
54
		$this->symfony_request = $symfony_request;
0 ignored issues
show
Documentation Bug introduced by
It seems like $symfony_request of type phpbb\symfony_request is incompatible with the declared type blitze\sitemaker\controller\symfony_request of property $symfony_request.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
55
		$this->translator = $translator;
56
		$this->user = $user;
57
	}
58
59
	/**
60
	 * @return \Symfony\Component\HttpFoundation\Response
61
	 */
62
	public function css($style)
63
	{
64
		$css = html_entity_decode($this->config_text->get('sitemaker_navbar_' . $style));
65
66
		$response = new Response($css);
67
		$response->headers->set('Content-Type', 'text/css');
68
69
		$response->setPublic();
70
		$response->setSharedMaxAge(3600);
71
		$response->setETag(md5($response->getContent()));
72
		$response->setLastModified(new \DateTime($this->config['sitemaker_nav_last_modified']));
73
74
		if ($response->isNotModified($this->symfony_request))
75
		{
76
			return $response;
77
		};
78
79
		return $response;
80
	}
81
82
	/**
83
	 * @return \Symfony\Component\HttpFoundation\Response
84
	 */
85
	public function save($style)
86
	{
87
		$data = array('message' => '');
88
89
		if (!$this->request->is_ajax() || !$this->auth->acl_get('a_sm_manage_blocks'))
90
		{
91
			$data['message'] = $this->translator->lang('NOT_AUTHORISED');
92
			$status = 401;
93
		}
94
		else
95
		{
96
			$css = $this->request->variable('css', '');
97
			$location = $this->request->variable('location', '');
98
99
			$locations = (array) json_decode($this->config['sitemaker_nav_locations'], true);
100
101
			$this->config_text->set('sitemaker_navbar_' . $style, $css);
102
103
			$this->config->set('sitemaker_nav_last_modified', new \phpbb\datetime($this->user));
104
			$this->config->set('sitemaker_nav_locations', json_encode(array_filter(array_merge($locations, [$style => $location]))));
105
106
			$data['message'] = '';
107
			$data['location'] = $locations[$style] ?? '';
108
			$status = 200;
109
		}
110
111
		$response = new Response(json_encode($data), $status);
112
		$response->headers->set('Content-Type', 'application/json');
113
114
        return $response;
115
	}
116
}
117