main_controller::handle()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 14
ccs 6
cts 6
cp 1
crap 4
rs 10
1
<?php
2
/**
3
 *
4
 * Collapsible Categories extension for the phpBB Forum Software package.
5
 *
6
 * @copyright (c) 2015 phpBB Limited <https://www.phpbb.com>
7
 * @license GNU General Public License, version 2 (GPL-2.0)
8
 *
9
 */
10
11
namespace phpbb\collapsiblecategories\controller;
12
13
use phpbb\collapsiblecategories\operator\operator;
14
use phpbb\request\request;
0 ignored issues
show
Bug introduced by
The type phpbb\request\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...
15
16
class main_controller implements main_interface
17
{
18
	/** @var operator */
19
	protected $operator;
20
21
	/** @var request */
22
	protected $request;
23
24
	/**
25
	 * Constructor
26
	 *
27
	 * @param operator $operator Operator object
28
	 * @param request  $request  Request object
29
	 */
30 11
	public function __construct(operator $operator, request $request)
31
	{
32 11
		$this->operator = $operator;
33 11
		$this->request = $request;
34 11
	}
35
36
	/**
37
	 * {@inheritdoc}
38
	 */
39 11
	public function handle($forum_id)
40
	{
41
		// Throw an exception for non-AJAX requests or invalid link requests
42 11
		if (!$this->request->is_ajax() || !$this->is_valid($forum_id) || !check_link_hash($this->request->variable('hash', ''), 'collapsible_' . $forum_id))
0 ignored issues
show
Bug introduced by
The function check_link_hash was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

42
		if (!$this->request->is_ajax() || !$this->is_valid($forum_id) || !/** @scrutinizer ignore-call */ check_link_hash($this->request->variable('hash', ''), 'collapsible_' . $forum_id))
Loading history...
43
		{
44 9
			throw new \phpbb\exception\http_exception(403, 'NO_AUTH_OPERATION');
0 ignored issues
show
Bug introduced by
The type phpbb\exception\http_exception 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...
45
		}
46
47
		// Update the user's collapsed category data for the given forum
48 2
		$response = $this->operator->set_user_categories($forum_id);
49
50
		// Return a JSON response
51 2
		return new \Symfony\Component\HttpFoundation\JsonResponse(array(
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpFoundation\JsonResponse 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...
52 2
			'success' => $response,
53
		));
54
	}
55
56
	/**
57
	 * Validate values containing only letters, numbers and underscores
58
	 *
59
	 * @param string $value Value to test
60
	 *
61
	 * @return bool true if valid, false if invalid
62
	 */
63 10
	protected function is_valid($value)
64
	{
65 10
		return !empty($value) && preg_match('/^\w+$/', $value);
66
	}
67
}
68