Skip to content

Commit

Permalink
Fixed type detection recognizing mixed as a collection
Browse files Browse the repository at this point in the history
  • Loading branch information
olivernybroe committed Nov 25, 2020
1 parent 2d5623d commit e3a0b8d
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
### Removed

### Fixed
- Fixed type detection recognizing `mixed` as a collection.

### Security

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.0.1-EAP.12
pluginVersion = 0.0.1-EAP.13
pluginSinceBuild = 202
pluginUntilBuild =

Expand Down
11 changes: 10 additions & 1 deletion src/main/kotlin/dev/nybroe/collector/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,14 @@ val Function.isShortArrowFunction: Boolean
get() = FunctionImpl.isShortArrowFunction(this)

fun PhpType.isCollection(project: Project): Boolean {
return collectionType.isConvertibleFrom(this, PhpIndex.getInstance(project))
val filteredType = this.filterMixed()

if (filteredType.isEmpty) {
return false
}

return collectionType.isConvertibleFrom(
filteredType,
PhpIndex.getInstance(project)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@ internal class CollectFunctionOnCollectionInspectionTest : InspectionTest() {
fun testCollectOnEloquentCollectVariable() {
doTest("collect_on_eloquent_collect_variable")
}

fun testCollectOnMixedVariable() {
doNotMatchTest("collect_on_mixed_variable")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

/** @var mixed|array $var */
$var = [];

collect($var);

0 comments on commit e3a0b8d

Please sign in to comment.