From 5e6627c895e14d0655972af6878697bd97d37930 Mon Sep 17 00:00:00 2001 From: Lisachenko Alexander Date: Sun, 5 Jul 2015 20:01:51 +0300 Subject: [PATCH 1/3] Add broken test for implicit public nodes --- test/PhpParser/Node/Stmt/ClassMethodTest.php | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/PhpParser/Node/Stmt/ClassMethodTest.php b/test/PhpParser/Node/Stmt/ClassMethodTest.php index cbc168a..fa8aed8 100644 --- a/test/PhpParser/Node/Stmt/ClassMethodTest.php +++ b/test/PhpParser/Node/Stmt/ClassMethodTest.php @@ -36,4 +36,28 @@ class ClassMethodTest extends \PHPUnit_Framework_TestCase array('static'), ); } + + /** + * Checks that implicit public modifier detection for method is working + * + * @dataProvider implicitPublicModifiers + * + * @param integer $modifier Node type modifier + */ + public function testImplicitPublic($modifier) + { + $node = new ClassMethod('foo', array( + 'type' => constant('PhpParser\Node\Stmt\Class_::MODIFIER_' . strtoupper($modifier)) + )); + + $this->assertTrue($node->isPublic(), 'Node should be implicitly public'); + } + + public function implicitPublicModifiers() { + return array( + array('abstract'), + array('final'), + array('static'), + ); + } } From 0fbb5f90a1302989c3a4575c860202d4a3a6174c Mon Sep 17 00:00:00 2001 From: Lisachenko Alexander Date: Sun, 5 Jul 2015 20:02:43 +0300 Subject: [PATCH 2/3] Fix public modifier check for ClassMethod node --- lib/PhpParser/Node/Stmt/ClassMethod.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/PhpParser/Node/Stmt/ClassMethod.php b/lib/PhpParser/Node/Stmt/ClassMethod.php index 762e9b1..41f099d 100644 --- a/lib/PhpParser/Node/Stmt/ClassMethod.php +++ b/lib/PhpParser/Node/Stmt/ClassMethod.php @@ -75,7 +75,7 @@ class ClassMethod extends Node\Stmt implements FunctionLike } public function isPublic() { - return ($this->type & Class_::MODIFIER_PUBLIC) !== 0 || $this->type === 0; + return ($this->type & Class_::MODIFIER_PUBLIC) !== 0 || (!$this->isPrivate() && !$this->isProtected()); } public function isProtected() { From 7434a682e5b52540235cda338ed8f96c7cf53453 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Sun, 5 Jul 2015 20:15:02 +0200 Subject: [PATCH 3/3] Fix implicit visibility for properties as well Also switch to using PPP mask. --- lib/PhpParser/Node/Stmt/ClassMethod.php | 3 ++- lib/PhpParser/Node/Stmt/Property.php | 3 ++- test/PhpParser/Node/Stmt/PropertyTest.php | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/PhpParser/Node/Stmt/ClassMethod.php b/lib/PhpParser/Node/Stmt/ClassMethod.php index 41f099d..c1bd577 100644 --- a/lib/PhpParser/Node/Stmt/ClassMethod.php +++ b/lib/PhpParser/Node/Stmt/ClassMethod.php @@ -75,7 +75,8 @@ class ClassMethod extends Node\Stmt implements FunctionLike } public function isPublic() { - return ($this->type & Class_::MODIFIER_PUBLIC) !== 0 || (!$this->isPrivate() && !$this->isProtected()); + return ($this->type & Class_::MODIFIER_PUBLIC) !== 0 + || ($this->type & Class_::VISIBILITY_MODIFER_MASK) === 0; } public function isProtected() { diff --git a/lib/PhpParser/Node/Stmt/Property.php b/lib/PhpParser/Node/Stmt/Property.php index 295f369..58052f7 100644 --- a/lib/PhpParser/Node/Stmt/Property.php +++ b/lib/PhpParser/Node/Stmt/Property.php @@ -38,7 +38,8 @@ class Property extends Node\Stmt } public function isPublic() { - return ($this->type & Class_::MODIFIER_PUBLIC) !== 0 || $this->type === 0; + return ($this->type & Class_::MODIFIER_PUBLIC) !== 0 + || ($this->type & Class_::VISIBILITY_MODIFER_MASK) === 0; } public function isProtected() { diff --git a/test/PhpParser/Node/Stmt/PropertyTest.php b/test/PhpParser/Node/Stmt/PropertyTest.php index a7efcd3..bcfc0c6 100644 --- a/test/PhpParser/Node/Stmt/PropertyTest.php +++ b/test/PhpParser/Node/Stmt/PropertyTest.php @@ -25,6 +25,14 @@ class PropertyTest extends \PHPUnit_Framework_TestCase $this->assertFalse($node->isStatic()); } + public function testStaticImplicitlyPublic() { + $node = new Property(Class_::MODIFIER_STATIC, array()); + $this->assertTrue($node->isPublic()); + $this->assertFalse($node->isProtected()); + $this->assertFalse($node->isPrivate()); + $this->assertTrue($node->isStatic()); + } + public function provideModifiers() { return array( array('public'),