Skip to content

Commit b08c116

Browse files
authored
Merge pull request #165 from funivan/PhpClean-163-final-anonymous
#163 MethodShouldBeFinal should not apply to anonymous classes
2 parents 8752dac + 519a3c9 commit b08c116

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<!-- Keep a Changelog guide -> https://keepachangelog.com -->
22

33
# PhpClean Changelog
4-
## [2022.08.05]
4+
## [2022.08.30]
55
### Changed
6+
- #163 Skip "final check" for anonymous classes
67
- #151 Fix property visibility inspection for php8.1
78
- #156 Skip Virtual type check for generic types
89

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pluginGroup = com.funivan.idea.phpClean
22
pluginName_ = PhpClean
33
name = PhpClean
4-
pluginVersion = 2020.06.03
4+
pluginVersion = 2022.08.30
55
pluginSinceBuild = 211
66
#pluginUntilBuild = 203.*
77
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl

src/main/kotlin/com/funivan/idea/phpClean/inspections/methodShouldBeFinal/MethodShouldBeFinalInspection.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MethodShouldBeFinalInspection : PhpCleanInspection() {
1414
override fun buildVisitor(holder: ProblemsHolder, isOnTheFly: Boolean): PsiElementVisitor {
1515
return object : PhpElementVisitor() {
1616
override fun visitPhpClass(phpClass: PhpClass) {
17-
if (!phpClass.isFinal && !phpClass.isInterface) {
17+
if (!phpClass.isFinal && !phpClass.isInterface && !phpClass.isAnonymous) {
1818
for (method in methods(phpClass)) {
1919
holder.registerProblem(
2020
method.nameIdentifier ?: method,
@@ -35,4 +35,4 @@ class MethodShouldBeFinalInspection : PhpCleanInspection() {
3535
&& !magic.match(it)
3636
}
3737
}
38-
}
38+
}

src/test/kotlin/com/funivan/idea/phpClean/inspections/methodShouldBeFinal/MethodShouldBeFinalInspectionTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ class MethodShouldBeFinalInspectionTest : BaseInspectionTest() {
1818
"""
1919
)
2020
}
21+
@Test
22+
fun testIgnoreAnonumousClass() {
23+
assert(
24+
MethodShouldBeFinalInspection(),
25+
"""<?php
26+
return new class {
27+
public function I_do_not_have_to_be_final () : void
28+
{
29+
}
30+
};
31+
"""
32+
)
33+
}
2134

2235

2336
@Test

0 commit comments

Comments
 (0)