diff --git a/build.gradle.kts b/build.gradle.kts index 8f88d2c..1c05146 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -74,7 +74,7 @@ tasks { // Set the compatibility versions to 1.8 withType { sourceCompatibility = "1.8" - targetCompatibility = "1.8" + targetCompatibility = "11" } listOf("compileKotlin", "compileTestKotlin").forEach { getByName(it) { @@ -83,7 +83,7 @@ tasks { } withType { - jvmTarget = "1.8" + jvmTarget = "11" } patchPluginXml { diff --git a/detekt-config.yml b/detekt-config.yml index f9b8d75..6c4f830 100644 --- a/detekt-config.yml +++ b/detekt-config.yml @@ -1,8 +1,9 @@ # Default detekt configuration: -# https://github.com/detekt/detekt/blob/master/detekt-core/src/main/resources/default-detekt-config.yml +# https://github.com/detekt/detekt/blob/master/detekt-cli/src/main/resources/default-detekt-config.yml formatting: Indentation: - continuationIndentSize: 8 - ParameterListWrapping: - indentSize: 8 + active: true +style: + ReturnCount: + max: 10 \ No newline at end of file diff --git a/src/main/kotlin/dev/nybroe/collector/Util.kt b/src/main/kotlin/dev/nybroe/collector/Util.kt index e5e024d..9e4b865 100644 --- a/src/main/kotlin/dev/nybroe/collector/Util.kt +++ b/src/main/kotlin/dev/nybroe/collector/Util.kt @@ -1,30 +1,7 @@ package dev.nybroe.collector -import com.intellij.openapi.util.text.StringUtil -import com.intellij.psi.PsiElement -import com.jetbrains.php.lang.PhpLangUtil -import com.jetbrains.php.lang.psi.PhpPsiUtil -import com.jetbrains.php.lang.psi.elements.Function import com.jetbrains.php.lang.psi.elements.FunctionReference -import com.jetbrains.php.lang.psi.elements.StringLiteralExpression -import com.jetbrains.php.lang.psi.elements.Variable fun FunctionReference.isGlobalFunctionCallWithName(name: String): Boolean { - return PhpLangUtil.isGlobalNamespaceFQN(this.namespaceName) && StringUtil.equals(this.name, name) + return this.name == name } - - -fun PsiElement.canBeCalledAsLambda(): Boolean { - return this is Variable || this is StringLiteralExpression -} - - -fun PsiElement.resolveFunction(): Function? { - if (this.canBeCalledAsLambda()) { - val references = this.references - if (references.size == 1) { - return references[0].resolve() as? Function - } - } - return PhpPsiUtil.getChildByCondition(this, Function.INSTANCEOF) as Function? -} \ No newline at end of file diff --git a/src/main/kotlin/dev/nybroe/collector/inspections/ArrayMapToCollectionInspection.kt b/src/main/kotlin/dev/nybroe/collector/inspections/ArrayMapToCollectionInspection.kt index 9731a86..4a2994f 100644 --- a/src/main/kotlin/dev/nybroe/collector/inspections/ArrayMapToCollectionInspection.kt +++ b/src/main/kotlin/dev/nybroe/collector/inspections/ArrayMapToCollectionInspection.kt @@ -27,4 +27,4 @@ class ArrayMapToCollectionInspection : PhpInspection() { } } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/dev/nybroe/collector/quickFixes/ArrayMapToCollectionQuickFix.kt b/src/main/kotlin/dev/nybroe/collector/quickFixes/ArrayMapToCollectionQuickFix.kt index 31984f4..dc83470 100644 --- a/src/main/kotlin/dev/nybroe/collector/quickFixes/ArrayMapToCollectionQuickFix.kt +++ b/src/main/kotlin/dev/nybroe/collector/quickFixes/ArrayMapToCollectionQuickFix.kt @@ -8,7 +8,7 @@ import com.jetbrains.php.lang.psi.elements.FunctionReference class ArrayMapToCollectionQuickFix : LocalQuickFix { companion object { - const val QUICK_FIX_NAME = "Refactor array_map to collection" + const val QUICK_FIX_NAME = "Refactor 'array_map' to collection" } override fun getFamilyName(): String { @@ -30,10 +30,10 @@ class ArrayMapToCollectionQuickFix : LocalQuickFix { } descriptor.psiElement.replace( - PhpPsiElementFactory.createStatement( + PhpPsiElementFactory.createMethodReference( project, "collect(${parameters[1].text})->map(${parameters[0].text})->all()" ) ) } -} \ No newline at end of file +} diff --git a/src/test/kotlin/dev/nybroe/collector/inspections/ArrayMapToCollectionInspectionTest.kt b/src/test/kotlin/dev/nybroe/collector/inspections/ArrayMapToCollectionInspectionTest.kt index 73584ff..63ab87b 100644 --- a/src/test/kotlin/dev/nybroe/collector/inspections/ArrayMapToCollectionInspectionTest.kt +++ b/src/test/kotlin/dev/nybroe/collector/inspections/ArrayMapToCollectionInspectionTest.kt @@ -15,4 +15,12 @@ internal class ArrayMapToCollectionInspectionTest : InspectionTest() { fun testCallbackAndArray() { doTest("array_map-callback-and-array") } + + fun testInNamespace() { + doTest("array_map-in-namespace") + } + + fun testNamespacedArrayMap() { + doTest("array_map-in-namespace") + } } diff --git a/src/test/resources/inspections/ArrayMapToCollectionInspection/array_map-in-namespace.after.php b/src/test/resources/inspections/ArrayMapToCollectionInspection/array_map-in-namespace.after.php new file mode 100644 index 0000000..4b98ac5 --- /dev/null +++ b/src/test/resources/inspections/ArrayMapToCollectionInspection/array_map-in-namespace.after.php @@ -0,0 +1,8 @@ +map(function ($n) { + return ($n * $n * $n); +})->all(); diff --git a/src/test/resources/inspections/ArrayMapToCollectionInspection/array_map-in-namespace.php b/src/test/resources/inspections/ArrayMapToCollectionInspection/array_map-in-namespace.php new file mode 100644 index 0000000..7e51e18 --- /dev/null +++ b/src/test/resources/inspections/ArrayMapToCollectionInspection/array_map-in-namespace.php @@ -0,0 +1,8 @@ +array_map(function($n) { + return ($n * $n * $n); +}, $a); diff --git a/src/test/resources/inspections/ArrayMapToCollectionInspection/namespaced_array_map.after.php b/src/test/resources/inspections/ArrayMapToCollectionInspection/namespaced_array_map.after.php new file mode 100644 index 0000000..9f58183 --- /dev/null +++ b/src/test/resources/inspections/ArrayMapToCollectionInspection/namespaced_array_map.after.php @@ -0,0 +1,8 @@ +\array_map(function($n) { + return ($n * $n * $n); +}, $a); diff --git a/src/test/resources/inspections/ArrayMapToCollectionInspection/namespaced_array_map.php b/src/test/resources/inspections/ArrayMapToCollectionInspection/namespaced_array_map.php new file mode 100644 index 0000000..4b98ac5 --- /dev/null +++ b/src/test/resources/inspections/ArrayMapToCollectionInspection/namespaced_array_map.php @@ -0,0 +1,8 @@ +map(function ($n) { + return ($n * $n * $n); +})->all();