Issues (197)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Analyzers/Ifs.php (12 issues)

Labels
Severity

Upgrade to new PHP Analysis Engine

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
use Imanghafoori\LaravelMicroscope\Refactors\IfElse;
6
use Imanghafoori\LaravelMicroscope\Refactors\NestedIf;
7
8
class Ifs
9
{
10
    public static function mergeIfs($tokens, $i)
11
    {
12
        $token = $tokens[$i];
13
14
        if ($token[0] !== T_IF) {
15
            return null;
16
        }
17
        $condition1 = self::readCondition($tokens, $i);
18
19
        [$char, $if1BlockStartIndex] = TokenManager::getNextToken($tokens, $condition1[2]);
0 ignored issues
show
The variable $char 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.

Loading history...
The variable $if1BlockStartIndex 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.

Loading history...
20
        // if with no curly brace.
21
        if ($char[0] == T_IF) {
22
            [$char,] = TokenManager::getNextToken($tokens, $if1BlockStartIndex);
23
            $condition2 = self::readCondition($tokens, $if1BlockStartIndex);
24
25
            $if2Body = self::readBody($tokens, $condition2[2]);
26
27
            $afterSecondIf = TokenManager::getNextToken($tokens, $if2Body[2]);
28
29
            if (T_ELSEIF !== $afterSecondIf[0][0] && T_ELSE !== $afterSecondIf[0][0]) {
30
                return NestedIf::merge($tokens, $condition1[2], $condition2[0], -1);
31
            }
32
        }
33
34
        // if with no curly brace.
35
        if ($char[0] !== '{') {
36
            return null;
37
        }
38
39
        $if2index = self::forwardTo($tokens, $if1BlockStartIndex);
40
41
        if ($tokens[$if2index][0] !== T_IF) {
42
            return null;
43
        }
44
45
        $condition2 = self::readCondition($tokens, $if2index);
46
47
        $if2Body = self::readBody($tokens, $condition2[2]);
48
        [, $if1BodyCloseIndex] = TokenManager::readBody($tokens, $if1BlockStartIndex);
0 ignored issues
show
The variable $if1BodyCloseIndex 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.

Loading history...
49
        $if1closeIndexCandid = self::forwardTo($tokens, $if2Body[2]);
50
51
        if ($if1closeIndexCandid !== $if1BodyCloseIndex) {
52
            return null;
53
        }
54
55
        $afterFirstIf = TokenManager::getNextToken($tokens, $if1BodyCloseIndex);
56
57
        if (T_ELSEIF == $afterFirstIf[0][0] || T_ELSE == $afterFirstIf[0][0]) {
58
            return null;
59
        }
60
61
        return NestedIf::merge($tokens, $condition1[2], $condition2[0], $if2Body[2]);
62
    }
63
64
    public static function else_If($tokens, $i)
65
    {
66
        $token = $tokens[$i];
67
        if ($token[0] !== T_IF) {
68
            return null;
69
        }
70
71
        $condition = self::readCondition($tokens, $i);
72
73
        $ifBody = self::readBody($tokens, $condition[2]);
74
        if (! $ifBody[0]) {
75
            return null;
76
        }
77
78
        [$afterIf, $afterIfIndex] = TokenManager::getNextToken($tokens, $ifBody[2]);
0 ignored issues
show
The variable $afterIf 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.

Loading history...
The variable $afterIfIndex 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.

Loading history...
79
80
        // in order to cover both   } else {   and   else:   syntax.
81
        if (T_ELSE !== $afterIf[0] && $tokens[$ifBody[2]][0] !== T_ELSE) {
82
            return null;
83
        }
84
85
        $elseBody = self::readBody($tokens, $afterIfIndex);
86
87
        if (! $elseBody[0]) {
88
            return null;
89
        }
90
91
        return IfElse::refactorElseIf($tokens, $ifBody, $elseBody, $condition);
92
    }
93
94
    public static function readCondition($tokens, $i)
95
    {
96
        [, $conditionStartIndex] = TokenManager::forwardTo($tokens, $i, ['(']);
0 ignored issues
show
The variable $conditionStartIndex 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.

Loading history...
97
        [$condition, $conditionCloseIndex] = TokenManager::readBody($tokens, $conditionStartIndex, ')');
0 ignored issues
show
The variable $condition 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.

Loading history...
The variable $conditionCloseIndex 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.

Loading history...
98
99
        return [$conditionStartIndex, $condition, $conditionCloseIndex];
100
    }
101
102
    private static function readBody($tokens, $afterIfIndex)
103
    {
104
        [$char, $elseBodyStartIndex] = TokenManager::getNextToken($tokens, $afterIfIndex);
0 ignored issues
show
The variable $char 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.

Loading history...
The variable $elseBodyStartIndex 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.

Loading history...
105
        // if with no curly brace.
106
        if ($char[0] !== '{') {
107
            return [null, null, null];
108
        }
109
110
        [$elseBody, $elseBodyEndIndex] = TokenManager::readBody($tokens, $elseBodyStartIndex);
0 ignored issues
show
The variable $elseBody 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.

Loading history...
The variable $elseBodyEndIndex 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.

Loading history...
111
112
        return [$elseBodyStartIndex, $elseBody, $elseBodyEndIndex];
113
    }
114
115
    private static function forwardTo($tokens, $index)
116
    {
117
        while (\in_array($tokens[++$index][0], [T_WHITESPACE, T_COMMENT, ';'])) {
118
        }
119
120
        return $index;
121
    }
122
}
123