Skip to content

Commit 9b9aa61

Browse files
committed
A failure in parsing an FQSEN causes the whole project to crash
In this change I catch any exception occuring during the interpretation of a file so that phpDocumentor won't stop generating documentation when a single file is corrupt or contains a critical error. The expected behaviour is that this issue is ignored, or logged, and that parsing should continue for other files.
1 parent 5e5d589 commit 9b9aa61

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/phpDocumentor/Reflection/Php/ProjectFactory.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,17 @@ public function create($name, array $files): ProjectInterface
7474
$project = new Project($name);
7575

7676
foreach ($files as $filePath) {
77-
$strategy = $this->strategies->findMatching($filePath);
78-
$file = $strategy->create($filePath, $this->strategies);
79-
$project->addFile($file);
77+
try {
78+
$strategy = $this->strategies->findMatching($filePath);
79+
$file = $strategy->create($filePath, $this->strategies);
80+
$project->addFile($file);
81+
} catch (\Exception $exception) {
82+
// TODO: Add logging
83+
// For now; silently ignore when there is an issue with a file so that
84+
// parsing continues for other files and this is not a showstopper.
85+
// The class responsible for failing also emits a log, so it should
86+
// not go unnoticed
87+
}
8088
}
8189

8290
$this->buildNamespaces($project);

tests/unit/phpDocumentor/Reflection/Php/ProjectFactoryTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,7 @@ public function testCreate()
6868
$this->assertEquals($files, $projectFilePaths);
6969
}
7070

71-
/**
72-
* @expectedException \OutOfBoundsException
73-
*/
74-
public function testCreateThrowsExceptionWhenStrategyNotFound()
71+
public function testSilentlyFailsWhenStrategyNotFound()
7572
{
7673
$projectFactory = new ProjectFactory([]);
7774
$projectFactory->create('MyProject', ['aa']);

0 commit comments

Comments
 (0)