Skip to content

Commit

Permalink
Declare list types (#907)
Browse files Browse the repository at this point in the history
Closes #905
  • Loading branch information
staabm authored Dec 14, 2022
1 parent 4c4af21 commit 8ad4129
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 46 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,24 @@ jobs:
run: "composer update --no-progress --prefer-dist"
- name: "Tests"
run: "test_old/run-php-src.sh 8.1.6"
phpstan:
runs-on: "ubuntu-latest"
name: "PHP ${{ matrix.php-version }} PHPStan"
strategy:
matrix:
php-version:
- "8.2"
steps:
- name: "Checkout"
uses: "actions/checkout@v2"
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
coverage: "none"
php-version: "${{ matrix.php-version }}"
tools: composer:v2
- name: "Install dependencies"
run: |
cd tools && composer install
- name: "PHPStan"
run: "php tools/vendor/bin/phpstan"
4 changes: 2 additions & 2 deletions lib/PhpParser/Builder/ClassConst.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class ClassConst implements PhpParser\Builder {
protected $flags = 0;
/** @var array<string, mixed> */
protected $attributes = [];
/** @var Const_[] */
/** @var list<Const_> */
protected $constants = [];

/** @var Node\AttributeGroup[] */
/** @var list<Node\AttributeGroup> */
protected $attributeGroups = [];

/**
Expand Down
12 changes: 6 additions & 6 deletions lib/PhpParser/Builder/Class_.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ class Class_ extends Declaration {

/** @var Name|null */
protected $extends = null;
/** @var Name[] */
/** @var list<Name> */
protected $implements = [];
/** @var int */
protected $flags = 0;

/** @var Stmt\TraitUse[] */
/** @var list<Stmt\TraitUse> */
protected $uses = [];
/** @var Stmt\ClassConst[] */
/** @var list<Stmt\ClassConst> */
protected $constants = [];
/** @var Stmt\Property[] */
/** @var list<Stmt\Property> */
protected $properties = [];
/** @var Stmt\ClassMethod[] */
/** @var list<Stmt\ClassMethod> */
protected $methods = [];
/** @var Node\AttributeGroup[] */
/** @var list<Node\AttributeGroup> */
protected $attributeGroups = [];

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Builder/EnumCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class EnumCase implements PhpParser\Builder {
/** @var array<string, mixed> */
protected $attributes = [];

/** @var Node\AttributeGroup[] */
/** @var list<Node\AttributeGroup> */
protected $attributeGroups = [];

/**
Expand Down
12 changes: 6 additions & 6 deletions lib/PhpParser/Builder/Enum_.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ class Enum_ extends Declaration {
protected $name;
/** @var Identifier|null */
protected $scalarType = null;
/** @var Name[] */
/** @var list<Name> */
protected $implements = [];
/** @var Stmt\TraitUse[] */
/** @var list<Stmt\TraitUse> */
protected $uses = [];
/** @var Stmt\EnumCase[] */
/** @var list<Stmt\EnumCase> */
protected $enumCases = [];
/** @var Stmt\ClassConst[] */
/** @var list<Stmt\ClassConst> */
protected $constants = [];
/** @var Stmt\ClassMethod[] */
/** @var list<Stmt\ClassMethod> */
protected $methods = [];
/** @var Node\AttributeGroup[] */
/** @var list<Node\AttributeGroup> */
protected $attributeGroups = [];

/**
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 @@ -10,10 +10,10 @@
class Function_ extends FunctionLike {
/** @var string */
protected $name;
/** @var Stmt[] */
/** @var list<Stmt> */
protected $stmts = [];

/** @var Node\AttributeGroup[] */
/** @var list<Node\AttributeGroup> */
protected $attributeGroups = [];

/**
Expand Down
8 changes: 4 additions & 4 deletions lib/PhpParser/Builder/Interface_.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
class Interface_ extends Declaration {
/** @var string */
protected $name;
/** @var Name[] */
/** @var list<Name> */
protected $extends = [];
/** @var Stmt\ClassConst[] */
/** @var list<Stmt\ClassConst> */
protected $constants = [];
/** @var Stmt\ClassMethod[] */
/** @var list<Stmt\ClassMethod> */
protected $methods = [];
/** @var Node\AttributeGroup[] */
/** @var list<Node\AttributeGroup> */
protected $attributeGroups = [];

/**
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 @@ -14,10 +14,10 @@ class Method extends FunctionLike {
/** @var int */
protected $flags = 0;

/** @var Stmt[]|null */
/** @var list<Stmt>|null */
protected $stmts = [];

/** @var Node\AttributeGroup[] */
/** @var list<Node\AttributeGroup> */
protected $attributeGroups = [];

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Builder/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Param implements PhpParser\Builder {
protected $byRef = false;
/** @var bool */
protected $variadic = false;
/** @var Node\AttributeGroup[] */
/** @var list<Node\AttributeGroup> */
protected $attributeGroups = [];

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Builder/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Property implements PhpParser\Builder {
protected $attributes = [];
/** @var null|Identifier|Name|ComplexType */
protected $type;
/** @var Node\AttributeGroup[] */
/** @var list<Node\AttributeGroup> */
protected $attributeGroups = [];

/**
Expand Down
10 changes: 5 additions & 5 deletions lib/PhpParser/Builder/Trait_.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
class Trait_ extends Declaration {
/** @var string */
protected $name;
/** @var Stmt\TraitUse[] */
/** @var list<Stmt\TraitUse> */
protected $uses = [];
/** @var Stmt\ClassConst[] */
/** @var list<Stmt\ClassConst> */
protected $constants = [];
/** @var Stmt\Property[] */
/** @var list<Stmt\Property> */
protected $properties = [];
/** @var Stmt\ClassMethod[] */
/** @var list<Stmt\ClassMethod> */
protected $methods = [];
/** @var Node\AttributeGroup[] */
/** @var list<Node\AttributeGroup> */
protected $attributeGroups = [];

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/BuilderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public function var($name): Expr\Variable {
*
* @param array $args List of arguments to normalize
*
* @return Arg[]
* @return list<Arg>
*/
public function args(array $args): array {
$normalizedArgs = [];
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class Lexer {
/** @var string Code being tokenized */
protected $code;
/** @var Token[] Array of tokens */
/** @var list<Token> List of tokens */
protected $tokens;
/** @var int Current position in the token array */
protected $pos;
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Lexer/Emulative.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class Emulative extends Lexer {
/** @var array{int, string, string}[] Patches used to reverse changes introduced in the code */
private $patches = [];

/** @var TokenEmulator[] */
/** @var list<TokenEmulator> */
private $emulators = [];

/** @var PhpVersion */
Expand Down
4 changes: 2 additions & 2 deletions lib/PhpParser/Node/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class Attribute extends NodeAbstract {
/** @var Name Attribute name */
public $name;

/** @var Arg[] Attribute arguments */
/** @var list<Arg> Attribute arguments */
public $args;

/**
* @param Node\Name $name Attribute name
* @param Arg[] $args Attribute arguments
* @param list<Arg> $args Attribute arguments
* @param array<string, mixed> $attributes Additional node attributes
*/
public function __construct(Name $name, array $args = [], array $attributes = []) {
Expand Down
4 changes: 2 additions & 2 deletions lib/PhpParser/Node/MatchArm.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
use PhpParser\NodeAbstract;

class MatchArm extends NodeAbstract {
/** @var null|Node\Expr[] */
/** @var null|list<Node\Expr> */
public $conds;
/** @var Node\Expr */
public $body;

/**
* @param null|Node\Expr[] $conds
* @param null|list<Node\Expr> $conds
*/
public function __construct(?array $conds, Node\Expr $body, array $attributes = []) {
$this->conds = $conds;
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Node/Param.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Param extends NodeAbstract {
* @param bool $variadic Whether this is a variadic argument
* @param array<string, mixed> $attributes Additional attributes
* @param int $flags Optional visibility flags
* @param AttributeGroup[] $attrGroups PHP attribute groups
* @param list<AttributeGroup> $attrGroups PHP attribute groups
*/
public function __construct(
$var, ?Expr $default = null, $type = null,
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Node/Stmt/ClassConst.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ClassConst extends Node\Stmt {
* @param Node\Const_[] $consts Constant declarations
* @param int $flags Modifiers
* @param array<string, mixed> $attributes Additional attributes
* @param Node\AttributeGroup[] $attrGroups PHP attribute groups
* @param list<Node\AttributeGroup> $attrGroups PHP attribute groups
*/
public function __construct(
array $consts,
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/Node/Stmt/EnumCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class EnumCase extends Node\Stmt {
/**
* @param string|Node\Identifier $name Enum case name
* @param Node\Expr|null $expr Enum case expression
* @param AttributeGroup[] $attrGroups PHP attribute groups
* @param list<AttributeGroup> $attrGroups PHP attribute groups
* @param array<string, mixed> $attributes Additional attributes
*/
public function __construct($name, ?Node\Expr $expr = null, array $attrGroups = [], array $attributes = []) {
Expand Down
2 changes: 1 addition & 1 deletion lib/PhpParser/NodeTraverser.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class NodeTraverser implements NodeTraverserInterface {
*/
public const DONT_TRAVERSE_CURRENT_AND_CHILDREN = 4;

/** @var NodeVisitor[] Visitors */
/** @var list<NodeVisitor> Visitors */
protected $visitors = [];

/** @var bool Whether traversal should be stopped */
Expand Down
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,6 @@ parameters:
count: 1
path: lib/PhpParser/ParserAbstract.php

-
message: "#^Property PhpParser\\\\ParserAbstract\\:\\:\\$createdArrays \\(SplObjectStorage\\<PhpParser\\\\Node\\\\Expr\\\\Array_, null\\>\\|null\\) does not accept SplObjectStorage\\<object, mixed\\>\\.$#"
count: 1
path: lib/PhpParser/ParserAbstract.php

-
message: "#^Unary operation \"\\+\" on string results in an error\\.$#"
count: 1
Expand Down

0 comments on commit 8ad4129

Please sign in to comment.