From ca84b976a763fb9fc4fcf86279f21232cf79f719 Mon Sep 17 00:00:00 2001 From: Brent Roose Date: Tue, 27 Aug 2024 14:41:14 +0200 Subject: [PATCH] Fix for functions called "new" --- UPGRADING.md | 1 + src/Languages/Php/PhpLanguage.php | 2 +- tests/Languages/Php/PhpLanguageTest.php | 1 + tests/targets/test.md | 4 ++-- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index ca5d89c..1e48952 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -6,6 +6,7 @@ - Fix for attribute in promoted property (#133) - Fix for comments in function argument lists (#134) - Fix for variadic types (#140) +- Fix for functions called "new" (#141) ## 2.8.2 diff --git a/src/Languages/Php/PhpLanguage.php b/src/Languages/Php/PhpLanguage.php index 474bd5b..fbf90c1 100644 --- a/src/Languages/Php/PhpLanguage.php +++ b/src/Languages/Php/PhpLanguage.php @@ -84,6 +84,7 @@ public function getPatterns(): array new OperatorPattern('\|\|'), new OperatorPattern('<=>'), new OperatorPattern('\?'), + new FunctionNamePattern(), // KEYWORDS new KeywordPattern('null'), @@ -190,7 +191,6 @@ public function getPatterns(): array // PROPERTIES new ClassPropertyPattern(), new PropertyAccessPattern(), - new FunctionNamePattern(), new NestedFunctionCallPattern(), new FunctionCallPattern(), new ConstantPropertyPattern(), diff --git a/tests/Languages/Php/PhpLanguageTest.php b/tests/Languages/Php/PhpLanguageTest.php index 32fd46c..962db14 100644 --- a/tests/Languages/Php/PhpLanguageTest.php +++ b/tests/Languages/Php/PhpLanguageTest.php @@ -135,6 +135,7 @@ public function info( * hello */ public ?array $chapters, ) {}'], + ['public static function new(mixed ...$params): self;', 'public static function new(mixed ...$params): self;'], ]; } } diff --git a/tests/targets/test.md b/tests/targets/test.md index 3cc03e9..567c397 100644 --- a/tests/targets/test.md +++ b/tests/targets/test.md @@ -1,3 +1,3 @@ ```php -public function update(Foo ...$params): self; -``` \ No newline at end of file +public static function new(mixed ...$params): self; +``` \ No newline at end of file