psalm icon indicating copy to clipboard operation
psalm copied to clipboard

ClassMustBeFinal tries to insert final into strange places.

Open HenkPoley opened this issue 7 months ago • 6 comments

Psalm 6.12.0@cf420941d061a57050b6c468ef2c778faf40aee2

Odd places such as inserting final before the initial <?php

diff --git a/src/Application.php b/src/Application.php
--- a/src/Application.php	(revision 1c2b1fbab260d4d4b4c17f9068947f8e9b418d70)
+++ b/src/Application.php	(date 1748664994185)
@@ -1,4 +1,4 @@
-<?php
+final <?php
 
 namespace HenkPoley\DocBlockDoctor;
 

Or in the middle of the use list.

diff --git a/src/AstUtils.php b/src/AstUtils.php
--- a/src/AstUtils.php	(revision 1c2b1fbab260d4d4b4c17f9068947f8e9b418d70)
+++ b/src/AstUtils.php	(date 1748664994185)
@@ -3,7 +3,7 @@
 namespace HenkPoley\DocBlockDoctor;
 
 use PhpParser\Node;
-use PhpParser\Node\Expr\Assign;
+final use PhpParser\Node\Expr\Assign;
 use PhpParser\NodeFinder;
 
 /**

From this code at revision 1c2b1fb https://github.com/HenkPoley/PhpDocBlockDoctor/commit/1c2b1fbab260d4d4b4c17f9068947f8e9b418d70

HenkPoley avatar May 31 '25 04:05 HenkPoley

Hey @HenkPoley, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.

psalm-github-bot[bot] avatar May 31 '25 04:05 psalm-github-bot[bot]

This does not appear to emit any 'ERROR:'. So it is not possible to reproduce on the demo page of https://psalm.dev/

HenkPoley avatar May 31 '25 04:05 HenkPoley

--no-cache nor --clear-cache / --clear-global-cache has any influence.

So it is not #11299.

In particular, running psalm without --alter, does not emit any ERROR: ClassMustBeFinal.

HenkPoley avatar May 31 '25 04:05 HenkPoley

I am seeing similar

-<?php
+final <?php
 
 namespace Database\Seeders;
 
@@ -14,69 +14,4 @@
 class UserSeeder extends Seeder
 {

I am also using "psalm/plugin-laravel": "^3.0", if that has any bearing on it.

pl38 avatar Jun 03 '25 11:06 pl38

Same here (Psalm 6.13.0) :

-use My\App\Config\Config;
+ufinal se My\App\Config\Config;
-<?php
+final <?php

emmanuelGuiton avatar Jul 23 '25 09:07 emmanuelGuiton

This issue makes fixer unusable. Patch from linked PR works

Xerkus avatar Oct 09 '25 08:10 Xerkus