route.php ➔ getRequestParams()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 13 and the first side effect is on line 9.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
use Bitrix\Main\Loader;
4
use DigitalWand\AdminHelper\Helper\AdminBaseHelper;
5
use DigitalWand\AdminHelper\Helper\AdminListHelper;
6
use DigitalWand\AdminHelper\Helper\AdminEditHelper;
7
use DigitalWand\AdminHelper\Helper\AdminInterface;
8
9
require_once($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_admin_before.php');
10
11
Loader::includeModule('digitalwand.admin_helper');
12
13
function getRequestParams($param)
0 ignored issues
show
Coding Style introduced by
getRequestParams uses the super-global variable $_REQUEST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
14
{
15
	if (!isset($_REQUEST[$param])) {
16
		return false;
17
	}
18
	else {
19
		return htmlspecialcharsbx($_REQUEST[$param]);
20
	}
21
}
22
23
/**
24
 * Очищаем переменные сессии, чтобы сортировка восстанавливалась с учетом $table_id.
25
 *
26
 * @global CMain $APPLICATION
27
 */
28
global $APPLICATION;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
29
$uniq = md5($APPLICATION->GetCurPage());
30
31
if (isset($_SESSION["SESS_SORT_BY"][$uniq])) {
32
	unset($_SESSION["SESS_SORT_BY"][$uniq]);
33
}
34
if (isset($_SESSION["SESS_SORT_ORDER"][$uniq])) {
35
	unset($_SESSION["SESS_SORT_ORDER"][$uniq]);
36
}
37
38
$module = getRequestParams('module');
39
$view = getRequestParams('view');
40
$entity = getRequestParams('entity');
41
42
if (!$module OR !$view OR !Loader::IncludeModule($module)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
43
	include $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/admin/404.php';
44
}
45
46
// Собираем имя класса админского интерфейса
47
$moduleNameParts = explode('.', $module);
48
$entityNameParts = explode('_', $entity);
49
$interfaceNameParts = array_merge($moduleNameParts, $entityNameParts);
50
$interfaceNameClass = null;
51
$viewParts = explode('_', $view);
52
53
$count = count($viewParts);
54
for ($i = 0; $i < $count; $i++) {
55
	$interfaceName = implode('', array_map('ucfirst', $viewParts));
56
	$parts = $interfaceNameParts;
57
	$parts[] = $interfaceName . 'AdminInterface';
58
	$class = array_map('ucfirst', $parts);
59
	$interfaceNameClass = implode('\\', $class);
60
61
	if (class_exists($interfaceNameClass)) {
62
		break;
63
	}
64
	else {
65
		$className = array_pop($parts);
66
		$parts[] = 'AdminInterface';
67
		$parts[] = $className;
68
		$class = array_map('ucfirst', $parts);
69
		$interfaceNameClass = implode('\\', $class);
70
		if (class_exists($interfaceNameClass)) {
71
			break;
72
		}
73
	}
74
	array_pop($viewParts);
75
}
76
77
/**
78
 * @var AdminInterface $interfaceNameClass
79
 */
80
81
if ($interfaceNameClass && class_exists($interfaceNameClass)) {
82
	$interfaceNameClass::register();
83
}
84
85
list($helper, $interface) = AdminBaseHelper::getGlobalInterfaceSettings($module, $view);
0 ignored issues
show
Security Bug introduced by
It seems like $module can also be of type false; however, DigitalWand\AdminHelper\...obalInterfaceSettings() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
Security Bug introduced by
It seems like $view can also be of type false; however, DigitalWand\AdminHelper\...obalInterfaceSettings() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
86
87
if (!$helper OR !$interface) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as or instead of || is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
88
	include $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/admin/404.php';
89
}
90
91
$isPopup = isset($_REQUEST['popup']) AND $_REQUEST['popup'] == 'Y';
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
92
$fields = isset($interface['FIELDS']) ? $interface['FIELDS'] : array();
93
$tabs = isset($interface['TABS']) ? $interface['TABS'] : array();
94
$helperType = false;
95
96
if (is_subclass_of($helper, 'DigitalWand\AdminHelper\Helper\AdminEditHelper')) {
97
	$helperType = 'edit';
98
	/**
99
	 * @var AdminEditHelper $adminHelper
100
	 */
101
	$adminHelper = new $helper($fields, $tabs);
102
}
103
elseif (is_subclass_of($helper, 'DigitalWand\AdminHelper\Helper\AdminListHelper')) {
104
	$helperType = 'list';
105
	/**
106
	 * @var AdminListHelper $adminHelper
107
	 */
108
	$adminHelper = new $helper($fields, $isPopup);
109
	$adminHelper->buildList(array($by => $order));
110
}
111
elseif (is_subclass_of($helper, 'DigitalWand\AdminHelper\Helper\AdminBaseHelper')) {
112
	$adminHelper = new $helper($fields, $tabs);
113
}
114
else {
115
	include $_SERVER['DOCUMENT_ROOT'] . BX_ROOT . '/admin/404.php';
116
	exit();
117
}
118
119
if ($isPopup) {
120
	require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_popup_admin.php");
121
}
122
else {
123
	require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_admin_after.php");
124
}
125
126
if ($helperType == 'list') {
127
	$adminHelper->createFilterForm();
128
}
129
130
$adminHelper->show();
131
132
if ($isPopup) {
133
	require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_popup_admin.php");
134
}
135
else {
136
	require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/epilog_admin.php");
137
}
138