Skip to content

Commit e3b0725

Browse files
authored
Merge pull request #1255 from phpDocumentor/fix/dev-server-bugs
Fix/dev server bugs
2 parents 813a175 + a1a7012 commit e3b0725

File tree

10 files changed

+432
-287
lines changed

10 files changed

+432
-287
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"phpdocumentor/guides-markdown": "^1.0 || ^1.0@dev",
5151
"phpdocumentor/guides-restructured-text": "^1.0 || ^1.0@dev",
5252
"phpdocumentor/guides-theme-bootstrap": "^1.0 || ^1.0@dev",
53-
"phpdocumentor/guides-theme-rst": "^1.0 || ^1.0@dev"
53+
"phpdocumentor/guides-theme-rst": "^1.0 || ^1.0@dev",
54+
"symfony/polyfill-php84": "^1.33"
5455
},
5556
"require-dev": {
5657
"ext-dom": "*",

composer.lock

Lines changed: 399 additions & 259 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/guides-cli/src/DevServer/RerenderListener.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@
2929
use phpDocumentor\Guides\Settings\ProjectSettings;
3030
use Symfony\Component\Console\Output\OutputInterface;
3131

32+
use function array_find_key;
3233
use function assert;
34+
use function current;
3335
use function sprintf;
3436
use function substr;
3537

3638
final class RerenderListener
3739
{
38-
/** @param array<string, DocumentNode> $documents */
40+
/** @param DocumentNode[] $documents */
3941
public function __construct(
4042
private readonly OutputInterface $output,
4143
private readonly CommandBus $commandBus,
@@ -72,7 +74,16 @@ public function __invoke(FileModifiedEvent $event): void
7274

7375
/** @var array<string, DocumentNode> $documents */
7476
$documents = $this->commandBus->handle(new CompileDocumentsCommand([$file => $document], new CompilerContext($this->projectNode)));
75-
$this->documents[$file] = $documents[$file];
77+
$key = array_find_key($this->documents, static fn (DocumentNode $entry) => $entry->getFilePath() === $document->getFilePath());
78+
$document = current($documents);
79+
assert($document instanceof DocumentNode);
80+
if ($key === null) {
81+
// If the document is new, we add it to the list with its file path as key
82+
$this->documents[] = $document;
83+
} else {
84+
$this->documents[$key] = $document;
85+
}
86+
7687
$destinationFileSystem = FlySystemAdapter::createForPath($this->settings->getOutput());
7788

7889
$documentIterator = DocumentListIterator::create(

packages/guides-restructured-text/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"doctrine/lexer": "^3.0",
2626
"phpdocumentor/guides": "^1.0 || ^2.0",
2727
"webmozart/assert": "^1.11",
28-
"league/csv": "^9.10.0"
28+
"league/csv": "^9.27.0"
2929
},
3030
"extra": {
3131
"branch-alias": {

packages/guides-restructured-text/src/RestructuredText/Directives/CsvTableDirective.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
use function explode;
3434
use function implode;
3535
use function is_string;
36-
use function method_exists;
3736
use function strval;
3837
use function trim;
3938

@@ -79,18 +78,10 @@ public function processNode(
7978
return new GenericNode('csv-table');
8079
}
8180

82-
if (method_exists(Reader::class, 'from')) {
83-
$csv = Reader::from($csvStream);
84-
} else {
85-
$csv = Reader::createFromStream($csvStream);
86-
}
81+
$csv = Reader::from($csvStream);
8782
} else {
8883
$lines = $blockContext->getDocumentIterator()->toArray();
89-
if (method_exists(Reader::class, 'fromString')) {
90-
$csv = Reader::fromString(implode("\n", $lines));
91-
} else {
92-
$csv = Reader::createFromString(implode("\n", $lines));
93-
}
84+
$csv = Reader::fromString(implode("\n", $lines));
9485
}
9586

9687
if ($directive->getOption('header-rows')->getValue() !== null) {
@@ -99,11 +90,7 @@ public function processNode(
9990

10091
$header = null;
10192
if ($directive->hasOption('header')) {
102-
if (method_exists(Reader::class, 'fromString')) {
103-
$headerCsv = Reader::fromString($directive->getOption('header')->toString());
104-
} else {
105-
$headerCsv = Reader::createFromString($directive->getOption('header')->toString());
106-
}
93+
$headerCsv = Reader::fromString($directive->getOption('header')->toString());
10794

10895
$header = new TableRow();
10996
foreach ($headerCsv->first() as $column) {

packages/guides-restructured-text/src/RestructuredText/Parser/Productions/FieldListRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ private function parseField(string $line): array
103103
{
104104
if (preg_match('/^:([^:]+):( (.*)|)$/mUsi', $line, $match) > 0) {
105105
return [
106-
$match[1] ?? '',
107-
$match[2] ?? '',
106+
$match[1],
107+
$match[2],
108108
];
109109
}
110110

packages/guides/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"symfony/clock": "^6.4.8",
3535
"symfony/html-sanitizer": "^6.4.8",
3636
"symfony/http-client": "^6.4.9",
37+
"symfony/polyfill-php84": "^1.33.0",
3738
"symfony/string": "^6.4.9",
3839
"symfony/translation-contracts": "^3.5.1",
3940
"twig/twig": "~2.15 || ^3.0",

packages/guides/src/Compiler/Passes/GlobalMenuPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function run(array $documents, CompilerContextInterface $compilerContext)
7070
}
7171

7272
if ($rootDocument === null) {
73-
return [];
73+
return $documents;
7474
}
7575

7676
$menuNodes = [];

packages/guides/src/Nodes/ProjectNode.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ public function addLinkTarget(string $anchorName, InternalTarget $target): void
154154
}
155155

156156
if (isset($this->internalLinkTargets[$linkType][$anchorName]) && $linkType !== 'std:title') {
157+
if ($this->internalLinkTargets[$linkType][$anchorName]->getDocumentPath() === $target->getDocumentPath()) {
158+
return;
159+
}
160+
157161
throw new DuplicateLinkAnchorException(sprintf('Duplicate anchor "%s". There is already another anchor of that name in document "%s"', $anchorName, $this->internalLinkTargets[$linkType][$anchorName]->getDocumentPath()));
158162
}
159163

packages/guides/tests/unit/Interlink/InventoryLoaderTest.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,6 @@ final class InventoryLoaderTest extends TestCase
4444
private JsonLoader&MockObject $jsonLoader;
4545
private DefaultInventoryRepository $inventoryRepository;
4646
private RenderContext&MockObject $renderContext;
47-
/** @var array<string, mixed> */
48-
private array $json;
4947

5048
protected function setUp(): void
5149
{
@@ -65,9 +63,10 @@ public function loadObjectsJsonInv(string $filename): void
6563
{
6664
$jsonString = file_get_contents($filename);
6765
assertIsString($jsonString);
68-
$this->json = (array) json_decode($jsonString, true, 512, JSON_THROW_ON_ERROR);
66+
/** @var array<array-key, mixed> $json */
67+
$json = (array) json_decode($jsonString, true, 512, JSON_THROW_ON_ERROR);
6968
$inventory = new Inventory('https://example.com/', new SluggerAnchorNormalizer());
70-
$this->inventoryLoader->loadInventoryFromJson($inventory, $this->json);
69+
$this->inventoryLoader->loadInventoryFromJson($inventory, $json);
7170
$this->inventoryRepository->addInventory('somekey', $inventory);
7271
$this->inventoryRepository->addInventory('some-key', $inventory);
7372
}
@@ -82,7 +81,9 @@ public function testInventoryLoaderLoadsInventory(): void
8281

8382
public function testInventoryIsLoadedExactlyOnce(): void
8483
{
85-
$this->jsonLoader->expects(self::once())->method('loadJsonFromUrl')->willReturn($this->json);
84+
$this->jsonLoader->expects(self::once())->method('loadJsonFromUrl')->willReturn(
85+
['dummy' => 'data', 'items' => []],
86+
);
8687
$inventory = new Inventory('https://example.com/', new SluggerAnchorNormalizer());
8788
$this->inventoryLoader->loadInventory($inventory);
8889
$this->inventoryLoader->loadInventory($inventory);

0 commit comments

Comments
 (0)