Skip to content

WIP Support PHPParser 4 alphas #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .phan/config.php
Original file line number Diff line number Diff line change
@@ -197,10 +197,14 @@
// A list of plugin files to execute
'plugins' => [
// NOTE: src/Phan/Language/Internal/FunctionSignatureMap.php mixes value without key as return type with values having keys deliberately.
'vendor/phan/phan/.phan/plugins/AlwaysReturnPlugin.php', // (TODO: make BlockExitStatus more reliable)
'vendor/phan/phan/.phan/plugins/DollarDollarPlugin.php',
'vendor/phan/phan/.phan/plugins/DuplicateArrayKeyPlugin.php',
'vendor/phan/phan/.phan/plugins/UnreachableCodePlugin.php', // (TODO: make BlockExitStatus more reliable)
'AlwaysReturnPlugin',
'DemoPlugin',
'DollarDollarPlugin',
'UnreachableCodePlugin',
// NOTE: src/Phan/Language/Internal/FunctionSignatureMap.php mixes value without keys (as return type) with values having keys deliberately.
'DuplicateArrayKeyPlugin',
'PregRegexCheckerPlugin',
'PrintfCheckerPlugin',
// NOTE: This plugin only produces correct results when
// Phan is run on a single core (-j1).
// 'vendor/phan/phan/.phan/plugins/UnusedSuppressionPlugin.php',
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -4,18 +4,19 @@
"keywords": ["php", "ast", "parser"],
"type": "library",
"license": "MIT",
"minimum-stability": "dev",
"prefer-stable": true,
"authors": [
{
"name": "Tyson Andre"
}
],
"require": {
"php": ">=7.1",
"nikic/PHP-Parser": "~3.1.1"
"nikic/PHP-Parser": "~4.0.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"phan/phan": "~0.10.0"
"phpunit/phpunit": "^5.7"
},
"suggest": {
"ext-ast": "~0.1.5"
352 changes: 34 additions & 318 deletions composer.lock

Large diffs are not rendered by default.

202 changes: 112 additions & 90 deletions src/ASTConverter/ASTConverter.php

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions test_files/src/namespace_short.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
namespace xyz;
foo();
3 changes: 3 additions & 0 deletions test_files/src/new.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
new stdClass();
new \stdClass;
4 changes: 4 additions & 0 deletions test_files/src/phan_test_files/encaps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
$tests = <<<TESTS
$i === $j
TESTS;
31 changes: 31 additions & 0 deletions test_files/src/php-src_tests/buf49649_2.php.TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

/**
*class Foo
*{
* private $private = 1;
*
* protected $protected = 2;
*
* public $public = 3;
*
* public $notThere = 'old';
* }
*
* echo base64_encode(serialize(new Foo()));
*
* The class above represents the serialized, base64_encoded string below.
*/
$serialized = 'TzozOiJGb28iOjQ6e3M6MTI6IgBGb28AcHJpdmF0ZSI7aToxO3M6MTI6IgAqAHByb3RlY3RlZCI7aToyO3M6NjoicHVibGljIjtpOjM7czo4OiJub3RUaGVyZSI7czozOiJvbGQiO30';

class Foo
{
private $public = null;

private $protected = null;

private $private = null;
}

$class = unserialize(base64_decode($serialized));
var_dump($class);
Binary file added test_files/src/php-src_tests/phar_oo_nosig.phar.php
Binary file not shown.
11 changes: 9 additions & 2 deletions tests/ASTConverter/ConversionTest.php
Original file line number Diff line number Diff line change
@@ -49,7 +49,11 @@ public function astValidFileExampleProvider() {
$tests = [];
$source_dir = dirname(dirname(realpath(__DIR__))) . '/test_files/src';
$paths = $this->_scanSourceDirForPHP($source_dir);
sort($paths);
$counts = [];
foreach ($paths as $path) {
$counts[$path] = \count(\token_get_all(\file_get_contents($path)));
}
usort($paths, function($a, $b) use ($counts) { return $counts[$a] <=> $counts[$b]; });
$supports40 = self::hasNativeASTSupport(40);
$supports45 = self::hasNativeASTSupport(45);
$supports50 = self::hasNativeASTSupport(50);
@@ -104,6 +108,9 @@ public static function normalizeLineNumbers(ast\Node $node) : ast\Node {

/** @dataProvider astValidFileExampleProvider */
public function testFallbackFromParser(string $file_name, int $ast_version) {
if ($ast_version === 40) {
file_put_contents('/tmp/files', "$file_name\n", FILE_APPEND);
}
$test_folder_name = basename(dirname($file_name));
if (PHP_VERSION_ID < 70100 && $test_folder_name === 'php71_or_newer') {
$this->markTestIncomplete('php-ast cannot parse php7.1 syntax when running in php7.0');
@@ -123,7 +130,7 @@ public function testFallbackFromParser(string $file_name, int $ast_version) {
}
$this->assertInstanceOf('\ast\Node', $fallback_ast, 'The fallback must also return a tree of php-ast nodes');

if ($test_folder_name === 'phan_test_files' || $test_folder_name === 'php-src_tests') {
if ($test_folder_name === 'phan_test_files' || $test_folder_name === 'php-src_tests' || $test_folder_name === 'php-src_tests2') {
$fallback_ast = self::normalizeLineNumbers($fallback_ast);
$ast = self::normalizeLineNumbers($ast);
}