Skip to content

Commit

Permalink
Merge pull request #456 from phpDocumentor/fix/invalid-fqsen-define
Browse files Browse the repository at this point in the history
Fix: issue with invalid defines
  • Loading branch information
jaapio committed Oct 9, 2023
2 parents 316073f + f66a2df commit 99926d6
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 90 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"phpdocumentor/reflection-common": "^2.1",
"phpdocumentor/reflection-docblock": "^5",
"phpdocumentor/type-resolver": "^1.2",
"symfony/polyfill-php80": "^1.28",
"webmozart/assert": "^1.7"
},
"require-dev": {
Expand Down
168 changes: 84 additions & 84 deletions composer.lock

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

2 changes: 0 additions & 2 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
$rectorConfig->rule(Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector::class);
$rectorConfig->rule(Rector\TypeDeclaration\Rector\Closure\AddClosureReturnTypeRector::class);
$rectorConfig->rule(Rector\PHPUnit\Rector\Class_\AddProphecyTraitRector::class);
$rectorConfig->importNames();

// define sets of rules
Expand Down
3 changes: 1 addition & 2 deletions src/phpDocumentor/Reflection/Php/Factory/Define.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

use function assert;
use function sprintf;
use function strpos;

/**
* Strategy to convert `define` expressions to ConstantElement
Expand Down Expand Up @@ -145,7 +144,7 @@ private function fqsenFromExpression(Expr $nameString, ContextStack $context): ?

private function fqsenFromString(string $nameString): Fqsen
{
if (strpos($nameString, '\\') === false) {
if (str_starts_with($nameString, '\\') === false) {
return new Fqsen(sprintf('\\%s', $nameString));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/ProjectCreationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public function testWithGlobalConstants() : void
$this->assertArrayHasKey('\\Luigi\\OVEN_TEMPERATURE', $project->getFiles()[$fileName]->getConstants());
$this->assertArrayHasKey('\\Luigi\\MAX_OVEN_TEMPERATURE', $project->getFiles()[$fileName]->getConstants());
$this->assertArrayHasKey('\\OUTSIDE_OVEN_TEMPERATURE', $project->getFiles()[$fileName]->getConstants());
$this->assertArrayHasKey('\\Luigi_OUTSIDE_OVEN_TEMPERATURE', $project->getFiles()[$fileName]->getConstants());
$this->assertArrayHasKey('\\LuigiFoo\\_OUTSIDE_OVEN_TEMPERATURE', $project->getFiles()[$fileName]->getConstants());
}

public function testInterfaceExtends() : void
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/data/Luigi/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const OVEN_TEMPERATURE = 9001;
define('\\Luigi\\MAX_OVEN_TEMPERATURE', 9002);
define('OUTSIDE_OVEN_TEMPERATURE', 9002);
define(__NAMESPACE__ . '_OUTSIDE_OVEN_TEMPERATURE', 9002);
define(__NAMESPACE__ . 'Foo\\_OUTSIDE_OVEN_TEMPERATURE', 9002);
$v = 1;
define($v . '_OUTSIDE_OVEN_TEMPERATURE', 9002);

Expand Down

0 comments on commit 99926d6

Please sign in to comment.