Issues (49)

Security Analysis    no request data  

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/Grammar/Symbol.php (2 issues)

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
 * This file is part of PHP-Yacc package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace PhpYacc\Grammar;
11
12
use PhpYacc\Exception\LogicException;
13
use PhpYacc\Yacc\Production;
14
15
/**
16
 * Class Symbol.
17
 *
18
 * @property null|Symbol $type
19
 * @property mixed $value
20
 * @property int $precedence
21
 * @property int $associativity
22
 * @property string $name
23
 * @property int $terminal
24
 */
25
class Symbol
26
{
27
    const UNDEF = 0;
28
    const LEFT = 1;
29
    const RIGHT = 2;
30
    const NON = 3;
31
    const MASK = 3;
32
    const TERMINAL = 0x100;
33
    const NON_TERMINAL = 0x200;
34
35
    /**
36
     * @var int
37
     */
38
    public $code;
39
40
    /**
41
     * @var null|Symbol
42
     */
43
    protected $_type;
44
45
    /**
46
     * @var mixed
47
     */
48
    protected $_value;
49
50
    /**
51
     * @var int
52
     */
53
    protected $_precedence;
54
55
    /**
56
     * @var int
57
     */
58
    protected $_associativity;
59
60
    /**
61
     * @var string
62
     */
63
    protected $_name;
64
65
    /**
66
     * @var bool
67
     */
68
    public $isTerminal = false;
69
70
    /**
71
     * @var bool
72
     */
73
    public $isnonterminal = false;
74
75
    /**
76
     * @var int
77
     */
78
    protected $_terminal = self::UNDEF;
79
80
    /**
81
     * Symbol constructor.
82
     *
83
     * @param int         $code
84
     * @param string      $name
85
     * @param null        $value
86
     * @param int         $terminal
87
     * @param int         $precedence
88
     * @param int         $associativity
89
     * @param Symbol|null $type
90
     *
91
     * @throws LogicException
92
     */
93
    public function __construct(int $code, string $name, $value = null, int $terminal = self::UNDEF, int $precedence = self::UNDEF, int $associativity = self::UNDEF, self $type = null)
94
    {
95
        $this->code = $code;
96
        $this->_name = $name;
97
        $this->_value = $value;
98
        $this->setTerminal($terminal);
99
        $this->_precedence = $precedence;
100
        $this->_associativity = $associativity;
101
        $this->_type = $type;
0 ignored issues
show
Documentation Bug introduced by
It seems like $type can also be of type object<self>. However, the property $_type is declared as type null|object<PhpYacc\Grammar\Symbol>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
102
    }
103
104
    /**
105
     * @return bool
106
     */
107
    public function isNilSymbol(): bool
108
    {
109
        return $this->_terminal === self::UNDEF;
110
    }
111
112
    /**
113
     * @param $name
114
     *
115
     * @return mixed
116
     */
117
    public function __get($name)
118
    {
119
        return $this->{'_'.$name};
120
    }
121
122
    /**
123
     * @param $name
124
     * @param $value
125
     */
126
    public function __set($name, $value)
127
    {
128
        $this->{'set'.$name}($value);
129
    }
130
131
    /**
132
     * @param int $terminal
133
     *
134
     * @throws LogicException
135
     */
136
    public function setTerminal(int $terminal)
137
    {
138
        $this->_terminal = $terminal;
139
        if ($terminal === self::TERMINAL) {
140
            $this->isTerminal = true;
141
            $this->isnonterminal = false;
142
        } elseif ($terminal === self::NON_TERMINAL) {
143
            $this->isTerminal = false;
144
            $this->isnonterminal = true;
145
        } else {
146
            $this->isTerminal = false;
147
            $this->isnonterminal = false;
148
        }
149
        $this->setValue($this->_value); // force check to prevent issues
150
    }
151
152
    /**
153
     * @param int $associativity
154
     */
155
    public function setAssociativity(int $associativity)
156
    {
157
        $this->_associativity = $associativity;
158
    }
159
160
    /**
161
     * @param int $precedence
162
     */
163
    public function setPrecedence(int $precedence)
164
    {
165
        $this->_precedence = $precedence;
166
    }
167
168
    /**
169
     * @param $value
170
     *
171
     * @throws LogicException
172
     */
173
    public function setValue($value)
174
    {
175
        if ($this->isTerminal && !is_int($value)) {
176
            throw new LogicException('Terminals value must be an integer, '.\gettype($value).' provided');
177
        } elseif ($this->isnonterminal && !($value instanceof Production || $value === null)) {
178
            throw new LogicException('NonTerminals value must be a production, '.\gettype($value).' provided');
179
        }
180
        $this->_value = $value;
181
    }
182
183
    /**
184
     * @param Symbol|null $type
185
     */
186
    public function setType(self $type = null)
187
    {
188
        $this->_type = $type;
0 ignored issues
show
Documentation Bug introduced by
It seems like $type can also be of type object<self>. However, the property $_type is declared as type null|object<PhpYacc\Grammar\Symbol>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
189
    }
190
191
    /**
192
     * @param int $flag
193
     */
194
    public function setAssociativityFlag(int $flag)
195
    {
196
        $this->_associativity |= $flag;
197
    }
198
}
199