Skip to content

Commit

Permalink
Fix inline function ignore
Browse files Browse the repository at this point in the history
Functions can be defined inline, as we are not really processing
inline functions ignore them for now.
  • Loading branch information
jaapio committed Oct 4, 2023
1 parent bad7c8e commit 448d229
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/phpDocumentor/Reflection/Php/Factory/Function_.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class Function_ extends AbstractFactory implements ProjectFactoryStrategy
{
public function matches(ContextStack $context, object $object): bool
{
return $object instanceof FunctionNode;
return $object instanceof FunctionNode && $context->peek() instanceof FileElement;
}

/**
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/FileDocblockTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,22 @@ public function testGlobalNamespacedFunctionDefine() : void
$project->getFiles()[$fileName]->getFunctions()
);
}

/**
* @covers \phpDocumentor\Reflection\Php\Factory\File::create
* @covers \phpDocumentor\Reflection\Php\Factory\File::<private>
*/
public function testFileWithInlineFunction() : void
{
$fileName = __DIR__ . '/data/GlobalFiles/inline_function.php';
$project = $this->fixture->create(
'MyProject',
[new LocalFile($fileName)]
);

$this->assertCount(
1,
$project->getFiles()[$fileName]->getClasses()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function testMatches(): void
{
$this->assertFalse($this->fixture->matches(self::createContext(null), new stdClass()));
$this->assertTrue($this->fixture->matches(
self::createContext(null),
self::createContext(null)->push(new File('hash', 'path')),
$this->prophesize(\PhpParser\Node\Stmt\Function_::class)->reveal()
));
}
Expand Down

0 comments on commit 448d229

Please sign in to comment.