Skip to content

Commit 13fe5b8

Browse files
committed
Simplify public interface
1 parent f936a0c commit 13fe5b8

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

packages/guides-cli/src/Command/Serve.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
use phpDocumentor\Guides\Nodes\DocumentNode;
2929
use phpDocumentor\Guides\RenderContext;
3030
use phpDocumentor\Guides\Renderer\DocumentListIterator;
31-
use phpDocumentor\Guides\Renderer\DocumentTreeIterator;
3231
use Symfony\Component\Console\Command\Command;
3332
use Symfony\Component\Console\Input\InputInterface;
3433
use Symfony\Component\Console\Input\InputOption;
@@ -152,11 +151,8 @@ function (FileModifiedEvent $event) use ($documents, $sourceFileSystem, $project
152151
$documents = $this->commandBus->handle(new CompileDocumentsCommand($documents, new CompilerContext($projectNode)));
153152
$destinationFileSystem = FlySystemAdapter::createForPath($settings->getOutput());
154153

155-
$documentIterator = new DocumentListIterator(
156-
new DocumentTreeIterator(
157-
[$projectNode->getRootDocumentEntry()],
158-
$documents,
159-
),
154+
$documentIterator = DocumentListIterator::create(
155+
$projectNode->getRootDocumentEntry(),
160156
$documents,
161157
);
162158

packages/guides/src/Handlers/RenderCommand.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use phpDocumentor\Guides\Nodes\DocumentNode;
1919
use phpDocumentor\Guides\Nodes\ProjectNode;
2020
use phpDocumentor\Guides\Renderer\DocumentListIterator;
21-
use phpDocumentor\Guides\Renderer\DocumentTreeIterator;
2221

2322
final class RenderCommand
2423
{
@@ -33,11 +32,8 @@ public function __construct(
3332
private readonly ProjectNode $projectNode,
3433
private readonly string $destinationPath = '/',
3534
) {
36-
$this->documentIterator = new DocumentListIterator(
37-
new DocumentTreeIterator(
38-
[$this->projectNode->getRootDocumentEntry()],
39-
$this->documentArray,
40-
),
35+
$this->documentIterator = DocumentListIterator::create(
36+
$this->projectNode->getRootDocumentEntry(),
4137
$this->documentArray,
4238
);
4339
}

packages/guides/src/Renderer/DocumentListIterator.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Iterator;
1919
use OutOfRangeException;
2020
use phpDocumentor\Guides\Nodes\DocumentNode;
21+
use phpDocumentor\Guides\Nodes\DocumentTree\DocumentEntryNode;
2122
use RecursiveIteratorIterator;
2223
use WeakMap;
2324
use WeakReference;
@@ -60,6 +61,17 @@ public function __construct(
6061
}
6162
}
6263

64+
public static function create(DocumentEntryNode $getRootDocumentEntry, array $documentArray): self
65+
{
66+
return new self(
67+
new DocumentTreeIterator(
68+
[$getRootDocumentEntry],
69+
$documentArray,
70+
),
71+
$documentArray,
72+
);
73+
}
74+
6375
public function next(): void
6476
{
6577
$this->previousDocument = $this->currentDocument;

0 commit comments

Comments
 (0)