Skip to content

Commit a1a7012

Browse files
committed
Fix stan errors
1 parent ac9dccd commit a1a7012

File tree

5 files changed

+22
-26
lines changed

5 files changed

+22
-26
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
final class RerenderListener
3939
{
40-
/** @param array<string, DocumentNode> $documents */
40+
/** @param DocumentNode[] $documents */
4141
public function __construct(
4242
private readonly OutputInterface $output,
4343
private readonly CommandBus $commandBus,
@@ -75,7 +75,15 @@ public function __invoke(FileModifiedEvent $event): void
7575
/** @var array<string, DocumentNode> $documents */
7676
$documents = $this->commandBus->handle(new CompileDocumentsCommand([$file => $document], new CompilerContext($this->projectNode)));
7777
$key = array_find_key($this->documents, static fn (DocumentNode $entry) => $entry->getFilePath() === $document->getFilePath());
78-
$this->documents[$key] = current($documents);
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+
7987
$destinationFileSystem = FlySystemAdapter::createForPath($this->settings->getOutput());
8088

8189
$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/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)