diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f19218..d142ff3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ### Removed ### Fixed +- Fixed collect on collection matching non strictly. ### Security ## [0.1.0] diff --git a/gradle.properties b/gradle.properties index 079795e..67688a0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ pluginGroup = dev.nybroe.collector pluginName_ = Collector -pluginVersion = 0.2.0.EAP.1 +pluginVersion = 0.2.0.EAP.2 pluginSinceBuild = 202 pluginUntilBuild = diff --git a/src/main/kotlin/dev/nybroe/collector/Util.kt b/src/main/kotlin/dev/nybroe/collector/Util.kt index d09dc24..e6e9b3e 100644 --- a/src/main/kotlin/dev/nybroe/collector/Util.kt +++ b/src/main/kotlin/dev/nybroe/collector/Util.kt @@ -36,6 +36,9 @@ val MethodReference.isCollectionMethod: Boolean val PhpReference.isCollectionType: Boolean get() = this.type.global(this.project).isCollection(this.project) +val PhpReference.isCollectionTypeStrict: Boolean + get() = this.type.global(this.project).isCollectionStrict(this.project) + val Function.isShortArrowFunction: Boolean get() = FunctionImpl.isShortArrowFunction(this) @@ -52,6 +55,10 @@ fun PhpType.isCollection(project: Project): Boolean { ) } +fun PhpType.isCollectionStrict(project: Project): Boolean { + return this.types.all { PhpType().add(it).isCollection(project) } +} + fun PhpType.isHigherOrderCollection(project: Project): Boolean { val filteredType = this.filterMixed() diff --git a/src/main/kotlin/dev/nybroe/collector/inspections/CollectFunctionInCollectionInspection.kt b/src/main/kotlin/dev/nybroe/collector/inspections/CollectFunctionInCollectionInspection.kt index 93c91ef..3a1e331 100644 --- a/src/main/kotlin/dev/nybroe/collector/inspections/CollectFunctionInCollectionInspection.kt +++ b/src/main/kotlin/dev/nybroe/collector/inspections/CollectFunctionInCollectionInspection.kt @@ -8,7 +8,7 @@ import com.jetbrains.php.lang.psi.elements.FunctionReference import com.jetbrains.php.lang.psi.elements.PhpReference import com.jetbrains.php.lang.psi.visitors.PhpElementVisitor import dev.nybroe.collector.MyBundle -import dev.nybroe.collector.isCollectionType +import dev.nybroe.collector.isCollectionTypeStrict import dev.nybroe.collector.isGlobalFunctionCallWithName import dev.nybroe.collector.quickFixes.NestedCollectionQuickFix @@ -26,7 +26,7 @@ class CollectFunctionInCollectionInspection : PhpInspection() { return } - if ((reference.parameters[0].reference as? PhpReference)?.isCollectionType != true) { + if ((reference.parameters[0].reference as? PhpReference)?.isCollectionTypeStrict != true) { return } diff --git a/src/test/kotlin/dev/nybroe/collector/inspections/CollectFunctionOnCollectionInspectionTest.kt b/src/test/kotlin/dev/nybroe/collector/inspections/CollectFunctionOnCollectionInspectionTest.kt index d4ad32a..e1f7a4e 100644 --- a/src/test/kotlin/dev/nybroe/collector/inspections/CollectFunctionOnCollectionInspectionTest.kt +++ b/src/test/kotlin/dev/nybroe/collector/inspections/CollectFunctionOnCollectionInspectionTest.kt @@ -21,4 +21,12 @@ internal class CollectFunctionOnCollectionInspectionTest : InspectionTest() { fun testCollectOnMixedVariable() { doNotMatchTest("collect_on_mixed_variable") } + + fun testCollectOnIterableVariable() { + doNotMatchTest("collect_on_iterable_variable") + } + + fun testCollectOnUnionCollectoinType() { + doNotMatchTest("collect_on_union_collection_type") + } } diff --git a/src/test/kotlin/dev/nybroe/collector/inspections/InspectionTest.kt b/src/test/kotlin/dev/nybroe/collector/inspections/InspectionTest.kt index 8393c7c..5f4731e 100644 --- a/src/test/kotlin/dev/nybroe/collector/inspections/InspectionTest.kt +++ b/src/test/kotlin/dev/nybroe/collector/inspections/InspectionTest.kt @@ -43,6 +43,6 @@ internal abstract class InspectionTest : BaseCollectTestCase() { myFixture.enableInspections(inspection) myFixture.testHighlighting(true, false, true, file.virtualFile) - myFixture.getAllQuickFixes().forEach { myFixture.launchAction(it) } + assertEmpty(myFixture.getAllQuickFixes()) } } diff --git a/src/test/resources/inspections/CollectFunctionInCollectionInspection/nonMatches/collect_on_iterable_variable.php b/src/test/resources/inspections/CollectFunctionInCollectionInspection/nonMatches/collect_on_iterable_variable.php new file mode 100644 index 0000000..3b410f8 --- /dev/null +++ b/src/test/resources/inspections/CollectFunctionInCollectionInspection/nonMatches/collect_on_iterable_variable.php @@ -0,0 +1,13 @@ +