Skip to content

Commit

Permalink
Merge pull request #34 from aik099/static-parser-upgrade
Browse files Browse the repository at this point in the history
Static PHP parser upgrade
  • Loading branch information
aik099 authored Jul 9, 2024
2 parents 787ea9a + babb32a commit c7dcbad
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 22 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"php": ">=5.6.0",
"console-helpers/console-kit": "^0.3",
"symfony/finder": "^2.8",
"goaop/parser-reflection": "^1.4",
"goaop/parser-reflection": "^1.4 || ^3.0 || ^4.0 || 4.0.0-RC2",
"console-helpers/db-migration": "^0.1.0",
"aura/sql": "^2.5 || ^3.0 || ^4.0 || ^5.0",
"doctrine/cache": "^1.5",
Expand Down
3 changes: 2 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\AbstractChecker;
use ConsoleHelpers\CodeInsight\BackwardsCompatibility\Checker\ClassChecker;
use PhpParser\BuilderHelpers;

class ClassCheckerTest extends AbstractCheckerTestCase
{
Expand All @@ -24,6 +25,15 @@ public function testGetName()

public function testCheck()
{
if ( class_exists(BuilderHelpers::class) ) {
// The "nikic/php-parser:4.x+" doesn't prefix top level namespace classes with "\".
$type_name = 'kEvent';
}
else {
// The "nikic/php-parser:3.x" prefixes top level namespace classes with "\".
$type_name = '\\kEvent';
}

$this->assertArrayEquals(
array(
array(
Expand Down Expand Up @@ -513,13 +523,13 @@ public function testCheck()
'type' => ClassChecker::TYPE_METHOD_SIGNATURE_CHANGED,
'element' => 'ExampleEventHandler::OnEventSig2',
'old' => '&$event',
'new' => '\kEvent $event',
'new' => $type_name . ' $event',
),
array(
'type' => ClassChecker::TYPE_METHOD_SIGNATURE_CHANGED,
'element' => 'ExampleEventHandler::OnEventSig3',
'old' => '$event',
'new' => '\kEvent $event',
'new' => $type_name . ' $event',
),
array(
'type' => ClassChecker::TYPE_METHOD_SCOPE_REDUCED,
Expand Down Expand Up @@ -549,13 +559,13 @@ public function testCheck()
'type' => ClassChecker::TYPE_METHOD_SIGNATURE_CHANGED,
'element' => 'AdminEventsHandler::OnEventSig2',
'old' => '&$event',
'new' => '\kEvent $event',
'new' => $type_name . ' $event',
),
array(
'type' => ClassChecker::TYPE_METHOD_SIGNATURE_CHANGED,
'element' => 'AdminEventsHandler::OnEventSig3',
'old' => '$event',
'new' => '\kEvent $event',
'new' => $type_name . ' $event',
),
array(
'type' => ClassChecker::TYPE_METHOD_SCOPE_REDUCED,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use ConsoleHelpers\CodeInsight\KnowledgeBase\KnowledgeBase;
use Go\ParserReflection\Locator\CallableLocator;
use Go\ParserReflection\ReflectionEngine;
use PhpParser\BuilderHelpers;
use Tests\ConsoleHelpers\CodeInsight\ProphecyToken\RegExToken;

class ClassDataCollectorTest extends AbstractDataCollectorTestCase
Expand Down Expand Up @@ -888,6 +889,15 @@ public function testClassMethodFlagChanges()

public function testMethodParameterChanges()
{
if ( class_exists(BuilderHelpers::class) ) {
// The "nikic/php-parser:4.x+" doesn't prefix top level namespace classes with "\".
$type_name = 'stdClass';
}
else {
// The "nikic/php-parser:3.x" prefixes top level namespace classes with "\".
$type_name = '\\stdClass';
}

$this->initFixture('MethodParametersBefore');
$this->collectData();

Expand Down Expand Up @@ -967,7 +977,7 @@ public function testMethodParameterChanges()
'Position' => '1',
'TypeClass' => 'stdClass',
'HasType' => '1',
'TypeName' => '\\stdClass',
'TypeName' => $type_name,
'AllowsNull' => '0',
'IsArray' => '0',
'IsCallable' => '0',
Expand Down Expand Up @@ -1152,7 +1162,7 @@ public function testMethodParameterChanges()
'ClassId' => '1',
'Name' => 'greedyMethod',
'ParameterCount' => '8',
'RequiredParameterCount' => '6',
'RequiredParameterCount' => '4',
'Scope' => (string)ClassDataCollector::SCOPE_PUBLIC,
'IsAbstract' => '0',
'IsFinal' => '0',
Expand Down Expand Up @@ -1188,7 +1198,7 @@ public function testMethodParameterChanges()
'Position' => '0',
'TypeClass' => 'stdClass',
'HasType' => '1',
'TypeName' => '\\stdClass',
'TypeName' => $type_name,
'AllowsNull' => '0',
'IsArray' => '0',
'IsCallable' => '0',
Expand Down Expand Up @@ -1264,7 +1274,7 @@ public function testMethodParameterChanges()
'AllowsNull' => '1',
'IsArray' => '0',
'IsCallable' => '0',
'IsOptional' => '0',
'IsOptional' => '1',
'IsVariadic' => '0',
'CanBePassedByValue' => '1',
'IsPassedByReference' => '0',
Expand All @@ -1282,12 +1292,12 @@ public function testMethodParameterChanges()
'AllowsNull' => '1',
'IsArray' => '0',
'IsCallable' => '0',
'IsOptional' => '0',
'IsOptional' => '1',
'IsVariadic' => '0',
'CanBePassedByValue' => '0',
'IsPassedByReference' => '1',
'HasDefaultValue' => '0',
'DefaultValue' => null,
'HasDefaultValue' => '1',
'DefaultValue' => 'true',
'DefaultConstant' => null,
),
array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use ConsoleHelpers\CodeInsight\KnowledgeBase\DataCollector\AbstractDataCollector;
use ConsoleHelpers\CodeInsight\KnowledgeBase\DataCollector\FunctionDataCollector;
use PhpParser\BuilderHelpers;

class FunctionDataCollectorTest extends AbstractDataCollectorTestCase
{
Expand Down Expand Up @@ -176,6 +177,15 @@ public function testFunctionFlagChanges()

public function testFunctionParameterChanges()
{
if ( class_exists(BuilderHelpers::class) ) {
// The "nikic/php-parser:4.x+" doesn't prefix top level namespace classes with "\".
$type_name = 'stdClass';
}
else {
// The "nikic/php-parser:3.x" prefixes top level namespace classes with "\".
$type_name = '\\stdClass';
}

$this->initFixture('FunctionParametersBefore');
$this->collectData();

Expand Down Expand Up @@ -233,7 +243,7 @@ public function testFunctionParameterChanges()
'Position' => '1',
'TypeClass' => 'stdClass',
'HasType' => '1',
'TypeName' => '\\stdClass',
'TypeName' => $type_name,
'AllowsNull' => '0',
'IsArray' => '0',
'IsCallable' => '0',
Expand Down Expand Up @@ -404,7 +414,7 @@ public function testFunctionParameterChanges()
'FileId' => '1',
'Name' => 'greedyFunction',
'ParameterCount' => '8',
'RequiredParameterCount' => '6',
'RequiredParameterCount' => '4',
'IsVariadic' => '0',
'ReturnsReference' => '0',
'HasReturnType' => '0',
Expand Down Expand Up @@ -432,7 +442,7 @@ public function testFunctionParameterChanges()
'Position' => '0',
'TypeClass' => 'stdClass',
'HasType' => '1',
'TypeName' => '\\stdClass',
'TypeName' => $type_name,
'AllowsNull' => '0',
'IsArray' => '0',
'IsCallable' => '0',
Expand Down Expand Up @@ -508,7 +518,7 @@ public function testFunctionParameterChanges()
'AllowsNull' => '1',
'IsArray' => '0',
'IsCallable' => '0',
'IsOptional' => '0',
'IsOptional' => '1',
'IsVariadic' => '0',
'CanBePassedByValue' => '1',
'IsPassedByReference' => '0',
Expand All @@ -526,12 +536,12 @@ public function testFunctionParameterChanges()
'AllowsNull' => '1',
'IsArray' => '0',
'IsCallable' => '0',
'IsOptional' => '0',
'IsOptional' => '1',
'IsVariadic' => '0',
'CanBePassedByValue' => '0',
'IsPassedByReference' => '1',
'HasDefaultValue' => '0',
'DefaultValue' => null,
'HasDefaultValue' => '1',
'DefaultValue' => 'true',
'DefaultConstant' => null,
),
array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function greedyMethod(
callable $param_three,
string $param_four,
$param_five = 'def',
&$param_six,
&$param_six = true,
$param_seven = null,
$param_eight = PHP_EOL
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function greedyFunction(
callable $param_three,
string $param_four,
$param_five = 'def',
&$param_six,
&$param_six = true,
$param_seven = null,
$param_eight = PHP_EOL
) {
Expand Down

0 comments on commit c7dcbad

Please sign in to comment.