diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cddd6a..0920350 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## 0.3.1: 2017-07-04 + +### Fixed + +* **NPE**: when `use` trait is temporarily empty (`use ;`); + ## 0.3.0: [Trigon Release](https://github.com/rentalhost/laravel-insight/releases/tag/0.3.0) - 2017-06-22 ### Added @@ -31,7 +37,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). * **NPE**: when class name identifier is absent (eg. `class {}`); -## 0.1.1 - 2017-06-01 +## 0.1.1: 2017-06-01 ### Changed diff --git a/resources-tests/laravelInsight/eloquent/ColumnWithoutAnnotationInspection.npe.php b/resources-tests/laravelInsight/eloquent/ColumnWithoutAnnotationInspection.npe.php index 5f19903..d72d690 100644 --- a/resources-tests/laravelInsight/eloquent/ColumnWithoutAnnotationInspection.npe.php +++ b/resources-tests/laravelInsight/eloquent/ColumnWithoutAnnotationInspection.npe.php @@ -9,3 +9,7 @@ class BaseModel extends Model { class ShouldBeRemovedProgramatically extends BaseModel { } + +trait CCNullTargetReference { + use CCWillBeRemoved; +} diff --git a/src/laravelInsight/eloquent/ColumnWithoutAnnotationInspection.java b/src/laravelInsight/eloquent/ColumnWithoutAnnotationInspection.java index da2c2c0..a055b1f 100644 --- a/src/laravelInsight/eloquent/ColumnWithoutAnnotationInspection.java +++ b/src/laravelInsight/eloquent/ColumnWithoutAnnotationInspection.java @@ -214,7 +214,10 @@ else if (isCastProperty && !element.isIndexed()) { public void visitPhpUse(@NotNull final PhpUse expression) { if (expression.isTraitImport()) { final PhpReference traitReferenceClass = expression.getTargetReference(); - assert traitReferenceClass != null; + + if (traitReferenceClass == null) { + return; + } final PhpClass traitContainingClass = PhpClassUtil.getTraitContainingClass(expression); assert traitContainingClass != null; diff --git a/tests/idea/laravelInsight/eloquent/ColumnWithoutAnnotationInspectionTest.java b/tests/idea/laravelInsight/eloquent/ColumnWithoutAnnotationInspectionTest.java index 2212f7d..61cc354 100644 --- a/tests/idea/laravelInsight/eloquent/ColumnWithoutAnnotationInspectionTest.java +++ b/tests/idea/laravelInsight/eloquent/ColumnWithoutAnnotationInspectionTest.java @@ -3,6 +3,7 @@ import com.intellij.psi.PsiFile; import com.jetbrains.php.lang.psi.elements.PhpClass; import com.jetbrains.php.lang.psi.elements.PhpClassMember; +import com.jetbrains.php.lang.psi.elements.PhpUse; import net.rentalhost.suite.FixtureSuite; @@ -42,5 +43,11 @@ public void testNPEs() { inspectTool(ColumnWithoutAnnotationInspection.class) .runVisitor(visitor -> visitor.visitPhpClass(fieldPrimaryKey.getContainingClass())); + + final PhpUse ccWillBeRemoved = (PhpUse) getElementByName(fileSample, "CCWillBeRemoved"); + runWriteAction(() -> ccWillBeRemoved.getChildren()[0].delete()); + + inspectTool(ColumnWithoutAnnotationInspection.class) + .runVisitor(visitor -> visitor.visitPhpUse(ccWillBeRemoved)); } }