Skip to content

Commit

Permalink
Fix NPE in NamespaceAndUseStatementCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
pynicolas committed Nov 5, 2015
1 parent c021ab3 commit 1e9a351
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,11 @@ public void visitScript(ScriptTree tree) {
nextStatement = statements.get(i + 1);
statements.get(i).accept(this);
}

nextStatement = null;
statements.get(nbStatements - 1).accept(this);

}


@Override
public void visitNamespaceStatement(NamespaceStatementTree tree) {
if (check.hasNamespaceBlankLine && nextStatement != null && !isFollowedWithBlankLine(tree)) {
if (check.hasNamespaceBlankLine && !isFollowedWithBlankLine(tree)) {
String message = String.format(
BLANK_LINE_NAMESPACE_MESSAGE,
tree.namespaceName() == null ? "" : " " + tree.namespaceName().fullName());
Expand All @@ -90,7 +85,7 @@ public void visitNamespaceStatement(NamespaceStatementTree tree) {
public void visitUseStatement(UseStatementTree tree) {
useStatements.add(tree);

if (nextStatement != null && !nextStatement.is(USE_KINDS)) {
if (!nextStatement.is(USE_KINDS)) {
checkUsesAreBeforeNamespace();
checkBlankLineAfterUses(tree);
useStatements.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ public void custom() throws Exception {
deactivateAll();
PHPCheckTest.check(check, TestUtils.getCheckFile(TEST_DIR + "NamespaceAndUseStatementCheck.php"), ImmutableList.<Issue>of());
}

@Test
public void emptyScript() throws Exception {
activeOnly("hasNamespaceBlankLine", "isUseAfterNamespace", "hasUseBlankLine");
PHPCheckTest.check(check, TestUtils.getCheckFile(TEST_DIR + "empty-script.php"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<?php

0 comments on commit 1e9a351

Please sign in to comment.