Skip to content

Commit

Permalink
ColumnWithoutAnnotationInspection: fixing NPE when use trait is tem…
Browse files Browse the repository at this point in the history
…porarily empty;
  • Loading branch information
rentalhost committed Jul 4, 2017
1 parent d7b920b commit a81ba21
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <caret>;`);

## 0.3.0: [Trigon Release](https://github.com/rentalhost/laravel-insight/releases/tag/0.3.0) - 2017-06-22

### Added
Expand All @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ class BaseModel extends Model {

class ShouldBeRemovedProgramatically extends BaseModel {
}

trait CCNullTargetReference {
use CCWillBeRemoved;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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));
}
}

0 comments on commit a81ba21

Please sign in to comment.