mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-12-13 09:37:21 +01:00
dce19b074b
Were this library to be fully annotated with scalar types and return types where possible and were strict types to be enabled for all files, the test suite would now pass.
50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace PhpParser\Node\Stmt;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\Error;
|
|
|
|
class Namespace_ extends Node\Stmt
|
|
{
|
|
/** @var null|Node\Name Name */
|
|
public $name;
|
|
/** @var Node[] Statements */
|
|
public $stmts;
|
|
|
|
protected static $specialNames = array(
|
|
'self' => true,
|
|
'parent' => true,
|
|
'static' => true,
|
|
);
|
|
|
|
/**
|
|
* Constructs a namespace node.
|
|
*
|
|
* @param null|Node\Name $name Name
|
|
* @param null|Node[] $stmts Statements
|
|
* @param array $attributes Additional attributes
|
|
*/
|
|
public function __construct(Node\Name $name = null, $stmts = array(), array $attributes = array()) {
|
|
parent::__construct(null, $attributes);
|
|
$this->name = $name;
|
|
$this->stmts = $stmts;
|
|
|
|
if (isset(self::$specialNames[(string) $this->name])) {
|
|
throw new Error(sprintf('Cannot use \'%s\' as namespace name', $this->name));
|
|
}
|
|
|
|
if (null !== $this->stmts) {
|
|
foreach ($this->stmts as $stmt) {
|
|
if ($stmt instanceof self) {
|
|
throw new Error('Namespace declarations cannot be nested', $stmt->getLine());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getSubNodeNames() {
|
|
return array('name', 'stmts');
|
|
}
|
|
}
|