Skip to content

Commit

Permalink
removing generators, not useful, xml is probably good?
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Jan 9, 2025
1 parent e9571bf commit 0a0b2c5
Show file tree
Hide file tree
Showing 23 changed files with 111 additions and 207 deletions.
6 changes: 3 additions & 3 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function writeFHIRVersionTypeClasses(string ...$versionNames): void

$types = $definition->getTypes();

foreach ($types->getGenerator() as $type) {
foreach ($types->getIterator() as $type) {
/** @var \DCarbone\PHPFHIR\Version\Definition\Type $type */
$log->debug("Generating class for type {$type}...");

Expand Down Expand Up @@ -182,7 +182,7 @@ public function writeFHIRVersionTestFiles(string ...$versionNames): void
// TestTypeEnum::INTEGRATION,
//// TestTypeEnum::VALIDATION,
// ];
// foreach ($types->getGenerator() as $type) {
// foreach ($types->getIterator() as $type) {
// if ($type->isAbstract()) {
// continue;
// }
Expand Down Expand Up @@ -223,7 +223,7 @@ public function writeCoreFiles(CoreFiles $coreFiles, array $templateArgs): void
$this->log->startBreak('Core Files');

// render each core file
foreach ($coreFiles->getGenerator() as $coreFile) {
foreach ($coreFiles->getIterator() as $coreFile) {
FileUtils::mkdirRecurse($coreFile->getFilepath());
$this->writeFile(
$coreFile->getFilepath(),
Expand Down
10 changes: 0 additions & 10 deletions src/Builder/Imports.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,6 @@ public function getIterator(): iterable
return new \ArrayIterator($this->_imports);
}

/**
* @return \Generator<\DCarbone\PHPFHIR\Builder\Import>
*/
public function getGenerator(): \Generator
{
foreach ($this->_imports as $import) {
yield $import;
}
}

/**
* @return int
*/
Expand Down
10 changes: 0 additions & 10 deletions src/CoreFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,4 @@ public function getIterator(): iterable
{
return new \ArrayIterator($this->_files);
}

/**
* @return \Generator<\DCarbone\PHPFHIR\CoreFile>
*/
public function getGenerator(): \Generator
{
foreach($this->_files as $file) {
yield $file;
}
}
}
8 changes: 5 additions & 3 deletions src/Utilities/DocumentationUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ public static function compilePropertyDocumentation(Property $property, int $spa
{
$propValueType = $property->getValueFHIRType();

$typeDoc = null === $propValueType ?
'' :
trim($propValueType->getDocBlockDocumentationFragment($spaces, false));
$typeDoc = match($propValueType) {
null => '',
default => trim($propValueType->getDocBlockDocumentationFragment($spaces, false)),
};

$propDoc = trim($property->getDocBlockDocumentationFragment($spaces, false));

if ('' === $typeDoc && '' === $propDoc) {
Expand Down
13 changes: 5 additions & 8 deletions src/Utilities/ImportUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ImportUtils
public static function compileImportStatements(Imports $imports): string
{
$stmts = [];
foreach ($imports->getGenerator() as $import) {
foreach ($imports->getIterator() as $import) {
if ($import->requiresImport()) {
$stmts[] = "use {$import->getFullyQualifiedName(false)};";
}
Expand All @@ -50,6 +50,10 @@ public static function buildVersionTypeImports(Type $type): void
if (!$type->isAbstract()) {
$imports->addCoreFileImportsByName(
PHPFHIR_ENCODING_CLASSNAME_XML_WRITER,
PHPFHIR_ENCODING_ENUM_XML_LOCATION,
PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG,
PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG,
PHPFHIR_INTERFACE_TYPE,
);
}

Expand All @@ -67,12 +71,6 @@ public static function buildVersionTypeImports(Type $type): void
PHPFHIR_VERSION_CLASSNAME_VERSION_CONSTANTS,
);

$imports->addCoreFileImportsByName(
PHPFHIR_ENCODING_CLASSNAME_UNSERIALIZE_CONFIG,
PHPFHIR_ENCODING_CLASSNAME_SERIALIZE_CONFIG,
PHPFHIR_INTERFACE_TYPE,
);

if (($type->isCommentContainer() && !$type->hasCommentContainerParent()) ||
$type->hasPropertiesWithValidations() ||
($typeKind->isOneOf(TypeKindEnum::PRIMITIVE) && !$type->hasPrimitiveParent())) {
Expand Down Expand Up @@ -101,7 +99,6 @@ public static function buildVersionTypeImports(Type $type): void
|| $type->hasValueContainerParent()
|| $type->hasPrimitiveContainerParent()
|| $typeKind->isOneOf(TypeKindEnum::PRIMITIVE, TypeKindEnum::LIST, TypeKindEnum::PRIMITIVE_CONTAINER)) {
$imports->addCoreFileImportsByName(PHPFHIR_ENCODING_ENUM_XML_LOCATION);
if (!$type->hasValueContainerParent() && !$type->hasPrimitiveContainerParent()) {
$imports->addCoreFileImportsByName(PHPFHIR_ENCODING_TRAIT_XML_LOCATION);
}
Expand Down
17 changes: 8 additions & 9 deletions src/Utilities/TypeHintUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public static function buildBaseHintParts(Version $version, Type $type, bool $fu
public static function propertyDeclarationHint(Version $version, Property $property, bool $nullable): string
{
if ($property->isCollection()) {
return $nullable ? 'null|array' : 'array';
return 'array';
}

$pt = $property->getValueFHIRType();
Expand Down Expand Up @@ -229,25 +229,24 @@ public static function propertyGetterDocHint(Version $version,
return self::primitivePHPValueTypeHint(
$version,
$property->getMemberOf()->getPrimitiveType(),
$nullable,
!$property->isCollection(),
);
}

if ($pt->getKind()->isResourceContainer($version)) {
$versionCoreFiles = $version->getCoreFiles();
$containedTypeInterface = $versionCoreFiles->getCoreFileByEntityName(PHPFHIR_VERSION_INTERFACE_VERSION_CONTAINED_TYPE);
return ($nullable ? 'null|' : '')
. $containedTypeInterface->getFullyQualifiedName(true)
. ($property->isCollection() ? '[]' : '');
if ($property->isCollection()) {
return "{$containedTypeInterface->getFullyQualifiedName(true)}[]";
}
return ($nullable ? 'null|' : '') . $containedTypeInterface->getFullyQualifiedName(true);
}

$hint = ($nullable ? 'null|' : '') . $pt->getFullyQualifiedClassName(true);

if ($property->isCollection()) {
return "{$hint}[]";
return "{$pt->getFullyQualifiedClassName(true)}[]";
}

return $hint;
return ($nullable ? 'null|' : '') . $pt->getFullyQualifiedClassName(true);
}

/**
Expand Down
10 changes: 0 additions & 10 deletions src/Version/Definition/Enumeration.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ public function getIterator(): iterable
return new \ArrayIterator($this->_values);
}

/**
* @return \Generator<\DCarbone\PHPFHIR\Version\Definition\Enumeration\EnumerationValue>
*/
public function getGenerator(): \Generator
{
foreach($this->_values as $value) {
yield $value;
}
}

/**
* @return int
*/
Expand Down
12 changes: 1 addition & 11 deletions src/Version/Definition/Properties.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,6 @@ public function getIterator(): iterable
return new \ArrayIterator($this->_properties);
}

/**
* @return \Generator
*/
public function getGenerator(): \Generator
{
foreach ($this->_properties as $p) {
yield $p;
}
}

/**
* Returns an iterator contanining all properties, including those inherited from parent types, sorted ascending by name
*
Expand Down Expand Up @@ -196,7 +186,7 @@ public function getIndexedIterator(): iterable
public function getIteratorOfTypeKinds(bool $includeCollections, null|TypeKindEnum...$kinds): iterable
{
$out = [];
foreach ($this->getGenerator() as $property) {
foreach ($this->getIterator() as $property) {
if (!$includeCollections && $property->isCollection()) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Version/Definition/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -463,12 +463,12 @@ public function buildValidationMap(Type $local): array

if ($memberOf->isEnumerated()) {
$map[PHPFHIR_VALIDATION_ENUM_NAME] = [];
foreach ($memberOf->getEnumeration()->getGenerator() as $enum) {
foreach ($memberOf->getEnumeration()->getIterator() as $enum) {
$map[PHPFHIR_VALIDATION_ENUM_NAME][] = $enum->getValue();
}
} else if ($this->isValueProperty() && $local->isEnumerated()) {
$map[PHPFHIR_VALIDATION_ENUM_NAME] = [];
foreach ($local->getEnumeration()->getGenerator() as $enum) {
foreach ($local->getEnumeration()->getIterator() as $enum) {
$map[PHPFHIR_VALIDATION_ENUM_NAME][] = $enum->getValue();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Version/Definition/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public function hasPropertiesWithValidations(): bool
if ($this->isEnumerated()) {
return true;
}
foreach ($this->getProperties()->getGenerator() as $property) {
foreach ($this->getProperties()->getIterator() as $property) {
if ([] !== $property->buildValidationMap($this)) {
return true;
}
Expand All @@ -381,11 +381,11 @@ public function getAllPropertiesIndexedIterator(): iterable
{
$p = [];
foreach ($this->getRootFirstParentTypes() as $parentType) {
foreach ($parentType->getProperties()->getGenerator() as $property) {
foreach ($parentType->getProperties()->getIterator() as $property) {
$p[$property->getName()] = $property;
}
}
foreach ($this->getProperties()->getGenerator() as $property) {
foreach ($this->getProperties()->getIterator() as $property) {
$p[$property->getName()] = $property;
}
// this returns an \SplFixedArray to provide an indexed iterator
Expand All @@ -402,7 +402,7 @@ public function getParentPropertiesIterator(): iterable
{
$p = [];
foreach ($this->getRootFirstParentTypes() as $parentType) {
foreach ($parentType->getProperties()->getGenerator() as $property) {
foreach ($parentType->getProperties()->getIterator() as $property) {
// do not include properties that are overloaded by this type
if (!$this->_properties->hasProperty($property->getName()) && !isset($p[$property->getName()])) {
$p[$property->getName()] = $property;
Expand Down
4 changes: 2 additions & 2 deletions src/Version/Definition/TypeDecorationValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function validateDecoration(Config $config, Version $version, Type
}

$seenClasses = [];
foreach ($types->getGenerator() as $type) {
foreach ($types->getIterator() as $type) {
$typeKind = $type->getKind();

if ($type->isRootType()) {
Expand Down Expand Up @@ -91,7 +91,7 @@ public static function validateDecoration(Config $config, Version $version, Type
throw ExceptionUtils::createContainedTypeFlagMismatchException($types->isContainedType($type), $type);
}

foreach ($type->getProperties()->getGenerator() as $property) {
foreach ($type->getProperties()->getIterator() as $property) {
$name = $property->getName();
if (null === $name || '' === $name) {
throw ExceptionUtils::createPropertyMissingNameException($type, $property);
Expand Down
26 changes: 13 additions & 13 deletions src/Version/Definition/TypeDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ abstract class TypeDecorator
*/
public static function findNamelessProperties(Config $config, Types $types): void
{
foreach($types->getGenerator() as $type) {
foreach($type->getProperties()->getGenerator() as $property) {
foreach($types->getIterator() as $type) {
foreach($type->getProperties()->getIterator() as $property) {
$name = $property->getName();
if ('' === $name || null === $name) {
$property->setName($property->getRef());
Expand All @@ -60,7 +60,7 @@ public static function findNamelessProperties(Config $config, Types $types): voi
*/
public static function findComponentOfTypes(Config $config, Types $types): void
{
foreach ($types->getGenerator() as $type) {
foreach ($types->getIterator() as $type) {
$fhirName = $type->getFHIRName();
if (!str_contains($fhirName, '.')) {
continue;
Expand Down Expand Up @@ -88,7 +88,7 @@ public static function findComponentOfTypes(Config $config, Types $types): void
public static function findRestrictionBaseTypes(Version $version, Types $types): void
{
$logger = $version->getConfig()->getLogger();
foreach ($types->getGenerator() as $type) {
foreach ($types->getIterator() as $type) {
$fhirName = $type->getFHIRName();

// skip primitive types as they are already as base as they can go
Expand Down Expand Up @@ -145,7 +145,7 @@ public static function findRestrictionBaseTypes(Version $version, Types $types):
public static function findParentTypes(Config $config, Types $types): void
{
$logger = $config->getLogger();
foreach ($types->getGenerator() as $type) {
foreach ($types->getIterator() as $type) {
$fhirName = $type->getFHIRName();

// try to locate parent type name...
Expand Down Expand Up @@ -201,7 +201,7 @@ public static function findParentTypes(Config $config, Types $types): void
public static function determinePrimitiveTypes(Config $config, Types $types): void
{
$logger = $config->getLogger();
foreach ($types->getGenerator() as $type) {
foreach ($types->getIterator() as $type) {
if (in_array($type->getFHIRName(), self::DSTU1_PRIMITIVES, true)) {
$ptn = PrimitiveTypeEnum::STRING->value;
$logger->debug(sprintf('(DSTU1 suppport) Type "%s" determined to be DSTU1 primitive', $type->getFHIRName()));
Expand Down Expand Up @@ -360,7 +360,7 @@ private static function determineParsedTypeKind(Config $config, Version $version
*/
public static function determineParsedTypeKinds(Config $config, Version $version, Types $types): void
{
foreach ($types->getGenerator() as $type) {
foreach ($types->getIterator() as $type) {
self::determineParsedTypeKind($config, $version, $types, $type);
}
}
Expand All @@ -374,7 +374,7 @@ public static function setContainedTypeFlag(Config $config, Version $version, Ty
{
$versionName = $version->getName();

foreach ($types->getGenerator() as $type) {
foreach ($types->getIterator() as $type) {
if ($types->isContainedType($type)) {
$type->setContainedType(true);
}
Expand All @@ -393,7 +393,7 @@ public static function setValueContainerFlag(Config $config, Types $types): void
TypeKindEnum::QUANTITY,
];

foreach ($types->getGenerator() as $type) {
foreach ($types->getIterator() as $type) {
// TODO: handle valueString, valueQuantity, etc. types?
// skip primitive types and their child types
Expand Down Expand Up @@ -427,7 +427,7 @@ public static function setValueContainerFlag(Config $config, Types $types): void
public static function setCommentContainerFlag(Config $config, Types $types): void
{
static $skip = [TypeKindEnum::PRIMITIVE, TypeKindEnum::PHPFHIR_XHTML];
foreach ($types->getGenerator() as $type) {
foreach ($types->getIterator() as $type) {
$type->setCommentContainer(
!$type->hasPrimitiveParent() && !$type->getKind()->isOneOf(...$skip)
);
Expand All @@ -441,7 +441,7 @@ public static function setCommentContainerFlag(Config $config, Types $types): vo
public static function parseUnionMemberTypes(Config $config, Types $types): void
{
$log = $config->getLogger();
foreach ($types->getGenerator() as $type) {
foreach ($types->getIterator() as $type) {
$unionOf = $type->getUnionOf();
if ([] === $unionOf) {
continue;
Expand All @@ -459,7 +459,7 @@ public static function parseUnionMemberTypes(Config $config, Types $types): void
$utype->getFHIRName()
)
);
foreach ($utype->getProperties()->getGenerator() as $property) {
foreach ($utype->getProperties()->getIterator() as $property) {
$type->getProperties()->addOrReturnProperty(clone $property);
}
} else {
Expand All @@ -484,7 +484,7 @@ public static function parseUnionMemberTypes(Config $config, Types $types): void
*/
public static function buildTypeImports(Config $config, Types $types): void
{
foreach ($types->getGenerator() as $type) {
foreach ($types->getIterator() as $type) {
ImportUtils::buildVersionTypeImports($type);
}
}
Expand Down
Loading

0 comments on commit 0a0b2c5

Please sign in to comment.