diff --git a/lib/PhpParser/Node/Stmt/ClassMethod.php b/lib/PhpParser/Node/Stmt/ClassMethod.php index 7e44ad7..8bbc9e6 100644 --- a/lib/PhpParser/Node/Stmt/ClassMethod.php +++ b/lib/PhpParser/Node/Stmt/ClassMethod.php @@ -27,9 +27,15 @@ class ClassMethod extends Node\Stmt * @param array $attributes Additional attributes */ public function __construct($name, array $subNodes = array(), array $attributes = array()) { + $type = isset($subNodes['type']) ? $subNodes['type'] : 0; + if (0 === ($type & Class_::VISIBILITY_MODIFER_MASK)) { + // If no visibility modifier given, PHP defaults to public + $type |= Class_::MODIFIER_PUBLIC; + } + parent::__construct( array( - 'type' => isset($subNodes['type']) ? $subNodes['type'] : Class_::MODIFIER_PUBLIC, + 'type' => $type, 'byRef' => isset($subNodes['byRef']) ? $subNodes['byRef'] : false, 'name' => $name, 'params' => isset($subNodes['params']) ? $subNodes['params'] : array(), diff --git a/lib/PhpParser/Node/Stmt/Class_.php b/lib/PhpParser/Node/Stmt/Class_.php index 3ed3645..3d34a32 100644 --- a/lib/PhpParser/Node/Stmt/Class_.php +++ b/lib/PhpParser/Node/Stmt/Class_.php @@ -21,6 +21,8 @@ class Class_ extends Node\Stmt const MODIFIER_ABSTRACT = 16; const MODIFIER_FINAL = 32; + const VISIBILITY_MODIFER_MASK = 7; // 1 | 2 | 4 + protected static $specialNames = array( 'self' => true, 'parent' => true, @@ -87,7 +89,7 @@ class Class_ extends Node\Stmt * @internal */ public static function verifyModifier($a, $b) { - if ($a & 7 && $b & 7) { + if ($a & self::VISIBILITY_MODIFER_MASK && $b & self::VISIBILITY_MODIFER_MASK) { throw new Error('Multiple access type modifiers are not allowed'); } diff --git a/lib/PhpParser/Node/Stmt/Property.php b/lib/PhpParser/Node/Stmt/Property.php index c161126..d886d50 100644 --- a/lib/PhpParser/Node/Stmt/Property.php +++ b/lib/PhpParser/Node/Stmt/Property.php @@ -18,6 +18,11 @@ class Property extends Node\Stmt * @param array $attributes Additional attributes */ public function __construct($type, array $props, array $attributes = array()) { + if (0 === ($type & Class_::VISIBILITY_MODIFER_MASK)) { + // If no visibility modifier given, PHP defaults to public + $type |= Class_::MODIFIER_PUBLIC; + } + parent::__construct( array( 'type' => $type, @@ -42,4 +47,4 @@ class Property extends Node\Stmt public function isStatic() { return (bool) ($this->type & Class_::MODIFIER_STATIC); } -} \ No newline at end of file +} diff --git a/test/PhpParser/Node/Stmt/ClassMethodTest.php b/test/PhpParser/Node/Stmt/ClassMethodTest.php index a750fc8..cbc168a 100644 --- a/test/PhpParser/Node/Stmt/ClassMethodTest.php +++ b/test/PhpParser/Node/Stmt/ClassMethodTest.php @@ -15,13 +15,15 @@ class ClassMethodTest extends \PHPUnit_Framework_TestCase $this->assertTrue($node->{'is' . $modifier}()); } - /** - * @dataProvider provideModifiers - */ - public function testNoModifiers($modifier) { + public function testNoModifiers() { $node = new ClassMethod('foo', array('type' => 0)); - $this->assertFalse($node->{'is' . $modifier}()); + $this->assertTrue($node->isPublic()); + $this->assertFalse($node->isProtected()); + $this->assertFalse($node->isPrivate()); + $this->assertFalse($node->isAbstract()); + $this->assertFalse($node->isFinal()); + $this->assertFalse($node->isStatic()); } public function provideModifiers() { @@ -34,4 +36,4 @@ class ClassMethodTest extends \PHPUnit_Framework_TestCase array('static'), ); } -} \ No newline at end of file +} diff --git a/test/PhpParser/Node/Stmt/PropertyTest.php b/test/PhpParser/Node/Stmt/PropertyTest.php index 57fb7af..a7efcd3 100644 --- a/test/PhpParser/Node/Stmt/PropertyTest.php +++ b/test/PhpParser/Node/Stmt/PropertyTest.php @@ -16,13 +16,13 @@ class PropertyTest extends \PHPUnit_Framework_TestCase $this->assertTrue($node->{'is' . $modifier}()); } - /** - * @dataProvider provideModifiers - */ - public function testNoModifiers($modifier) { + public function testNoModifiers() { $node = new Property(0, array()); - $this->assertFalse($node->{'is' . $modifier}()); + $this->assertTrue($node->isPublic()); + $this->assertFalse($node->isProtected()); + $this->assertFalse($node->isPrivate()); + $this->assertFalse($node->isStatic()); } public function provideModifiers() { @@ -33,4 +33,4 @@ class PropertyTest extends \PHPUnit_Framework_TestCase array('static'), ); } -} \ No newline at end of file +} diff --git a/test/code/parser/stmt/class/implicitPublic.test b/test/code/parser/stmt/class/implicitPublic.test new file mode 100644 index 0000000..70a90d2 --- /dev/null +++ b/test/code/parser/stmt/class/implicitPublic.test @@ -0,0 +1,77 @@ +Implicitly public properties and methods +----- +