GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ScramblePrivateProperty::scanPropertyDefinitions()   C
last analyzed

Complexity

Conditions 7
Paths 5

Size

Total Lines 23
Code Lines 9

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 23
loc 23
rs 6.7272
cc 7
eloc 9
nc 5
nop 1
1
<?php
2
/**
3
 * ScramblePrivateProperty.php
4
 *
5
 * @category        Naneau
6
 * @package         Obfuscator
7
 * @subpackage      NodeVisitor
8
 */
9
10
namespace Naneau\Obfuscator\Node\Visitor;
11
12
use Naneau\Obfuscator\Node\Visitor\TrackingRenamerTrait;
13
use Naneau\Obfuscator\Node\Visitor\SkipTrait;
14
15
use Naneau\Obfuscator\Node\Visitor\Scrambler as ScramblerVisitor;
16
use Naneau\Obfuscator\StringScrambler;
17
18
use PhpParser\Node;
19
20
use PhpParser\Node\Stmt\Class_ as ClassNode;
21
use PhpParser\Node\Stmt\Property;
22
23
use PhpParser\Node\Expr\PropertyFetch;
24
25
use PhpParser\Node\Expr\Variable;
26
27
/**
28
 * ScramblePrivateProperty
29
 *
30
 * Renames private properties
31
 *
32
 * WARNING
33
 *
34
 * See warning for private method scrambler
35
 *
36
 * @category        Naneau
37
 * @package         Obfuscator
38
 * @subpackage      NodeVisitor
39
 */
40
class ScramblePrivateProperty extends ScramblerVisitor
41
{
42
    use TrackingRenamerTrait;
43
    use SkipTrait;
44
45
    /**
46
     * Constructor
47
     *
48
     * @param  StringScrambler $scrambler
49
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
50
     **/
51
    public function __construct(StringScrambler $scrambler)
52
    {
53
        parent::__construct($scrambler);
54
    }
55
56
    /**
57
     * Before node traversal
58
     *
59
     * @param  Node[] $nodes
60
     * @return array
61
     **/
62
    public function beforeTraverse(array $nodes)
63
    {
64
        $this
65
            ->resetRenamed()
66
            ->scanPropertyDefinitions($nodes);
67
68
        return $nodes;
69
    }
70
71
    /**
72
     * Check all variable nodes
73
     *
74
     * @param  Node $node
75
     * @return void
76
     **/
77
    public function enterNode(Node $node)
78
    {
79
        if ($node instanceof PropertyFetch) {
80
81
            if (!is_string($node->name)) {
82
                return;
83
            }
84
85
            if ($this->isRenamed($node->name)) {
86
                $node->name = $this->getNewName($node->name);
87
                return $node;
88
            }
89
        }
90
    }
91
92
    /**
93
     * Recursively scan for private method definitions and rename them
94
     *
95
     * @param  Node[] $nodes
96
     * @return void
97
     **/
98 View Code Duplication
    private function scanPropertyDefinitions(array $nodes)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
99
    {
100
        foreach ($nodes as $node) {
101
            // Scramble the private method definitions
102
            if ($node instanceof Property && ($node->type & ClassNode::MODIFIER_PRIVATE)) {
103
                foreach($node->props as $property) {
104
105
                    // Record original name and scramble it
106
                    $originalName = $property->name;
107
                    $this->scramble($property);
108
109
                    // Record renaming
110
                    $this->renamed($originalName, $property->name);
111
                }
112
113
            }
114
115
            // Recurse over child nodes
116
            if (isset($node->stmts) && is_array($node->stmts)) {
0 ignored issues
show
Bug introduced by
Accessing stmts on the interface PhpParser\Node suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
117
                $this->scanPropertyDefinitions($node->stmts);
0 ignored issues
show
Bug introduced by
Accessing stmts on the interface PhpParser\Node suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
118
            }
119
        }
120
    }
121
}
122