Completed
Push — magic-autoload-deprecations ( 6419e3 )
by Wim
01:42
created

DeprecatedMagicAutoloadSniff   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
B process() 0 24 3
1
<?php
2
/**
3
 * PHPCompatibility_Sniffs_PHP_DeprecatedMagicAutoloadSniff.
4
 *
5
 * PHP version 7.2
6
 *
7
 * @category  PHP
8
 * @package   PHPCompatibility
9
 * @author    Wim Godden <[email protected]
10
 */
11
12
/**
13
 * PHPCompatibility_Sniffs_PHP_DeprecatedMagicAutoloadSniff.
14
 *
15
 * @category  PHP
16
 * @package   PHPCompatibility
17
 * @author    Wim Godden <[email protected]
18
 */
19
class PHPCompatibility_Sniffs_PHP_DeprecatedMagicAutoloadSniff extends PHPCompatibility_Sniff
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
20
{
21
22
    public function register()
23
    {
24
        return array(T_FUNCTION);
25
26
    }//end register()
27
28
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
29
    {
30
        if ($this->supportsAbove('7.2') === false) {
31
            return;
32
        }
33
34
        $tokens = $phpcsFile->getTokens();
35
36
        $function = $tokens[$stackPtr];
37
        var_dump($function) . "\n";
0 ignored issues
show
Security Debugging Code introduced by
var_dump($function); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
38
        $funcName = $phpcsFile->getDeclarationName($stackPtr);
0 ignored issues
show
Unused Code introduced by
$funcName is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
39
        die('wtf');
0 ignored issues
show
Coding Style Compatibility introduced by
The method process() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
40
        echo $funcName . "\n";
0 ignored issues
show
Unused Code introduced by
echo $funcName . ' '; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
41
42
        if (strtolower($funcName) !== '__autoload') {
43
            return;
44
        }
45
46
        $phpcsFile->addWarning(
47
            'Use of __autoload() function is deprecated since PHP 7.2',
48
            $stackPtr,
49
            'Found'
50
        );
51
    }
52
}
53