@@ -1493,23 +1493,20 @@ public static Collection<String> getMethodParameterTypeHints(@NotNull Method met
1493
1493
*/
1494
1494
@ Nullable
1495
1495
public static String getFirstVariableTypeInScope (@ NotNull Variable variable ) {
1496
-
1497
1496
// parent search scope, eg Method else fallback to a grouped statement
1498
- PsiElement searchScope = PsiTreeUtil .getParentOfType (variable , Function .class );
1499
- if (searchScope == null ) {
1500
- searchScope = PsiTreeUtil .getParentOfType (variable , GroupStatement .class );
1501
- }
1502
-
1497
+ PhpScopeHolder searchScope = PsiTreeUtil .getParentOfType (variable , PhpScopeHolder .class );
1503
1498
if (searchScope == null ) {
1504
1499
return null ;
1505
1500
}
1506
1501
1507
1502
final String name = variable .getName ();
1508
1503
final String [] result = {null };
1509
- searchScope .acceptChildren (new PsiRecursiveElementVisitor () {
1504
+
1505
+ PhpControlFlowUtil .processFlow (searchScope .getControlFlow (), new PhpInstructionProcessor () {
1510
1506
@ Override
1511
- public void visitElement (PsiElement element ) {
1512
- if (element instanceof Variable && name .equals (((Variable ) element ).getName ())) {
1507
+ public boolean processAccessVariableInstruction (PhpAccessVariableInstruction instruction ) {
1508
+ PhpPsiElement element = instruction .getAnchor ();
1509
+ if (element instanceof Variable variableVisit && name .equals (variableVisit .getName ())) {
1513
1510
PsiElement assignmentExpression = element .getParent ();
1514
1511
if (assignmentExpression instanceof AssignmentExpression ) {
1515
1512
PhpPsiElement value = ((AssignmentExpression ) assignmentExpression ).getValue ();
@@ -1525,51 +1522,7 @@ public void visitElement(PsiElement element) {
1525
1522
}
1526
1523
}
1527
1524
1528
- super .visitElement (element );
1529
- }
1530
- });
1531
-
1532
- return result [0 ];
1533
- }
1534
-
1535
- /**
1536
- * Find first variable declaration in parent scope of a given variable:
1537
- *
1538
- * function() {
1539
- * $event = new FooEvent();
1540
- * dispatch('foo', $event);
1541
- * }
1542
- */
1543
- @ Nullable
1544
- public static PhpPsiElement getFirstVariableAssignmentInScope (@ NotNull Variable variable ) {
1545
-
1546
- // parent search scope, eg Method else fallback to a grouped statement
1547
- PsiElement searchScope = PsiTreeUtil .getParentOfType (variable , Function .class );
1548
- if (searchScope == null ) {
1549
- searchScope = PsiTreeUtil .getParentOfType (variable , GroupStatement .class );
1550
- }
1551
-
1552
- if (searchScope == null ) {
1553
- return null ;
1554
- }
1555
-
1556
- final String name = variable .getName ();
1557
- final PhpPsiElement [] result = {null };
1558
-
1559
- searchScope .acceptChildren (new PsiRecursiveElementVisitor () {
1560
- @ Override
1561
- public void visitElement (@ NotNull PsiElement element ) {
1562
- if (element instanceof Variable && name .equals (((Variable ) element ).getName ())) {
1563
- PsiElement assignmentExpression = element .getParent ();
1564
- if (assignmentExpression instanceof AssignmentExpression ) {
1565
- PhpPsiElement value = ((AssignmentExpression ) assignmentExpression ).getValue ();
1566
- if (value != null ) {
1567
- result [0 ] = value ;
1568
- }
1569
- }
1570
- }
1571
-
1572
- super .visitElement (element );
1525
+ return super .processAccessVariableInstruction (instruction );
1573
1526
}
1574
1527
});
1575
1528
0 commit comments