Skip to content

Commit

Permalink
Generate PHP 7 type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Apr 28, 2017
1 parent e5fbdd6 commit a32e379
Show file tree
Hide file tree
Showing 145 changed files with 326 additions and 326 deletions.
4 changes: 2 additions & 2 deletions lib/PhpParser/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Autoloader
*
* @param bool $prepend Whether to prepend the autoloader instead of appending
*/
static public function register($prepend = false) {
static public function register(bool $prepend = false) {
if (self::$registered === true) {
return;
}
Expand All @@ -29,7 +29,7 @@ static public function register($prepend = false) {
*
* @param string $class A class name.
*/
static public function autoload($class) {
static public function autoload(string $class) {
if (0 === strpos($class, 'PhpParser\\')) {
$fileName = __DIR__ . strtr(substr($class, 9), '\\', '/') . '.php';
if (file_exists($fileName)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ interface Builder
*
* @return Node The built node
*/
public function getNode();
public function getNode() : Node;
}
4 changes: 2 additions & 2 deletions lib/PhpParser/Builder/Class_.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Class_ extends Declaration
*
* @param string $name Name of the class
*/
public function __construct($name) {
public function __construct(string $name) {
$this->name = $name;
}

Expand Down Expand Up @@ -111,7 +111,7 @@ public function addStmt($stmt) {
*
* @return Stmt\Class_ The built class node
*/
public function getNode() {
public function getNode() : PhpParser\Node {
return new Stmt\Class_($this->name, array(
'flags' => $this->flags,
'extends' => $this->extends,
Expand Down
4 changes: 2 additions & 2 deletions lib/PhpParser/Builder/Function_.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Function_ extends FunctionLike
*
* @param string $name Name of the function
*/
public function __construct($name) {
public function __construct(string $name) {
$this->name = $name;
}

Expand All @@ -39,7 +39,7 @@ public function addStmt($stmt) {
*
* @return Stmt\Function_ The built function node
*/
public function getNode() {
public function getNode() : Node {
return new Stmt\Function_($this->name, array(
'byRef' => $this->returnByRef,
'params' => $this->params,
Expand Down
4 changes: 2 additions & 2 deletions lib/PhpParser/Builder/Interface_.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Interface_ extends Declaration
*
* @param string $name Name of the interface
*/
public function __construct($name) {
public function __construct(string $name) {
$this->name = $name;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ public function addStmt($stmt) {
*
* @return Stmt\Interface_ The built interface node
*/
public function getNode() {
public function getNode() : PhpParser\Node {
return new Stmt\Interface_($this->name, array(
'extends' => $this->extends,
'stmts' => array_merge($this->constants, $this->methods),
Expand Down
4 changes: 2 additions & 2 deletions lib/PhpParser/Builder/Method.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Method extends FunctionLike
*
* @param string $name Name of the method
*/
public function __construct($name) {
public function __construct(string $name) {
$this->name = $name;
}

Expand Down Expand Up @@ -117,7 +117,7 @@ public function addStmt($stmt) {
*
* @return Stmt\ClassMethod The built method node
*/
public function getNode() {
public function getNode() : Node {
return new Stmt\ClassMethod($this->name, array(
'flags' => $this->flags,
'byRef' => $this->returnByRef,
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Builder/Namespace_.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function addStmts(array $stmts) {
*
* @return Node The built node
*/
public function getNode() {
public function getNode() : Node {
return new Stmt\Namespace_($this->name, $this->stmts);
}
}
4 changes: 2 additions & 2 deletions lib/PhpParser/Builder/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Param implements PhpParser\Builder
*
* @param string $name Name of the parameter
*/
public function __construct($name) {
public function __construct(string $name) {
$this->name = $name;
}

Expand Down Expand Up @@ -84,7 +84,7 @@ public function makeVariadic() {
*
* @return Node\Param The built parameter node
*/
public function getNode() {
public function getNode() : Node {
return new Node\Param(
new Node\Expr\Variable($this->name),
$this->default, $this->type, $this->byRef, $this->variadic
Expand Down
4 changes: 2 additions & 2 deletions lib/PhpParser/Builder/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Property implements PhpParser\Builder
*
* @param string $name Name of the property
*/
public function __construct($name) {
public function __construct(string $name) {
$this->name = $name;
}

Expand Down Expand Up @@ -100,7 +100,7 @@ public function setDocComment($docComment) {
*
* @return Stmt\Property The built property node
*/
public function getNode() {
public function getNode() : PhpParser\Node {
return new Stmt\Property(
$this->flags !== 0 ? $this->flags : Stmt\Class_::MODIFIER_PUBLIC,
array(
Expand Down
4 changes: 2 additions & 2 deletions lib/PhpParser/Builder/Trait_.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Trait_ extends Declaration
*
* @param string $name Name of the interface
*/
public function __construct($name) {
public function __construct(string $name) {
$this->name = $name;
}

Expand Down Expand Up @@ -47,7 +47,7 @@ public function addStmt($stmt) {
*
* @return Stmt\Trait_ The built interface node
*/
public function getNode() {
public function getNode() : PhpParser\Node {
return new Stmt\Trait_(
$this->name, array(
'stmts' => array_merge($this->properties, $this->methods)
Expand Down
6 changes: 3 additions & 3 deletions lib/PhpParser/Builder/Use_.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Use_ implements Builder {
* @param Node\Name|string $name Name of the entity (namespace, class, function, constant) to alias
* @param int $type One of the Stmt\Use_::TYPE_* constants
*/
public function __construct($name, $type) {
public function __construct($name, int $type) {
$this->name = BuilderHelpers::normalizeName($name);
$this->type = $type;
}
Expand All @@ -33,7 +33,7 @@ public function __construct($name, $type) {
*
* @return $this The builder instance (for fluid interface)
*/
protected function as_($alias) {
protected function as_(string $alias) {
$this->alias = $alias;
return $this;
}
Expand All @@ -50,7 +50,7 @@ public function __call($name, $args) {
*
* @return Node The built node
*/
public function getNode() {
public function getNode() : Node {
return new Stmt\Use_(array(
new Stmt\UseUse($this->name, $this->alias)
), $this->type);
Expand Down
24 changes: 12 additions & 12 deletions lib/PhpParser/BuilderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class BuilderFactory
*
* @return Builder\Namespace_ The created namespace builder
*/
protected function _namespace($name) {
protected function _namespace($name) : Builder\Namespace_ {
return new Builder\Namespace_($name);
}

Expand All @@ -40,7 +40,7 @@ protected function _namespace($name) {
*
* @return Builder\Class_ The created class builder
*/
protected function _class($name) {
protected function _class(string $name) : Builder\Class_ {
return new Builder\Class_($name);
}

Expand All @@ -51,7 +51,7 @@ protected function _class($name) {
*
* @return Builder\Interface_ The created interface builder
*/
protected function _interface($name) {
protected function _interface(string $name) : Builder\Interface_ {
return new Builder\Interface_($name);
}

Expand All @@ -62,7 +62,7 @@ protected function _interface($name) {
*
* @return Builder\Trait_ The created trait builder
*/
protected function _trait($name) {
protected function _trait(string $name) : Builder\Trait_ {
return new Builder\Trait_($name);
}

Expand All @@ -73,7 +73,7 @@ protected function _trait($name) {
*
* @return Builder\Method The created method builder
*/
public function method($name) {
public function method(string $name) : Builder\Method {
return new Builder\Method($name);
}

Expand All @@ -84,7 +84,7 @@ public function method($name) {
*
* @return Builder\Param The created parameter builder
*/
public function param($name) {
public function param(string $name) : Builder\Param {
return new Builder\Param($name);
}

Expand All @@ -95,7 +95,7 @@ public function param($name) {
*
* @return Builder\Property The created property builder
*/
public function property($name) {
public function property(string $name) : Builder\Property {
return new Builder\Property($name);
}

Expand All @@ -106,7 +106,7 @@ public function property($name) {
*
* @return Builder\Function_ The created function builder
*/
protected function _function($name) {
protected function _function(string $name) : Builder\Function_ {
return new Builder\Function_($name);
}

Expand All @@ -117,7 +117,7 @@ protected function _function($name) {
*
* @return Builder\Use_ The create use builder
*/
protected function _use($name) {
protected function _use($name) : Builder\Use_ {
return new Builder\Use_($name, Use_::TYPE_NORMAL);
}

Expand All @@ -128,7 +128,7 @@ protected function _use($name) {
*
* @return Expr
*/
public function val($value) {
public function val($value) : Expr {
return BuilderHelpers::normalizeValue($value);
}

Expand All @@ -141,7 +141,7 @@ public function val($value) {
*
* @return Arg[]
*/
public function args(array $args) {
public function args(array $args) : array {
$normalizedArgs = [];
foreach ($args as $arg) {
if ($arg instanceof Arg) {
Expand All @@ -160,7 +160,7 @@ public function args(array $args) {
*
* @return Concat
*/
public function concat(...$exprs) {
public function concat(...$exprs) : Concat {
$numExprs = count($exprs);
if ($numExprs < 2) {
throw new \LogicException('Expected at least two expressions');
Expand Down
12 changes: 6 additions & 6 deletions lib/PhpParser/BuilderHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class BuilderHelpers {
*
* @return Node The normalized node
*/
public static function normalizeNode($node) {
public static function normalizeNode($node) : Node {
if ($node instanceof Builder) {
return $node->getNode();
} elseif ($node instanceof Node) {
Expand All @@ -42,7 +42,7 @@ public static function normalizeNode($node) {
*
* @return Stmt The normalized statement node
*/
public static function normalizeStmt($node) {
public static function normalizeStmt($node) : Stmt {
$node = self::normalizeNode($node);
if ($node instanceof Stmt) {
return $node;
Expand All @@ -62,7 +62,7 @@ public static function normalizeStmt($node) {
*
* @return Name The normalized name
*/
public static function normalizeName($name) {
public static function normalizeName($name) : Name {
if ($name instanceof Name) {
return $name;
} elseif (is_string($name)) {
Expand Down Expand Up @@ -134,7 +134,7 @@ public static function normalizeType($type) {
*
* @return Expr The normalized value
*/
public static function normalizeValue($value) {
public static function normalizeValue($value) : Expr {
if ($value instanceof Node\Expr) {
return $value;
} elseif (is_null($value)) {
Expand Down Expand Up @@ -182,7 +182,7 @@ public static function normalizeValue($value) {
*
* @return Comment\Doc The normalized doc comment
*/
public static function normalizeDocComment($docComment) {
public static function normalizeDocComment($docComment) : Comment\Doc {
if ($docComment instanceof Comment\Doc) {
return $docComment;
} else if (is_string($docComment)) {
Expand All @@ -200,7 +200,7 @@ public static function normalizeDocComment($docComment) {
*
* @return int New modifiers
*/
public static function addModifier($modifiers, $modifier) {
public static function addModifier(int $modifiers, int $modifier) : int {
Stmt\Class_::verifyModifier($modifiers, $modifier);
return $modifiers | $modifier;
}
Expand Down
Loading

0 comments on commit a32e379

Please sign in to comment.