Skip to content

Commit 6f24218

Browse files
1023: Added phtml files support
1 parent 6228b90 commit 6f24218

File tree

3 files changed

+37
-26
lines changed

3 files changed

+37
-26
lines changed

src/com/magento/idea/magento2uct/execution/GenerateUctReportCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ public void execute() {
139139

140140
if (fileProblemsHolder.hasResults()) {
141141
if (!isModuleHeaderPrinted) {
142-
outputUtil.printModuleName(componentData.getName());
142+
outputUtil.printModuleName(componentData);
143143
isModuleHeaderPrinted = true;
144144
}
145145
outputUtil.printProblemFile(filename);
@@ -171,7 +171,7 @@ public void execute() {
171171
summary.setProcessedThemes(scanner.getThemeCount());
172172
outputUtil.printSummary(summary);
173173

174-
if (summary.getProcessedModules() == 0) {
174+
if (summary.getProcessedModules() == 0 && summary.getProcessedThemes() == 0) {
175175
process.destroyProcess();
176176
return;
177177
}

src/com/magento/idea/magento2uct/execution/output/UctReportOutputUtil.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
import com.intellij.codeInspection.ProblemDescriptor;
99
import com.magento.idea.magento2uct.bundles.UctInspectionBundle;
1010
import com.magento.idea.magento2uct.execution.process.OutputWrapper;
11+
import com.magento.idea.magento2uct.execution.scanner.data.ComponentData;
1112
import com.magento.idea.magento2uct.packages.SupportedIssue;
1213
import java.util.LinkedHashMap;
14+
import java.util.Locale;
1315
import java.util.Map;
1416
import org.jetbrains.annotations.NotNull;
1517

@@ -31,10 +33,19 @@ public UctReportOutputUtil(final @NotNull OutputWrapper output) {
3133
/**
3234
* Print module name header.
3335
*
34-
* @param moduleName String
36+
* @param componentData ComponentData
3537
*/
36-
public void printModuleName(final @NotNull String moduleName) {
37-
final String moduleNameLine = "Module Name: ".concat(moduleName);
38+
public void printModuleName(final @NotNull ComponentData componentData) {
39+
final String componentType = componentData.getType().toString();
40+
final String componentTypeFormatted = componentType
41+
.substring(0, 1)
42+
.toUpperCase(new Locale("en","EN"))
43+
.concat(componentType.substring(1));
44+
45+
final String moduleNameLine = componentTypeFormatted
46+
.concat(" Name: ")
47+
.concat(componentData.getName());
48+
3849
stdout.print("\n\n" + stdout.wrapInfo(moduleNameLine).concat("\n"));
3950
stdout.print(stdout.wrapInfo("-".repeat(moduleNameLine.length())).concat("\n"));
4051
}
@@ -81,7 +92,7 @@ public void printIssue(final @NotNull ProblemDescriptor descriptor, final int co
8192
*/
8293
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops")
8394
public void printSummary(final Summary summary) {
84-
if (summary.getProcessedModules() == 0) {
95+
if (summary.getProcessedModules() == 0 && summary.getProcessedThemes() == 0) {
8596
stdout.print(stdout.wrapInfo("Couldn't find modules to analyse").concat("\n"));
8697
return;
8798
}

src/com/magento/idea/magento2uct/inspections/UctInspectionManager.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,14 @@ public UctInspectionManager(final @NotNull Project project) {
5252
if (!(psiFile instanceof PhpFile)) {
5353
return null;
5454
}
55-
final PhpClass phpClass = GetFirstClassOfFile.getInstance().execute((PhpFile) psiFile);
56-
57-
if (phpClass == null) {
58-
return null;
59-
}
6055
final UctProblemsHolder problemsHolder = new UctProblemsHolder(
6156
InspectionManager.getInstance(project),
6257
psiFile,
6358
false
6459
);
6560
final List<PsiElementVisitor> visitors = SupportedIssue.getVisitors(problemsHolder);
6661

67-
for (final PsiElement element : collectElements(phpClass)) {
62+
for (final PsiElement element : collectElements(psiFile)) {
6863
for (final PsiElementVisitor visitor : visitors) {
6964
element.accept(visitor);
7065
}
@@ -76,26 +71,31 @@ public UctInspectionManager(final @NotNull Project project) {
7671
/**
7772
* Collect elements for PHP based inspections.
7873
*
79-
* @param phpClass PhpClass
74+
* @param psiFile PsiFile
8075
*
8176
* @return List[PsiElement]
8277
*/
83-
private List<PsiElement> collectElements(final @NotNull PhpClass phpClass) {
78+
private List<PsiElement> collectElements(final @NotNull PsiFile psiFile) {
8479
final List<PsiElement> elements = new LinkedList<>();
85-
elements.add(phpClass);
8680

87-
final PhpPsiElement scopeForUseOperator = PhpCodeInsightUtil.findScopeForUseOperator(
88-
phpClass
89-
);
90-
if (scopeForUseOperator != null) {
91-
elements.addAll(PhpCodeInsightUtil.collectImports(scopeForUseOperator));
81+
final PhpClass phpClass = GetFirstClassOfFile.getInstance().execute((PhpFile) psiFile);
82+
83+
if (phpClass != null) {
84+
elements.add(phpClass);
85+
final PhpPsiElement scopeForUseOperator = PhpCodeInsightUtil.findScopeForUseOperator(
86+
phpClass
87+
);
88+
89+
if (scopeForUseOperator != null) {
90+
elements.addAll(PhpCodeInsightUtil.collectImports(scopeForUseOperator));
91+
}
92+
elements.addAll(Arrays.asList(phpClass.getOwnFields()));
9293
}
93-
elements.addAll(PsiTreeUtil.findChildrenOfType(phpClass, ClassConstantReference.class));
94-
elements.addAll(Arrays.asList(phpClass.getOwnFields()));
95-
elements.addAll(PsiTreeUtil.findChildrenOfType(phpClass, MethodReference.class));
96-
elements.addAll(PsiTreeUtil.findChildrenOfType(phpClass, AssignmentExpression.class));
97-
elements.addAll(PsiTreeUtil.findChildrenOfType(phpClass, ClassReference.class));
98-
elements.addAll(PsiTreeUtil.findChildrenOfType(phpClass, FieldReference.class));
94+
elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, ClassConstantReference.class));
95+
elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, MethodReference.class));
96+
elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, AssignmentExpression.class));
97+
elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, ClassReference.class));
98+
elements.addAll(PsiTreeUtil.findChildrenOfType(psiFile, FieldReference.class));
9999

100100
return elements;
101101
}

0 commit comments

Comments
 (0)