mirror of
https://github.com/danog/PHP-Parser.git
synced 2025-01-20 12:46:47 +01:00
parent
a8ffc6fcfc
commit
0f69f12b94
@ -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(),
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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() {
|
||||
|
@ -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() {
|
||||
|
77
test/code/parser/stmt/class/implicitPublic.test
Normal file
77
test/code/parser/stmt/class/implicitPublic.test
Normal file
@ -0,0 +1,77 @@
|
||||
Implicitly public properties and methods
|
||||
-----
|
||||
<?php
|
||||
|
||||
abstract class A {
|
||||
var $a;
|
||||
static $b;
|
||||
abstract function c();
|
||||
final function d() {}
|
||||
static function e() {}
|
||||
final static function f() {}
|
||||
}
|
||||
-----
|
||||
array(
|
||||
0: Stmt_Class(
|
||||
type: 16
|
||||
name: A
|
||||
extends: null
|
||||
implements: array(
|
||||
)
|
||||
stmts: array(
|
||||
0: Stmt_Property(
|
||||
type: 1
|
||||
props: array(
|
||||
0: Stmt_PropertyProperty(
|
||||
name: a
|
||||
default: null
|
||||
)
|
||||
)
|
||||
)
|
||||
1: Stmt_Property(
|
||||
type: 9
|
||||
props: array(
|
||||
0: Stmt_PropertyProperty(
|
||||
name: b
|
||||
default: null
|
||||
)
|
||||
)
|
||||
)
|
||||
2: Stmt_ClassMethod(
|
||||
type: 17
|
||||
byRef: false
|
||||
name: c
|
||||
params: array(
|
||||
)
|
||||
stmts: null
|
||||
)
|
||||
3: Stmt_ClassMethod(
|
||||
type: 33
|
||||
byRef: false
|
||||
name: d
|
||||
params: array(
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
4: Stmt_ClassMethod(
|
||||
type: 9
|
||||
byRef: false
|
||||
name: e
|
||||
params: array(
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
5: Stmt_ClassMethod(
|
||||
type: 41
|
||||
byRef: false
|
||||
name: f
|
||||
params: array(
|
||||
)
|
||||
stmts: array(
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
Loading…
x
Reference in New Issue
Block a user