-
-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathContextAnalyzer.php
More file actions
61 lines (49 loc) · 1.58 KB
/
ContextAnalyzer.php
File metadata and controls
61 lines (49 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
namespace Rector\NodeNestingScope;
use PhpParser\Node;
use PhpParser\Node\Expr\NullsafePropertyFetch;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class ContextAnalyzer
{
/**
* @api
*/
public function isInLoop(Node $node): bool
{
return $node->getAttribute(AttributeKey::IS_IN_LOOP_OR_SWITCH) === true;
}
/**
* @api
*/
public function isInIf(Node $node): bool
{
return $node->getAttribute(AttributeKey::IS_IN_IF) === true;
}
public function isChangeableContext(
PropertyFetch | StaticPropertyFetch | NullsafePropertyFetch $propertyFetch
): bool {
if ($propertyFetch->getAttribute(AttributeKey::IS_UNSET_VAR, false)) {
return true;
}
if ($propertyFetch->getAttribute(AttributeKey::INSIDE_ARRAY_DIM_FETCH, false)) {
return true;
}
if ($propertyFetch->getAttribute(AttributeKey::IS_USED_AS_ARG_BY_REF_VALUE, false) === true) {
return true;
}
return $propertyFetch->getAttribute(AttributeKey::IS_INCREMENT_OR_DECREMENT, false) === true;
}
public function isLeftPartOfAssign(Node $node): bool
{
if ($node->getAttribute(AttributeKey::IS_BEING_ASSIGNED) === true) {
return true;
}
if ($node->getAttribute(AttributeKey::IS_ASSIGN_REF_EXPR) === true) {
return true;
}
return $node->getAttribute(AttributeKey::IS_ASSIGN_OP_VAR) === true;
}
}