This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Imanghafoori\LaravelMicroscope\Analyzers; |
||
4 | |||
5 | class TokenManager |
||
6 | { |
||
7 | public static function removeTokens($tokens, $from, $to, $at) |
||
8 | { |
||
9 | $refactoredTokens = []; |
||
10 | foreach ($tokens as $i => $oldToken) { |
||
11 | if ($i > $from && $i <= $to) { |
||
12 | continue; |
||
13 | } |
||
14 | |||
15 | if ($i == $at) { |
||
16 | continue; |
||
17 | } |
||
18 | $refactoredTokens[] = $oldToken; |
||
19 | } |
||
20 | |||
21 | return $refactoredTokens; |
||
22 | } |
||
23 | |||
24 | public static function getNextToken($tokens, $i) |
||
25 | { |
||
26 | $i++; |
||
27 | $token = $tokens[$i] ?? '_'; |
||
28 | while ($token[0] == T_WHITESPACE || $token[0] == T_COMMENT) { |
||
29 | $i++; |
||
30 | $token = $tokens[$i] ?? [null, null]; |
||
31 | } |
||
32 | |||
33 | return [$token, $i]; |
||
34 | } |
||
35 | |||
36 | public static function getPrevToken($tokens, $i) |
||
37 | { |
||
38 | $i--; |
||
39 | $token = $tokens[$i]; |
||
40 | while ($token[0] == T_WHITESPACE || $token[0] == T_COMMENT) { |
||
41 | $i--; |
||
42 | $token = $tokens[$i]; |
||
43 | } |
||
44 | |||
45 | return [$token, $i]; |
||
46 | } |
||
47 | |||
48 | public static function forwardTo($tokens, $i, $tokenType) |
||
49 | { |
||
50 | $i++; |
||
51 | $nextToken = $tokens[$i] ?? '_'; |
||
52 | while (! \in_array($nextToken[0], $tokenType)) { |
||
53 | $i++; |
||
54 | $nextToken = $tokens[$i] ?? [null, null]; |
||
55 | } |
||
56 | |||
57 | return [$nextToken, $i]; |
||
58 | } |
||
59 | |||
60 | public static function readBodyBack(&$tokens, $i) |
||
61 | { |
||
62 | $body = []; |
||
63 | $level = 0; |
||
64 | while (true) { |
||
65 | [$token, $i] = self::getPrevToken($tokens, $i); |
||
0 ignored issues
–
show
|
|||
66 | |||
67 | if (\in_array($token[0], [']', ')', '}'])) { |
||
0 ignored issues
–
show
|
|||
68 | $level--; |
||
69 | } |
||
70 | |||
71 | $isOpening = \in_array($token[0], ['[', '(', '{', T_CURLY_OPEN]); |
||
0 ignored issues
–
show
|
|||
72 | |||
73 | if ($level == 0 && $isOpening) { |
||
74 | break; |
||
75 | } |
||
76 | |||
77 | if ($isOpening) { |
||
78 | $level++; |
||
79 | } |
||
80 | |||
81 | $body[] = $token; |
||
0 ignored issues
–
show
|
|||
82 | } |
||
83 | |||
84 | return [$body, $i]; |
||
85 | } |
||
86 | |||
87 | public static function readBody(&$tokens, $i, $until = '}') |
||
88 | { |
||
89 | $body = []; |
||
90 | $level = 0; |
||
91 | while (true) { |
||
92 | $i++; |
||
93 | $nextToken = $tokens[$i] ?? '_'; |
||
94 | |||
95 | if ($nextToken == '_') { |
||
96 | break; |
||
97 | } |
||
98 | |||
99 | if ($level == 0 && $nextToken[0] == $until) { |
||
100 | break; |
||
101 | } |
||
102 | |||
103 | if (\in_array($nextToken[0], ['[', '(', '{', T_CURLY_OPEN])) { |
||
104 | $level++; |
||
105 | } |
||
106 | |||
107 | if (\in_array($nextToken[0], [']', ')', '}'])) { |
||
108 | $level--; |
||
109 | } |
||
110 | |||
111 | $body[] = $nextToken; |
||
112 | } |
||
113 | |||
114 | return [$body, $i]; |
||
115 | } |
||
116 | |||
117 | public static function readBackUntil(&$tokens, $i, $chars = ['}']) |
||
118 | { |
||
119 | $orphanBlock = []; |
||
120 | while (true) { |
||
121 | [$token, $i] = self::getPrevToken($tokens, $i); |
||
0 ignored issues
–
show
|
|||
122 | |||
123 | $depth = 0; |
||
124 | if (\in_array($token[0], $chars)) { |
||
0 ignored issues
–
show
|
|||
125 | [$ifBody, $openIfIndex] = self::readBodyBack($tokens, $i); |
||
0 ignored issues
–
show
The variable
$openIfIndex does not exist. Did you forget to declare it?
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug. ![]() |
|||
126 | [, $closeParenIndex] = self::getPrevToken($tokens, $openIfIndex); |
||
0 ignored issues
–
show
The variable
$closeParenIndex does not exist. Did you forget to declare it?
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug. ![]() |
|||
127 | [$condition, $openParenIndex] = self::readBodyBack($tokens, $closeParenIndex); |
||
0 ignored issues
–
show
The variable
$openParenIndex does not exist. Did you forget to declare it?
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug. ![]() |
|||
128 | [$ownerOfClosing] = self::getPrevToken($tokens, $openParenIndex); |
||
0 ignored issues
–
show
The variable
$ownerOfClosing does not exist. Did you forget to declare it?
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug. ![]() |
|||
129 | |||
130 | if ($ownerOfClosing[0] == T_IF) { |
||
131 | break; |
||
132 | } else { |
||
133 | return [null, null]; |
||
134 | } |
||
135 | } |
||
136 | |||
137 | if ($token[0] == '{') { |
||
0 ignored issues
–
show
|
|||
138 | $depth--; |
||
139 | |||
140 | if ($depth === -1) { |
||
141 | return [null, null]; |
||
142 | } |
||
143 | } |
||
144 | |||
145 | $orphanBlock[] = $token; |
||
0 ignored issues
–
show
|
|||
146 | } |
||
147 | |||
148 | return [[$ifBody, [$openIfIndex, $i]], [$condition, [$openParenIndex, $closeParenIndex]], $orphanBlock, $i]; |
||
149 | } |
||
150 | |||
151 | public static function isEqual($expectedToken, $actualToken) |
||
152 | { |
||
153 | return $expectedToken[0] == $actualToken[0] && ($expectedToken[1] ?? '') == ($actualToken[1] ?? ''); |
||
154 | } |
||
155 | } |
||
156 |
This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.
The variable may have been renamed without also renaming all references.