Skip to content
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

Static PHP parser upgrade #34

Merged
merged 1 commit into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
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
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
Loading