Skip to content

Commit

Permalink
Fix higher order type provider crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Nybroe committed Oct 12, 2021
1 parent bce380f commit a9c20ac
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
# collections-intellij Changelog

## [Unreleased]
### Fixed
- Fixed recursive collection on variables with no types
- Fix higher order type provider when no types are possible

## [0.3.3]
### Fixed
### Fixed
- Fixed recursive collection on std class

## [0.3.2]
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

pluginGroup = dev.nybroe.collector
pluginName = Collector
pluginVersion = 0.3.3
pluginVersion = 0.3.4

# See https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
# for insight into build numbers and IntelliJ Platform versions.
Expand Down
6 changes: 5 additions & 1 deletion src/main/kotlin/dev/nybroe/collector/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ fun PhpType.isCollection(project: Project): Boolean {
}

fun PhpType.isCollectionStrict(project: Project): Boolean {
return this.types.all { PhpType().add(it).isCollection(project) }
if (this.types.isEmpty()) {
return false
}

return this.types.none { !PhpType().add(it).isCollection(project) }
}

fun PhpType.isHigherOrderCollection(project: Project): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class HigherOrderTypeProvider : PhpTypeProvider4 {
val type = PhpIndex.getInstance(project)
.getBySignature(signature.split('|')[0])
.map { it.type }
.reduce { acc, phpType -> acc.add(phpType) }
.global(project)
.reduceOrNull { acc, phpType -> acc.add(phpType) }
?.global(project)

if (type === null) return null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ internal class CollectFunctionOnCollectionInspectionTest : InspectionTest() {
doNotMatchTest("collect_on_union_collection_type")
}

fun testCollectionOnStdObject_property() {
fun testCollectionOnStdObjectProperty() {
doNotMatchTest("collect_on_stdClass_property")
}

fun testCollectionOnNoTypeVariable() {
doNotMatchTest("collect_on_no_type_variable")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php

function($variable) {
collect($variable);
}

0 comments on commit a9c20ac

Please sign in to comment.