Skip to content

Commit 448d229

Browse files
committed
Fix inline function ignore
Functions can be defined inline, as we are not really processing inline functions ignore them for now.
1 parent bad7c8e commit 448d229

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

src/phpDocumentor/Reflection/Php/Factory/Function_.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ final class Function_ extends AbstractFactory implements ProjectFactoryStrategy
3333
{
3434
public function matches(ContextStack $context, object $object): bool
3535
{
36-
return $object instanceof FunctionNode;
36+
return $object instanceof FunctionNode && $context->peek() instanceof FileElement;
3737
}
3838

3939
/**

tests/integration/FileDocblockTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,22 @@ public function testGlobalNamespacedFunctionDefine() : void
8383
$project->getFiles()[$fileName]->getFunctions()
8484
);
8585
}
86+
87+
/**
88+
* @covers \phpDocumentor\Reflection\Php\Factory\File::create
89+
* @covers \phpDocumentor\Reflection\Php\Factory\File::<private>
90+
*/
91+
public function testFileWithInlineFunction() : void
92+
{
93+
$fileName = __DIR__ . '/data/GlobalFiles/inline_function.php';
94+
$project = $this->fixture->create(
95+
'MyProject',
96+
[new LocalFile($fileName)]
97+
);
98+
99+
$this->assertCount(
100+
1,
101+
$project->getFiles()[$fileName]->getClasses()
102+
);
103+
}
86104
}

tests/unit/phpDocumentor/Reflection/Php/Factory/Function_Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function testMatches(): void
6363
{
6464
$this->assertFalse($this->fixture->matches(self::createContext(null), new stdClass()));
6565
$this->assertTrue($this->fixture->matches(
66-
self::createContext(null),
66+
self::createContext(null)->push(new File('hash', 'path')),
6767
$this->prophesize(\PhpParser\Node\Stmt\Function_::class)->reveal()
6868
));
6969
}

0 commit comments

Comments
 (0)