Skip to content

Commit b25e204

Browse files
Refactor and document type handling for generics and containers across writers and formatters, update PHP-CS rules, and enhance URL generation logic.
1 parent 0897c05 commit b25e204

6 files changed

Lines changed: 30 additions & 11 deletions

File tree

src/BmmSchemaCollection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use RuntimeException;
1414

1515
/**
16-
* @implements \IteratorAggregate<int, BmmSchema>
16+
* @implements \IteratorAggregate<string, BmmSchema>
1717
*/
1818
class BmmSchemaCollection implements \IteratorAggregate
1919
{
@@ -61,8 +61,10 @@ public function count(): int
6161
return $this->schemas->count();
6262
}
6363

64+
/** @return \ArrayIterator<string, BmmSchema> */
6465
public function getIterator(): \ArrayIterator
6566
{
67+
/** @var \ArrayIterator<string, BmmSchema> */
6668
return $this->schemas->getIterator();
6769
}
6870

src/Writer/BmmJsonSplit.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ private function writePackage(BmmPackage $package, BmmSchema $schema, string $na
8484
'aom2' => 'AOM2.html',
8585
default => $page . '.html',
8686
};
87-
$data['specUrl'] = \sprintf('https://specifications.openehr.org/releases/%s/development/%s#%s', strtoupper($schema->schemaName), $page, $fragment);
87+
$component = strtoupper($schema->schemaName);
88+
$data['specUrl'] = "https://specifications.openehr.org/releases/{$component}/development/{$page}#{$fragment}";
8889
}
8990
$logger->notice('Writing {file} class ...', ['file' => $filename]);
9091
$content = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR);

src/Writer/Formatter/AsciidocDefinition.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,11 @@ protected function formatFunctionSignature(BmmFunction $function, string $prefix
356356
}
357357
$args = implode(", +\n", array_map(function ($parameter) use ($prefix, $schema) {
358358
if ($parameter instanceof BmmContainerFunctionParameter) {
359-
return $parameter->name . ': `' . $this->formatContainerType($parameter->typeDef, $prefix, $schema) . ($parameter->isNullable ? '' : '[1]') . '`';
359+
$type = $this->formatContainerType($parameter->typeDef, $prefix, $schema);
360+
return $parameter->name . ': `' . $type . ($parameter->isNullable ? '' : '[1]') . '`';
360361
} elseif ($parameter instanceof BmmGenericFunctionParameter) {
361-
return $parameter->name . ': `' . $this->formatGenericType($parameter->typeDef, $prefix, $schema) . ($parameter->isNullable ? '' : '[1]') . '`';
362+
$type = $this->formatGenericType($parameter->typeDef, $prefix, $schema);
363+
return $parameter->name . ': `' . $type . ($parameter->isNullable ? '' : '[1]') . '`';
362364
} elseif ($parameter instanceof BmmSingleFunctionParameter || $parameter instanceof BmmSingleFunctionParameterOpen) {
363365
return $parameter->name . ': `' . $this->formatType($parameter->type, $prefix, $schema) . ($parameter->isNullable ? '' : '[1]') . '`';
364366
}
@@ -404,14 +406,16 @@ protected function formatContainerType(BmmContainerType $type, string $prefix, B
404406
protected function formatGenericType(BmmGenericType $type, string $prefix, BmmSchema $schema): string
405407
{
406408
if (!empty($type->genericParameters)) {
409+
/** @var array<string|BmmGenericType> $params — library types string[] but nested generics produce BmmGenericType */
410+
$params = $type->genericParameters;
407411
$genericParameters = implode(',', array_map(
408412
function (string|BmmGenericType $t) use ($prefix, $schema): string {
409413
if ($t instanceof BmmGenericType) {
410414
return $this->formatGenericType($t, $prefix, $schema);
411415
}
412416
return $this->formatType($t, $prefix, $schema);
413417
},
414-
$type->genericParameters,
418+
$params,
415419
));
416420
} elseif (!empty($type->genericParameterDefs)) {
417421
$genericParameters = implode(',', array_map(function ($t) use ($prefix, $schema) {
@@ -471,15 +475,19 @@ public function formatType(string $type, string $prefix, BmmSchema $schema): str
471475
// type is on the same spec page, an example format is '<<_boolean_class,Boolean>>'
472476
return '<<_' . strtolower($type) . '_' . $classType . ',' . $type . '>>';
473477
}
474-
// an example format is 'link:/releases/BASE/{base_release}/foundation_types.html#_boolean_class[Boolean^]'
475-
return 'link:/releases/' . $m[0] . '/{' . strtolower($m[0]) . '_release}/' . $m[1] . '.html#_' . strtolower($type) . '_' . $classType . '[' . $type . '^]';
478+
// format: 'link:/releases/BASE/{base_release}/foundation_types.html#_boolean_class[Boolean^]'
479+
$rel = strtolower($m[0]) . '_release';
480+
$anchor = strtolower($type) . '_' . $classType;
481+
return "link:/releases/{$m[0]}/{{$rel}}/{$m[1]}.html#_{$anchor}[{$type}^]";
476482
}
477483

478-
// an example format is 'xref:/releases/BASE/{base_release}/foundation_types.html#_boolean_class[Boolean^]'
484+
// format: 'xref:BASE:foundation_types:overview.adoc#_boolean_class[Boolean]'
479485
$xref = match ($xref) {
480486
'BASE:foundation_types' => 'BASE:foundation_types:overview',
481487
'BASE:foundation_types:time' => 'BASE:foundation_types:time_types',
482-
'BASE:foundation_types:structures', 'BASE:foundation_types:structure', 'BASE:foundation_types:structure_package' => 'BASE:foundation_types:structure_types',
488+
'BASE:foundation_types:structures',
489+
'BASE:foundation_types:structure',
490+
'BASE:foundation_types:structure_package' => 'BASE:foundation_types:structure_types',
483491
'BASE:foundation_types:interval' => 'BASE:foundation_types:interval',
484492
'BASE:foundation_types:primitive_types' => 'BASE:foundation_types:primitive_types',
485493
'BASE:foundation_types:functional' => 'BASE:foundation_types:functional',

src/Writer/Formatter/PlantUml.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,16 @@ private function formatContainerParameterType(BmmContainerType $type): string
233233
private function formatGenericParameterType(BmmGenericType $type): string
234234
{
235235
if (!empty($type->genericParameters)) {
236+
/** @var array<string|BmmGenericType> $params — library types string[] but nested generics produce BmmGenericType */
237+
$params = $type->genericParameters;
236238
$genericParameters = implode(',', array_map(
237239
function (string|BmmGenericType $t): string {
238240
if ($t instanceof BmmGenericType) {
239241
return $this->formatGenericParameterType($t);
240242
}
241243
return $t;
242244
},
243-
$type->genericParameters,
245+
$params,
244246
));
245247
} elseif (!empty($type->genericParameterDefs)) {
246248
$genericParameters = implode(',', array_map(function ($t) {

tests/Unit/BmmSchemaCollectionTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
final class BmmSchemaCollectionTest extends TestCase
1515
{
16-
1716
#[Test]
1817
public function inputDirPointsToResourcesDirectory(): void
1918
{

tests/phpcs.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,11 @@
1010
<exclude-pattern>*/var/*</exclude-pattern>
1111

1212
<rule ref="PSR12"/>
13+
14+
<rule ref="Generic.Files.LineLength">
15+
<properties>
16+
<property name="lineLimit" value="160"/>
17+
<property name="absoluteLineLimit" value="0"/>
18+
</properties>
19+
</rule>
1320
</ruleset>

0 commit comments

Comments
 (0)