Skip to content

Commit 3330f4e

Browse files
committed
Prevent deprecation warning when parsing some anonymous classes.
Fixes #867
1 parent 49342d8 commit 3330f4e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/CodeCleaner/ValidConstructorPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function enterNode(Node $node)
6969
}
7070

7171
// We found a possible old-style constructor (unless there is also a __construct method)
72-
if (empty($this->namespace) && \strtolower($node->name) === \strtolower($stmt->name)) {
72+
if (empty($this->namespace) && $node->name !== null && \strtolower($node->name) === \strtolower($stmt->name)) {
7373
$constructor = $stmt;
7474
}
7575
}

test/CodeCleaner/ValidConstructorPassTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,22 @@ public function validStatements()
9090
['namespace B; class A { private static function A(): ?array {}}'],
9191
];
9292
}
93+
94+
/**
95+
* @dataProvider anonymousClasses
96+
*/
97+
public function testAnonymousClasses($code)
98+
{
99+
$this->parseAndTraverse($code);
100+
$this->assertTrue(true);
101+
}
102+
103+
public function anonymousClasses()
104+
{
105+
return [
106+
['new class() { public function __construct() {} }'],
107+
['new class() { public function f(): void {} }'],
108+
['new class() { private function f(): void {} public function __construct() {} }'],
109+
];
110+
}
93111
}

0 commit comments

Comments
 (0)