Skip to content

Commit c7dcbad

Browse files
authored
Merge pull request #34 from aik099/static-parser-upgrade
Static PHP parser upgrade
2 parents 787ea9a + babb32a commit c7dcbad

File tree

7 files changed

+53
-22
lines changed

7 files changed

+53
-22
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"php": ">=5.6.0",
77
"console-helpers/console-kit": "^0.3",
88
"symfony/finder": "^2.8",
9-
"goaop/parser-reflection": "^1.4",
9+
"goaop/parser-reflection": "^1.4 || ^3.0 || ^4.0 || 4.0.0-RC2",
1010
"console-helpers/db-migration": "^0.1.0",
1111
"aura/sql": "^2.5 || ^3.0 || ^4.0 || ^5.0",
1212
"doctrine/cache": "^1.5",

composer.lock

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/CodeInsight/BackwardsCompatibility/Checker/ClassCheckerTest.php

+14-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\AbstractChecker;
1515
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\ClassChecker;
16+
use PhpParser\BuilderHelpers;
1617

1718
class ClassCheckerTest extends AbstractCheckerTestCase
1819
{
@@ -24,6 +25,15 @@ public function testGetName()
2425

2526
public function testCheck()
2627
{
28+
if ( class_exists(BuilderHelpers::class) ) {
29+
// The "nikic/php-parser:4.x+" doesn't prefix top level namespace classes with "\".
30+
$type_name = 'kEvent';
31+
}
32+
else {
33+
// The "nikic/php-parser:3.x" prefixes top level namespace classes with "\".
34+
$type_name = '\\kEvent';
35+
}
36+
2737
$this->assertArrayEquals(
2838
array(
2939
array(
@@ -513,13 +523,13 @@ public function testCheck()
513523
'type' => ClassChecker::TYPE_METHOD_SIGNATURE_CHANGED,
514524
'element' => 'ExampleEventHandler::OnEventSig2',
515525
'old' => '&$event',
516-
'new' => '\kEvent $event',
526+
'new' => $type_name . ' $event',
517527
),
518528
array(
519529
'type' => ClassChecker::TYPE_METHOD_SIGNATURE_CHANGED,
520530
'element' => 'ExampleEventHandler::OnEventSig3',
521531
'old' => '$event',
522-
'new' => '\kEvent $event',
532+
'new' => $type_name . ' $event',
523533
),
524534
array(
525535
'type' => ClassChecker::TYPE_METHOD_SCOPE_REDUCED,
@@ -549,13 +559,13 @@ public function testCheck()
549559
'type' => ClassChecker::TYPE_METHOD_SIGNATURE_CHANGED,
550560
'element' => 'AdminEventsHandler::OnEventSig2',
551561
'old' => '&$event',
552-
'new' => '\kEvent $event',
562+
'new' => $type_name . ' $event',
553563
),
554564
array(
555565
'type' => ClassChecker::TYPE_METHOD_SIGNATURE_CHANGED,
556566
'element' => 'AdminEventsHandler::OnEventSig3',
557567
'old' => '$event',
558-
'new' => '\kEvent $event',
568+
'new' => $type_name . ' $event',
559569
),
560570
array(
561571
'type' => ClassChecker::TYPE_METHOD_SCOPE_REDUCED,

tests/CodeInsight/KnowledgeBase/DataCollector/ClassDataCollectorTest.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ConsoleHelpers\CodeInsight\KnowledgeBase\KnowledgeBase;
1717
use Go\ParserReflection\Locator\CallableLocator;
1818
use Go\ParserReflection\ReflectionEngine;
19+
use PhpParser\BuilderHelpers;
1920
use Tests\ConsoleHelpers\CodeInsight\ProphecyToken\RegExToken;
2021

2122
class ClassDataCollectorTest extends AbstractDataCollectorTestCase
@@ -888,6 +889,15 @@ public function testClassMethodFlagChanges()
888889

889890
public function testMethodParameterChanges()
890891
{
892+
if ( class_exists(BuilderHelpers::class) ) {
893+
// The "nikic/php-parser:4.x+" doesn't prefix top level namespace classes with "\".
894+
$type_name = 'stdClass';
895+
}
896+
else {
897+
// The "nikic/php-parser:3.x" prefixes top level namespace classes with "\".
898+
$type_name = '\\stdClass';
899+
}
900+
891901
$this->initFixture('MethodParametersBefore');
892902
$this->collectData();
893903

@@ -967,7 +977,7 @@ public function testMethodParameterChanges()
967977
'Position' => '1',
968978
'TypeClass' => 'stdClass',
969979
'HasType' => '1',
970-
'TypeName' => '\\stdClass',
980+
'TypeName' => $type_name,
971981
'AllowsNull' => '0',
972982
'IsArray' => '0',
973983
'IsCallable' => '0',
@@ -1152,7 +1162,7 @@ public function testMethodParameterChanges()
11521162
'ClassId' => '1',
11531163
'Name' => 'greedyMethod',
11541164
'ParameterCount' => '8',
1155-
'RequiredParameterCount' => '6',
1165+
'RequiredParameterCount' => '4',
11561166
'Scope' => (string)ClassDataCollector::SCOPE_PUBLIC,
11571167
'IsAbstract' => '0',
11581168
'IsFinal' => '0',
@@ -1188,7 +1198,7 @@ public function testMethodParameterChanges()
11881198
'Position' => '0',
11891199
'TypeClass' => 'stdClass',
11901200
'HasType' => '1',
1191-
'TypeName' => '\\stdClass',
1201+
'TypeName' => $type_name,
11921202
'AllowsNull' => '0',
11931203
'IsArray' => '0',
11941204
'IsCallable' => '0',
@@ -1264,7 +1274,7 @@ public function testMethodParameterChanges()
12641274
'AllowsNull' => '1',
12651275
'IsArray' => '0',
12661276
'IsCallable' => '0',
1267-
'IsOptional' => '0',
1277+
'IsOptional' => '1',
12681278
'IsVariadic' => '0',
12691279
'CanBePassedByValue' => '1',
12701280
'IsPassedByReference' => '0',
@@ -1282,12 +1292,12 @@ public function testMethodParameterChanges()
12821292
'AllowsNull' => '1',
12831293
'IsArray' => '0',
12841294
'IsCallable' => '0',
1285-
'IsOptional' => '0',
1295+
'IsOptional' => '1',
12861296
'IsVariadic' => '0',
12871297
'CanBePassedByValue' => '0',
12881298
'IsPassedByReference' => '1',
1289-
'HasDefaultValue' => '0',
1290-
'DefaultValue' => null,
1299+
'HasDefaultValue' => '1',
1300+
'DefaultValue' => 'true',
12911301
'DefaultConstant' => null,
12921302
),
12931303
array(

tests/CodeInsight/KnowledgeBase/DataCollector/FunctionDataCollectorTest.php

+17-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use ConsoleHelpers\CodeInsight\KnowledgeBase\DataCollector\AbstractDataCollector;
1515
use ConsoleHelpers\CodeInsight\KnowledgeBase\DataCollector\FunctionDataCollector;
16+
use PhpParser\BuilderHelpers;
1617

1718
class FunctionDataCollectorTest extends AbstractDataCollectorTestCase
1819
{
@@ -176,6 +177,15 @@ public function testFunctionFlagChanges()
176177

177178
public function testFunctionParameterChanges()
178179
{
180+
if ( class_exists(BuilderHelpers::class) ) {
181+
// The "nikic/php-parser:4.x+" doesn't prefix top level namespace classes with "\".
182+
$type_name = 'stdClass';
183+
}
184+
else {
185+
// The "nikic/php-parser:3.x" prefixes top level namespace classes with "\".
186+
$type_name = '\\stdClass';
187+
}
188+
179189
$this->initFixture('FunctionParametersBefore');
180190
$this->collectData();
181191

@@ -233,7 +243,7 @@ public function testFunctionParameterChanges()
233243
'Position' => '1',
234244
'TypeClass' => 'stdClass',
235245
'HasType' => '1',
236-
'TypeName' => '\\stdClass',
246+
'TypeName' => $type_name,
237247
'AllowsNull' => '0',
238248
'IsArray' => '0',
239249
'IsCallable' => '0',
@@ -404,7 +414,7 @@ public function testFunctionParameterChanges()
404414
'FileId' => '1',
405415
'Name' => 'greedyFunction',
406416
'ParameterCount' => '8',
407-
'RequiredParameterCount' => '6',
417+
'RequiredParameterCount' => '4',
408418
'IsVariadic' => '0',
409419
'ReturnsReference' => '0',
410420
'HasReturnType' => '0',
@@ -432,7 +442,7 @@ public function testFunctionParameterChanges()
432442
'Position' => '0',
433443
'TypeClass' => 'stdClass',
434444
'HasType' => '1',
435-
'TypeName' => '\\stdClass',
445+
'TypeName' => $type_name,
436446
'AllowsNull' => '0',
437447
'IsArray' => '0',
438448
'IsCallable' => '0',
@@ -508,7 +518,7 @@ public function testFunctionParameterChanges()
508518
'AllowsNull' => '1',
509519
'IsArray' => '0',
510520
'IsCallable' => '0',
511-
'IsOptional' => '0',
521+
'IsOptional' => '1',
512522
'IsVariadic' => '0',
513523
'CanBePassedByValue' => '1',
514524
'IsPassedByReference' => '0',
@@ -526,12 +536,12 @@ public function testFunctionParameterChanges()
526536
'AllowsNull' => '1',
527537
'IsArray' => '0',
528538
'IsCallable' => '0',
529-
'IsOptional' => '0',
539+
'IsOptional' => '1',
530540
'IsVariadic' => '0',
531541
'CanBePassedByValue' => '0',
532542
'IsPassedByReference' => '1',
533-
'HasDefaultValue' => '0',
534-
'DefaultValue' => null,
543+
'HasDefaultValue' => '1',
544+
'DefaultValue' => 'true',
535545
'DefaultConstant' => null,
536546
),
537547
array(

tests/CodeInsight/KnowledgeBase/DataCollector/fixtures/ClassDataCollector/MethodParametersAfter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function greedyMethod(
99
callable $param_three,
1010
string $param_four,
1111
$param_five = 'def',
12-
&$param_six,
12+
&$param_six = true,
1313
$param_seven = null,
1414
$param_eight = PHP_EOL
1515
) {

tests/CodeInsight/KnowledgeBase/DataCollector/fixtures/FunctionDataCollector/FunctionParametersAfter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function greedyFunction(
66
callable $param_three,
77
string $param_four,
88
$param_five = 'def',
9-
&$param_six,
9+
&$param_six = true,
1010
$param_seven = null,
1111
$param_eight = PHP_EOL
1212
) {

0 commit comments

Comments
 (0)