Corveda / PHPSandbox

A PHP-based sandboxing library with a full suite of configuration and validation options.
https://phpsandbox.org
Other
220 stars 46 forks source link

Fix issues with closures, traits, aliases, and interfaces #27

Closed mortenson closed 2 years ago

mortenson commented 2 years ago

Just started using this project and found that traits and closures were unusable.

For traits, aliases, and interfaces, I found that the name of the trait was always passed to the visitor as Node\Identifier, not string, but included both for BC. Maybe a change in PHPParser?

For closures, the $name instanceof checks in checkFunc could never be reached because of the function's type hint.

Sorry to lump them in one PR but that's how I committed it in my fork. I've added test coverage for both cases as well. Thanks!

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

mortenson commented 2 years ago

From reviewing other GitHub issues, it looks like PHPParser was updated to v4 without moving to use Node\Identifier which is the root cause of the issue. See https://github.com/phpstan/phpstan/issues/859 for more details and https://github.com/phpstan/phpstan/pull/1008/files for an example PR.

@fieryprophet if you'd like, I can try to go through the codebase and fix more issues. The changes in this PR were done based on manual testing.