Skip to content

Commit

Permalink
fix parameter declared with name identical variable in function scope…
Browse files Browse the repository at this point in the history
… mark as unused
  • Loading branch information
nvlad committed Feb 7, 2017
1 parent f6ba7e9 commit 2a7a9eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<idea-plugin version="2">
<id>com.yii2support</id>
<name>Yii2 Support</name>
<version>0.2.10.10</version>
<version>0.2.10.11</version>
<vendor email="[email protected]" url="http://nvlad.com">NVlad</vendor>

<description><![CDATA[
Expand All @@ -26,7 +26,8 @@

<change-notes><![CDATA[
<ul>
<li>Fix work with variables used in closures</li>
<li>Fix variables used in closures mark as unused</li>
<li>Fix parameter declared with name identical variable in function scope mark as unused</li>
</ul>
]]>
</change-notes>
Expand Down
6 changes: 4 additions & 2 deletions src/com/nvlad/yii2support/views/ViewsUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.util.PsiTreeUtil;
import com.jetbrains.php.lang.parser.PhpElementTypes;
import com.jetbrains.php.lang.psi.PhpFile;
Expand Down Expand Up @@ -56,13 +57,14 @@ private static ArrayList<String> getPhpViewVariables(PsiFile psiFile) {
}
}

final SearchScope fileScope = psiFile.getUseScope();
for (Variable variable : viewVariables) {
String variableName = variable.getName();
if (variable.isDeclaration() && !(variable.getParent() instanceof PhpUseList)) {
if (variable.isDeclaration() && fileScope.equals(variable.getUseScope()) && !(variable.getParent() instanceof PhpUseList)) {
declaredVariables.add(variableName);
} else {
if (!ignoredVariables.contains(variableName)) {
if (psiFile.getUseScope().equals(variable.getUseScope()) || variable.getParent() instanceof PhpUseList) {
if (fileScope.equals(variable.getUseScope()) || variable.getParent() instanceof PhpUseList) {
if (variable.getName().equals("") && variable.getParent() instanceof StringLiteralExpression) {
Variable inlineVariable = PsiTreeUtil.findChildOfType(variable, Variable.class);
if (inlineVariable != null) {
Expand Down

0 comments on commit 2a7a9eb

Please sign in to comment.