Skip to content

Commit 7f427a1

Browse files
mousetrapsfelixfbecker
authored andcommitted
Adopt Microsoft/tolerant-php-parser (felixfbecker#357)
1 parent 08cf1a3 commit 7f427a1

File tree

194 files changed

+6450
-1483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

194 files changed

+6450
-1483
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ vendor/
55
.phpls/
66
composer.lock
77
stubs
8+
*.ast

.gitmodules

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[submodule "validation/frameworks/php-language-server"]
2+
path = validation/frameworks/php-language-server
3+
url = https://github.com/felixfbecker/php-language-server
4+
[submodule "validation/frameworks/wordpress"]
5+
path = validation/frameworks/wordpress
6+
url = https://github.com/wordpress/wordpress
7+
[submodule "validation/frameworks/drupal"]
8+
path = validation/frameworks/drupal
9+
url = https://github.com/drupal/drupal
10+
[submodule "validation/frameworks/tolerant-php-parser"]
11+
path = validation/frameworks/tolerant-php-parser
12+
url = https://github.com/microsoft/tolerant-php-parser
13+
[submodule "validation/frameworks/symfony"]
14+
path = validation/frameworks/symfony
15+
url = https://github.com/symfony/symfony
16+
[submodule "validation/frameworks/math-php"]
17+
path = validation/frameworks/math-php
18+
url = https://github.com/markrogoyski/math-php
19+
[submodule "validation/frameworks/codeigniter"]
20+
path = validation/frameworks/codeigniter
21+
url = https://github.com/bcit-ci/codeigniter
22+
[submodule "validation/frameworks/cakephp"]
23+
path = validation/frameworks/cakephp
24+
url = https://github.com/cakephp/cakephp
25+
[submodule "validation/frameworks/phpunit"]
26+
path = validation/frameworks/phpunit
27+
url = https://github.com/sebastianbergmann/phpunit

Performance.php

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
namespace LanguageServer\Tests;
4+
require __DIR__ . '/vendor/autoload.php';
5+
6+
use Exception;
7+
use LanguageServer\Index\Index;
8+
use LanguageServer\PhpDocument;
9+
use LanguageServer\DefinitionResolver;
10+
use Microsoft\PhpParser;
11+
use phpDocumentor\Reflection\DocBlockFactory;
12+
use RecursiveDirectoryIterator;
13+
use RecursiveIteratorIterator;
14+
15+
$totalSize = 0;
16+
17+
$frameworks = ["drupal", "wordpress", "php-language-server", "tolerant-php-parser", "math-php", "symfony", "CodeIgniter", "cakephp"];
18+
19+
foreach($frameworks as $framework) {
20+
$iterator = new RecursiveDirectoryIterator(__DIR__ . "/validation/frameworks/$framework");
21+
$testProviderArray = array();
22+
23+
foreach (new RecursiveIteratorIterator($iterator) as $file) {
24+
if (strpos((string)$file, ".php") !== false) {
25+
$totalSize += $file->getSize();
26+
$testProviderArray[] = $file->getPathname();
27+
}
28+
}
29+
30+
if (count($testProviderArray) === 0) {
31+
throw new Exception("ERROR: Validation testsuite frameworks not found - run `git submodule update --init --recursive` to download.");
32+
}
33+
34+
$start = microtime(true);
35+
36+
foreach ($testProviderArray as $idx => $testCaseFile) {
37+
if (filesize($testCaseFile) > 10000) {
38+
continue;
39+
}
40+
if ($idx % 1000 === 0) {
41+
echo "$idx\n";
42+
}
43+
44+
$fileContents = file_get_contents($testCaseFile);
45+
46+
$docBlockFactory = DocBlockFactory::createInstance();
47+
$index = new Index;
48+
$maxRecursion = [];
49+
$definitions = [];
50+
51+
$definitionResolver = new DefinitionResolver($index);
52+
$parser = new PhpParser\Parser();
53+
54+
try {
55+
$document = new PhpDocument($testCaseFile, $fileContents, $index, $parser, $docBlockFactory, $definitionResolver);
56+
} catch (\Throwable $e) {
57+
continue;
58+
}
59+
}
60+
61+
echo "------------------------------\n";
62+
63+
echo "Time [$framework]: " . (microtime(true) - $start) . PHP_EOL;
64+
}
65+

composer.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
},
2929
"require": {
3030
"php": ">=7.0",
31-
"nikic/php-parser": "^3.0.5",
3231
"phpdocumentor/reflection-docblock": "^3.0",
3332
"sabre/event": "^5.0",
3433
"felixfbecker/advanced-json-rpc": "^2.0",
@@ -38,7 +37,8 @@
3837
"webmozart/glob": "^4.1",
3938
"sabre/uri": "^2.0",
4039
"jetbrains/phpstorm-stubs": "dev-master",
41-
"composer/composer": "^1.3"
40+
"composer/composer": "^1.3",
41+
"Microsoft/tolerant-php-parser": "^0.0.2"
4242
},
4343
"minimum-stability": "dev",
4444
"prefer-stable": true,
@@ -47,7 +47,9 @@
4747
"LanguageServer\\": "src/"
4848
},
4949
"files" : [
50-
"src/utils.php"
50+
"src/utils.php",
51+
"src/FqnUtilities.php",
52+
"src/ParserHelpers.php"
5153
]
5254
},
5355
"autoload-dev": {

phpcs.xml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<ruleset name="PHP Language Server">
33
<file>src</file>
44
<file>tests</file>
5+
<exclude-pattern>tests/Validation/cases</exclude-pattern>
56
<rule ref="PSR2">
67
<exclude name="PSR2.Namespaces.UseDeclaration.MultipleDeclarations"/>
78
<exclude name="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed"/>

phpunit.xml.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
</whitelist>
1313
</filter>
1414
<php>
15-
<ini name="memory_limit" value="256M"/>
15+
<ini name="memory_limit" value="1024M"/>
1616
</php>
1717
</phpunit>

0 commit comments

Comments
 (0)