Superglobals   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
ccs 0
cts 14
cp 0
wmc 3
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 14 3
1
<?php
2
/**
3
 * This file is part of PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
namespace PHPMD\Rule\Controversial;
19
20
use PHPMD\AbstractNode;
21
use PHPMD\AbstractRule;
22
use PHPMD\Rule\FunctionAware;
23
use PHPMD\Rule\MethodAware;
24
25
/**
26
 * This rule class detects the usage of superglobals.
27
 *
28
 * @author     Francis Besset <[email protected]>
29
 * @since      1.1.0
30
 */
31
class Superglobals extends AbstractRule implements MethodAware, FunctionAware
32
{
33
    protected $superglobals = array(
34
        '$GLOBALS',
35
        '$_SERVER',  '$HTTP_SERVER_VARS',
36
        '$_GET',     '$HTTP_GET_VARS',
37
        '$_POST',    '$HTTP_POST_VARS',
38
        '$_FILES',   '$HTTP_POST_FILES',
39
        '$_COOKIE',  '$HTTP_COOKIE_VARS',
40
        '$_SESSION', '$HTTP_SESSION_VARS',
41
        '$_REQUEST',
42
        '$_ENV',     '$HTTP_ENV_VARS',
43
    );
44
45
    /**
46
     * This method checks if a superglobal is used
47
     * and emits a rule violation.
48
     *
49
     * @param \PHPMD\AbstractNode $node
50
     * @return void
51
     */
52
    public function apply(AbstractNode $node)
53
    {
54
        foreach ($node->findChildrenOfType('Variable') as $variable) {
55
            if (in_array($variable->getImage(), $this->superglobals)) {
56
                $this->addViolation(
57
                    $node,
58
                    array(
59
                        $node->getName(),
60
                        $variable->getImage()
61
                    )
62
                );
63
            }
64
        }
65
    }
66
}
67