-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathRestrictedVariablesSniff.php
More file actions
68 lines (63 loc) · 1.85 KB
/
RestrictedVariablesSniff.php
File metadata and controls
68 lines (63 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
/**
* WordPressVIPMinimum Coding Standard.
*
* @package VIPCS\WordPressVIPMinimum
* @link https://github.com/Automattic/VIP-Coding-Standards
* @license https://opensource.org/license/gpl-2-0 GPL-2.0
* @license https://opensource.org/licenses/MIT MIT
*/
namespace WordPressVIPMinimum\Sniffs\Variables;
use WordPressVIPMinimum\Sniffs\AbstractVariableRestrictionsSniff;
/**
* Restricts usage of some variables in VIP context.
*
* @since 0.5.0
*/
class RestrictedVariablesSniff extends AbstractVariableRestrictionsSniff {
/**
* Groups of variables to restrict.
*
* Example: groups => array(
* 'wpdb' => array(
* 'type' => 'error' | 'warning',
* 'message' => 'Dont use this one please!',
* 'variables' => array( '$val', '$var' ),
* 'object_vars' => array( '$foo->bar', .. ),
* 'array_members' => array( '$foo['bar']', .. ),
* )
* )
*
* @return array<string, array<string, string|array<string>>>
*/
public function getGroups() {
return [
'user_meta' => [
'type' => 'error',
'message' => 'Usage of users tables is highly discouraged in VIP context',
'object_vars' => [
'$wpdb->users',
],
],
'session' => [
'type' => 'error',
'message' => 'Usage of $_SESSION variable is prohibited.',
'variables' => [
'$_SESSION',
],
],
// @link https://docs.wpvip.com/technical-references/code-review/vip-errors/#h-cache-constraints
'cache_constraints' => [
'type' => 'warning',
'message' => 'Due to server-side caching, server-side based client related logic might not work. We recommend implementing client side logic in JavaScript instead.',
'variables' => [
'$_COOKIE',
],
'array_members' => [
'$_SERVER[\'HTTP_USER_AGENT\']',
'$_SERVER[\'REMOTE_ADDR\']',
],
],
];
}
}