From 9fe6b010ec6f8fc7fd69018cd3644b699800eb8f Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Wed, 5 Apr 2017 23:09:16 +0300 Subject: [PATCH] fix obfuscator error --- .../Obfuscator/Node/Visitor/ScramblePrivateMethod.php | 6 ++++-- tests/before/SimpleClass.php | 3 +++ tests/expected/SimpleClass.php | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php b/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php index 3a00661..2435f45 100644 --- a/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php +++ b/src/Naneau/Obfuscator/Node/Visitor/ScramblePrivateMethod.php @@ -57,7 +57,9 @@ public function beforeTraverse(array $nodes) ->resetRenamed() ->skip($this->variableMethodCallsUsed($nodes)); - $this->scanMethodDefinitions($nodes); + if (!$this->shouldSkip()) { + $this->scanMethodDefinitions($nodes); + } return $nodes; } @@ -95,7 +97,7 @@ public function enterNode(Node $node) private function variableMethodCallsUsed(array $nodes) { foreach ($nodes as $node) { - if ($node instanceof MethodCall && $node->name instanceof Variable) { + if ($node instanceof MethodCall && $node->name instanceof Variable && $node->var->name === "this") { // A method call uses a Variable as its name return true; } diff --git a/tests/before/SimpleClass.php b/tests/before/SimpleClass.php index 8e6df75..b45d53f 100644 --- a/tests/before/SimpleClass.php +++ b/tests/before/SimpleClass.php @@ -37,6 +37,9 @@ public function publicMethod() { $this->publicProperty = $localVar; $this->_protectedMethod(); $this->_privateMethod(); + $dt = new \DateTime(); + $dtMethodName = "getTimestamp"; + $dt->$dtMethodName(); } } diff --git a/tests/expected/SimpleClass.php b/tests/expected/SimpleClass.php index 2ba8c4a..7c0a81a 100644 --- a/tests/expected/SimpleClass.php +++ b/tests/expected/SimpleClass.php @@ -1,2 +1,2 @@ sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; self::$publicStaticProperty = "test"; self::$protectedStaticProperty = "test"; self::$sp39db2b = "test"; } protected function _protectedMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod(); \ No newline at end of file +class SimpleClass { const CONSTANT_VARIABLE = "test"; public static $publicStaticProperty = "test"; protected static $protectedStaticProperty = "test"; private static $sp39db2b = "test"; private $sp8839d9; protected $_protectedProperty; public $publicProperty; private function sp51fa3f() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; self::$publicStaticProperty = "test"; self::$protectedStaticProperty = "test"; self::$sp39db2b = "test"; } protected function _protectedMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } public function publicMethod() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; $this->_protectedMethod(); $this->sp51fa3f(); $spce0ae5 = new \DateTime(); $sp167220 = "getTimestamp"; $spce0ae5->{$sp167220}(); } } $sp5de0e2 = new SimpleClass(); $sp5de0e2->publicMethod(); \ No newline at end of file