From d23a99ac71bcbc0b44bd9256862b18ad73e374c4 Mon Sep 17 00:00:00 2001 From: Vyacheslav Gulyam Date: Tue, 4 Apr 2017 20:39:38 +0300 Subject: [PATCH] added php7 support --- composer.json | 2 +- src/Naneau/Obfuscator/Resources/services.yml | 2 +- tests/before/Functions.php | 7 ++++++- tests/expected/Functions.php | 2 +- tests/expected/MultipleClasses.php | 2 +- tests/expected/SimpleClass.php | 2 +- 6 files changed, 11 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 4efdca6..6c6753b 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ ], "require": { - "nikic/php-parser": "~1@dev", + "nikic/php-parser": "~3@dev", "symfony/console": "~2.5", "symfony/dependency-injection": "~2.5", "symfony/config": "~2.5", diff --git a/src/Naneau/Obfuscator/Resources/services.yml b/src/Naneau/Obfuscator/Resources/services.yml index bb036e9..8d0b86a 100644 --- a/src/Naneau/Obfuscator/Resources/services.yml +++ b/src/Naneau/Obfuscator/Resources/services.yml @@ -70,7 +70,7 @@ services: # Parser obfuscator.parser: - class: PhpParser\Parser + class: PhpParser\Parser\Php7 arguments: - @obfuscator.lexer diff --git a/tests/before/Functions.php b/tests/before/Functions.php index 9d71efe..5dd10f1 100644 --- a/tests/before/Functions.php +++ b/tests/before/Functions.php @@ -11,6 +11,11 @@ function functionB() { return functionB($localVarB); } +function functionC(?int $a): ?string { + return $a === null ? null : "Output: " . $a; +} + $localVarMainA = "local value"; $localVarMainB = functionB(); -$localVarMainA = functionA($localVarMainA); \ No newline at end of file +$localVarMainA = functionA($localVarMainA); +functionC(); \ No newline at end of file diff --git a/tests/expected/Functions.php b/tests/expected/Functions.php index 638da32..17f923e 100644 --- a/tests/expected/Functions.php +++ b/tests/expected/Functions.php @@ -1,2 +1,2 @@ sp8839d9 = parent::$_protectedProperty; } public function publicMethod() { parent::publicMethod(); echo 'This is public method of second class'; $this->sp8839d9 = parent::$publicProperty; } public static function anotherPublicMethod() { } } class ThirdClass { private $spa36ab6; private static function spe81a11() { } public function __construct(SecondClass $spb91639) { $spb91639->publicMethod(); $spb91639::anotherPublicMethod(); $spb91639->publicProperty = 'test'; } private function sp70ab23() { echo 'test'; } protected function someFunc() { $this->spa36ab6 = 'test'; $this->sp70ab23(); self::spe81a11(); } } \ No newline at end of file +class FirstClass { protected $_protectedProperty; public $publicProperty; protected function _protectedMethod() { echo "This is protected method of first class"; } public function publicMethod() { echo "This is public method of first class"; } } class SecondClass extends FirstClass { private $sp8839d9; protected function _protectedMethod() { parent::_protectedMethod(); echo "This is protected method of second class"; $this->sp8839d9 = parent::$_protectedProperty; } public function publicMethod() { parent::publicMethod(); echo "This is public method of second class"; $this->sp8839d9 = parent::$publicProperty; } public static function anotherPublicMethod() { } } class ThirdClass { private $spa36ab6; private static function spe81a11() { } public function __construct(SecondClass $spb91639) { $spb91639->publicMethod(); $spb91639::anotherPublicMethod(); $spb91639->publicProperty = 'test'; } private function sp70ab23() { echo 'test'; } protected function someFunc() { $this->spa36ab6 = 'test'; $this->sp70ab23(); self::spe81a11(); } } \ No newline at end of file diff --git a/tests/expected/SimpleClass.php b/tests/expected/SimpleClass.php index c7b8a8b..104ccd5 100644 --- a/tests/expected/SimpleClass.php +++ b/tests/expected/SimpleClass.php @@ -1,2 +1,2 @@ sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } 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"; static $staticProperty = "test"; private $sp8839d9; protected $_protectedProperty; public $publicProperty; private function sp51fa3f() { $spd8dce8 = "test"; $this->sp8839d9 = $spd8dce8; $this->_protectedProperty = $spd8dce8; $this->publicProperty = $spd8dce8; } 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