Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing void return types #997

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types=1);

Check failure on line 1 in lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Ignored error pattern #^Method PhpParser\\NodeVisitor\\NodeConnectingVisitor\:\:beforeTraverse\(\) should return array\<PhpParser\\Node\>\|null but return statement is missing\.$# in path /home/runner/work/PHP-Parser/PHP-Parser/lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php was not matched in reported errors.

Check failure on line 1 in lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Ignored error pattern #^Method PhpParser\\NodeVisitor\\NodeConnectingVisitor\:\:enterNode\(\) should return array\<PhpParser\\Node\>\|int\|PhpParser\\Node\|null but return statement is missing\.$# in path /home/runner/work/PHP-Parser/PHP-Parser/lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php was not matched in reported errors.

Check failure on line 1 in lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Ignored error pattern #^Method PhpParser\\NodeVisitor\\NodeConnectingVisitor\:\:leaveNode\(\) should return array\<PhpParser\\Node\>\|int\|PhpParser\\Node\|null but return statement is missing\.$# in path /home/runner/work/PHP-Parser/PHP-Parser/lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php was not matched in reported errors.

namespace PhpParser\NodeVisitor;

Expand All @@ -25,12 +25,12 @@
*/
private $previous;

public function beforeTraverse(array $nodes) {
public function beforeTraverse(array $nodes): void {

Check failure on line 28 in lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Return type (void) of method PhpParser\NodeVisitor\NodeConnectingVisitor::beforeTraverse() should be compatible with return type (array<PhpParser\Node>|null) of method PhpParser\NodeVisitor::beforeTraverse()

Check failure on line 28 in lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Return type (void) of method PhpParser\NodeVisitor\NodeConnectingVisitor::beforeTraverse() should be compatible with return type (array<PhpParser\Node>|null) of method PhpParser\NodeVisitorAbstract::beforeTraverse()
nikic marked this conversation as resolved.
Show resolved Hide resolved
$this->stack = [];
$this->previous = null;
}

public function enterNode(Node $node) {
public function enterNode(Node $node): void {

Check failure on line 33 in lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Return type (void) of method PhpParser\NodeVisitor\NodeConnectingVisitor::enterNode() should be compatible with return type (array<PhpParser\Node>|int|PhpParser\Node|null) of method PhpParser\NodeVisitor::enterNode()

Check failure on line 33 in lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Return type (void) of method PhpParser\NodeVisitor\NodeConnectingVisitor::enterNode() should be compatible with return type (array<PhpParser\Node>|int|PhpParser\Node|null) of method PhpParser\NodeVisitorAbstract::enterNode()
if (!empty($this->stack)) {
$node->setAttribute('parent', $this->stack[count($this->stack) - 1]);
}
Expand All @@ -43,7 +43,7 @@
$this->stack[] = $node;
}

public function leaveNode(Node $node) {
public function leaveNode(Node $node): void {

Check failure on line 46 in lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Return type (void) of method PhpParser\NodeVisitor\NodeConnectingVisitor::leaveNode() should be compatible with return type (array<PhpParser\Node>|int|PhpParser\Node|null) of method PhpParser\NodeVisitor::leaveNode()

Check failure on line 46 in lib/PhpParser/NodeVisitor/NodeConnectingVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Return type (void) of method PhpParser\NodeVisitor\NodeConnectingVisitor::leaveNode() should be compatible with return type (array<PhpParser\Node>|int|PhpParser\Node|null) of method PhpParser\NodeVisitorAbstract::leaveNode()
$this->previous = $node;

array_pop($this->stack);
Expand Down
6 changes: 3 additions & 3 deletions lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php declare(strict_types=1);

Check failure on line 1 in lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php

View workflow job for this annotation

GitHub Actions / PHPStan

Ignored error pattern #^Method PhpParser\\NodeVisitor\\ParentConnectingVisitor\:\:beforeTraverse\(\) should return array\<PhpParser\\Node\>\|null but return statement is missing\.$# in path /home/runner/work/PHP-Parser/PHP-Parser/lib/PhpParser/NodeVisitor/ParentConnectingVisitor.php was not matched in reported errors.

namespace PhpParser\NodeVisitor;

Expand All @@ -20,19 +20,19 @@
*/
private array $stack = [];

public function beforeTraverse(array $nodes) {
public function beforeTraverse(array $nodes): void {
$this->stack = [];
}

public function enterNode(Node $node) {
public function enterNode(Node $node): void {
if (!empty($this->stack)) {
$node->setAttribute('parent', $this->stack[count($this->stack) - 1]);
}

$this->stack[] = $node;
}

public function leaveNode(Node $node) {
public function leaveNode(Node $node): void {
array_pop($this->stack);
}
}
12 changes: 6 additions & 6 deletions test/PhpParser/Builder/ClassConstTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function createClassConstBuilder($name, $value) {
return new ClassConst($name, $value);
}

public function testModifiers() {
public function testModifiers(): void {
$node = $this->createClassConstBuilder("TEST", 1)
->makePrivate()
->getNode()
Expand Down Expand Up @@ -82,7 +82,7 @@ public function testModifiers() {
);
}

public function testDocComment() {
public function testDocComment(): void {
$node = $this->createClassConstBuilder('TEST', 1)
->setDocComment('/** Test */')
->makePublic()
Expand All @@ -102,7 +102,7 @@ public function testDocComment() {
);
}

public function testAddConst() {
public function testAddConst(): void {
$node = $this->createClassConstBuilder('FIRST_TEST', 1)
->addConst("SECOND_TEST", 2)
->getNode();
Expand All @@ -118,7 +118,7 @@ public function testAddConst() {
);
}

public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
Expand All @@ -142,7 +142,7 @@ public function testAddAttribute() {
);
}

public function testType() {
public function testType(): void {
$node = $this->createClassConstBuilder('TYPE', 1)
->setType('int')
->getNode();
Expand All @@ -157,7 +157,7 @@ public function testType() {
/**
* @dataProvider provideTestDefaultValues
*/
public function testValues($value, $expectedValueNode) {
public function testValues($value, $expectedValueNode): void {
$node = $this->createClassConstBuilder('TEST', $value)
->getNode()
;
Expand Down
22 changes: 11 additions & 11 deletions test/PhpParser/Builder/ClassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected function createClassBuilder($class) {
return new Class_($class);
}

public function testExtendsImplements() {
public function testExtendsImplements(): void {
$node = $this->createClassBuilder('SomeLogger')
->extend('BaseLogger')
->implement('Namespaced\Logger', new Name('SomeInterface'))
Expand All @@ -40,7 +40,7 @@ public function testExtendsImplements() {
);
}

public function testAbstract() {
public function testAbstract(): void {
$node = $this->createClassBuilder('Test')
->makeAbstract()
->getNode()
Expand All @@ -54,7 +54,7 @@ public function testAbstract() {
);
}

public function testFinal() {
public function testFinal(): void {
$node = $this->createClassBuilder('Test')
->makeFinal()
->getNode()
Expand All @@ -68,7 +68,7 @@ public function testFinal() {
);
}

public function testReadonly() {
public function testReadonly(): void {
$node = $this->createClassBuilder('Test')
->makeReadonly()
->getNode()
Expand All @@ -82,7 +82,7 @@ public function testReadonly() {
);
}

public function testStatementOrder() {
public function testStatementOrder(): void {
$method = new Stmt\ClassMethod('testMethod');
$property = new Stmt\Property(
Modifiers::PUBLIC,
Expand All @@ -108,7 +108,7 @@ public function testStatementOrder() {
);
}

public function testDocComment() {
public function testDocComment(): void {
$docComment = <<<'DOC'
/**
* Test
Expand Down Expand Up @@ -141,7 +141,7 @@ public function testDocComment() {
);
}

public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
Expand All @@ -162,29 +162,29 @@ public function testAddAttribute() {
);
}

public function testInvalidStmtError() {
public function testInvalidStmtError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Unexpected node of type "Stmt_Echo"');
$this->createClassBuilder('Test')
->addStmt(new Stmt\Echo_([]))
;
}

public function testInvalidDocComment() {
public function testInvalidDocComment(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Doc comment must be a string or an instance of PhpParser\Comment\Doc');
$this->createClassBuilder('Test')
->setDocComment(new Comment('Test'));
}

public function testEmptyName() {
public function testEmptyName(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Name cannot be empty');
$this->createClassBuilder('Test')
->extend('');
}

public function testInvalidName() {
public function testInvalidName(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Name must be a string or an instance of Node\Name');
$this->createClassBuilder('Test')
Expand Down
6 changes: 3 additions & 3 deletions test/PhpParser/Builder/EnumCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function createEnumCaseBuilder($name) {
return new EnumCase($name);
}

public function testDocComment() {
public function testDocComment(): void {
$node = $this->createEnumCaseBuilder('TEST')
->setDocComment('/** Test */')
->getNode();
Expand All @@ -35,7 +35,7 @@ public function testDocComment() {
);
}

public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
Expand All @@ -59,7 +59,7 @@ public function testAddAttribute() {
/**
* @dataProvider provideTestDefaultValues
*/
public function testValues($value, $expectedValueNode) {
public function testValues($value, $expectedValueNode): void {
$node = $this->createEnumCaseBuilder('TEST')
->setValue($value)
->getNode()
Expand Down
18 changes: 9 additions & 9 deletions test/PhpParser/Builder/EnumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ protected function createEnumBuilder($class) {
return new Enum_($class);
}

public function testImplements() {
public function testImplements(): void {
$node = $this->createEnumBuilder('SomeEnum')
->implement('Namespaced\SomeInterface', new Name('OtherInterface'))
->getNode()
Expand All @@ -34,7 +34,7 @@ public function testImplements() {
);
}

public function testSetScalarType() {
public function testSetScalarType(): void {
$node = $this->createEnumBuilder('Test')
->setScalarType('int')
->getNode()
Expand All @@ -48,7 +48,7 @@ public function testSetScalarType() {
);
}

public function testStatementOrder() {
public function testStatementOrder(): void {
$method = new Stmt\ClassMethod('testMethod');
$enumCase = new Stmt\EnumCase(
'TEST_ENUM_CASE'
Expand All @@ -73,7 +73,7 @@ public function testStatementOrder() {
);
}

public function testDocComment() {
public function testDocComment(): void {
$docComment = <<<'DOC'
/**
* Test
Expand Down Expand Up @@ -106,7 +106,7 @@ public function testDocComment() {
);
}

public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
Expand All @@ -127,29 +127,29 @@ public function testAddAttribute() {
);
}

public function testInvalidStmtError() {
public function testInvalidStmtError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Unexpected node of type "PropertyItem"');
$this->createEnumBuilder('Test')
->addStmt(new Node\PropertyItem('property'))
;
}

public function testInvalidDocComment() {
public function testInvalidDocComment(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Doc comment must be a string or an instance of PhpParser\Comment\Doc');
$this->createEnumBuilder('Test')
->setDocComment(new Comment('Test'));
}

public function testEmptyName() {
public function testEmptyName(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Name cannot be empty');
$this->createEnumBuilder('Test')
->implement('');
}

public function testInvalidName() {
public function testInvalidName(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Name must be a string or an instance of Node\Name');
$this->createEnumBuilder('Test')
Expand Down
18 changes: 9 additions & 9 deletions test/PhpParser/Builder/FunctionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function createFunctionBuilder($name) {
return new Function_($name);
}

public function testReturnByRef() {
public function testReturnByRef(): void {
$node = $this->createFunctionBuilder('test')
->makeReturnByRef()
->getNode()
Expand All @@ -34,7 +34,7 @@ public function testReturnByRef() {
);
}

public function testParams() {
public function testParams(): void {
$param1 = new Node\Param(new Variable('test1'));
$param2 = new Node\Param(new Variable('test2'));
$param3 = new Node\Param(new Variable('test3'));
Expand All @@ -53,7 +53,7 @@ public function testParams() {
);
}

public function testStmts() {
public function testStmts(): void {
$stmt1 = new Print_(new String_('test1'));
$stmt2 = new Print_(new String_('test2'));
$stmt3 = new Print_(new String_('test3'));
Expand All @@ -76,7 +76,7 @@ public function testStmts() {
);
}

public function testDocComment() {
public function testDocComment(): void {
$node = $this->createFunctionBuilder('test')
->setDocComment('/** Test */')
->getNode();
Expand All @@ -86,7 +86,7 @@ public function testDocComment() {
]), $node);
}

public function testAddAttribute() {
public function testAddAttribute(): void {
$attribute = new Attribute(
new Name('Attr'),
[new Arg(new Int_(1), false, false, [], new Identifier('name'))]
Expand All @@ -102,7 +102,7 @@ public function testAddAttribute() {
], []), $node);
}

public function testReturnType() {
public function testReturnType(): void {
$node = $this->createFunctionBuilder('test')
->setReturnType('void')
->getNode();
Expand All @@ -112,21 +112,21 @@ public function testReturnType() {
], []), $node);
}

public function testInvalidNullableVoidType() {
public function testInvalidNullableVoidType(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('void type cannot be nullable');
$this->createFunctionBuilder('test')->setReturnType('?void');
}

public function testInvalidParamError() {
public function testInvalidParamError(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Expected parameter node, got "Name"');
$this->createFunctionBuilder('test')
->addParam(new Node\Name('foo'))
;
}

public function testAddNonStmt() {
public function testAddNonStmt(): void {
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Expected statement or expression node');
$this->createFunctionBuilder('test')
Expand Down
Loading
Loading