Skip to content

Commit

Permalink
misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dcarbone committed Apr 15, 2024
1 parent c78c365 commit 237d3da
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ public static function decorate(
foreach ($annotation->children('xs', true) as $child) {
switch ($child->getName()) {
case ElementName::DOCUMENTATION->value:
TypeBuilderUtils::setPropertyStringFromElementValue(
$property,
$annotation,
$child,
'addDocumentationFragment'
);
$property->addDocumentationFragment((string)$child);
break;
case ElementName::COMPLEX_CONTENT->value:
ComplexContentElementTypeDecorator::decorate($config, $types, $type, $child);
Expand Down
20 changes: 10 additions & 10 deletions src/Definition/Types.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ class Types implements Countable
*/
private Type $containerType;

private const _CONTAINED_IGNORED_TYPES = [
TypeKind::RESOURCE_INLINE,
TypeKind::RESOURCE_CONTAINER,
TypeKind::_LIST,
TypeKind::PRIMITIVE,
TypeKind::PRIMITIVE_CONTAINER,
];

/**
* FHIRTypes constructor.
* @param \DCarbone\PHPFHIR\Config\VersionConfig $config
Expand Down Expand Up @@ -150,7 +158,7 @@ public function getIterator(): iterable
*
* @return \DCarbone\PHPFHIR\Definition\Type[]
*/
public function getSortedIterator(): iterable
public function getNameSortedIterator(): iterable
{
$tmp = $this->types;
usort(
Expand Down Expand Up @@ -200,16 +208,8 @@ public function getContainerType(): ?Type
*/
public function isContainedType(Type $type): bool
{
static $ignoredTypes = [
TypeKind::RESOURCE_INLINE,
TypeKind::RESOURCE_CONTAINER,
TypeKind::_LIST,
TypeKind::PRIMITIVE,
TypeKind::PRIMITIVE_CONTAINER,
];

// only bother with actual Resource types.
if ($type->getKind()->isOneOf(...$ignoredTypes)) {
if ($type->getKind()->isOneOf(...self::_CONTAINED_IGNORED_TYPES)) {
return false;
}
$container = $this->getContainerType();
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/AttributeName.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
enum AttributeName : string
{
use EnumCompat;
use ValuesTrait;

case NAME = 'name';
case VALUE = 'value';
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/ElementName.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
enum ElementName : string
{
use EnumCompat;
use ValuesTrait;

case _INCLUDE = 'include';
case IMPORT = 'import';
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/PrimitiveType.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
use DCarbone\PHPFHIR\Utilities\ExceptionUtils;
enum PrimitiveType:string
{
use EnumCompat;
use ValuesTrait;

case STRING = 'string';
case BOOLEAN = 'boolean';
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/PropertyUse.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
enum PropertyUse: string
{
use EnumCompat;
use ValuesTrait;

case PROHIBITED = 'prohibited';
case OPTIONAL = 'optional';
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/TypeKind.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
enum TypeKind: string
{
use EnumCompat;
use ValuesTrait;

// this represents an actual value: string, int, etc.
case PRIMITIVE = 'primitive';
Expand Down
2 changes: 1 addition & 1 deletion src/Enum/EnumCompat.php → src/Enum/ValuesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* limitations under the License.
*/

trait EnumCompat
trait ValuesTrait
{
/**
* @return string[]
Expand Down
4 changes: 2 additions & 2 deletions src/LogLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
* limitations under the License.
*/

use DCarbone\PHPFHIR\Enum\EnumCompat;
use DCarbone\PHPFHIR\Enum\ValuesTrait;
use Psr\Log\LogLevel as PLogLevel;

enum LogLevel: string
{
use EnumCompat;
use ValuesTrait;

case EMERGENCY = PLogLevel::EMERGENCY;
case ALERT = PLogLevel::ALERT;
Expand Down
18 changes: 6 additions & 12 deletions src/Utilities/TypeBuilderUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public static function setTypeIntegerFromAttribute(
)
);
}
self::callTypeSetter($type, $parentElement, $attribute, $setterMethod, intval($int, 10));
self::callTypeSetter($type, $parentElement, $attribute, $setterMethod, intval($int));
}

/**
Expand All @@ -195,21 +195,15 @@ public static function setTypeIntegerFromElementAttribute(
/**
* @param \DCarbone\PHPFHIR\Definition\Type $type
* @param \SimpleXMLElement $parentElement
* @param \SimpleXMLElement $enum
* @param \SimpleXMLElement $enumElement
*/
public static function addTypeEnumeratedValue(Type $type, \SimpleXMLElement $parentElement, \SimpleXMLElement $enum): void
public static function addTypeEnumeratedValue(Type $type, \SimpleXMLElement $parentElement, \SimpleXMLElement $enumElement): void
{
$value = $enum->attributes()->value;
$value = $enumElement->attributes()->value;
if (null === $value) {
throw ExceptionUtils::createExpectedTypeElementAttributeNotFoundException($type, $enum, 'value');
throw ExceptionUtils::createExpectedTypeElementAttributeNotFoundException($type, $enumElement, 'value');
}
self::callTypeSetter(
$type,
$parentElement,
$enum,
'addEnumerationValue',
new EnumerationValue((string)$value, $enum)
);
$type->addEnumerationValue(new EnumerationValue((string)$value, $enumElement));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion template/tests/test_class_constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
class <?php echo PHPFHIR_TEST_CLASSNAME_CONSTANTS; ?> extends TestCase
{
<?php foreach($types->getSortedIterator() as $type) : ?>
<?php foreach($types->getNameSortedIterator() as $type) : ?>
public function testTypeConstantsDefined<?php echo str_replace('\\', '_', $type->getFullyQualifiedClassName(false)); ?>()
{
$this->assertEquals('<?php echo $type->getFHIRName(); ?>', <?php echo $type->getTypeNameConst(true); ?>);
Expand Down
8 changes: 4 additions & 4 deletions template/tests/test_class_type_map.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testGetTypeClassWithNonStringReturnsNull()

public function testGetContainedTypeClassName()
{
<?php foreach($types->getSortedIterator() as $type) :
<?php foreach($types->getNameSortedIterator() as $type) :
if ($type->isContainedType()) : ?>
$this->assertEquals('<?php echo $type->getFullyQualifiedClassName(true); ?>', <?php echo PHPFHIR_CLASSNAME_TYPEMAP; ?>::getContainedTypeClassName('<?php echo $type->getFHIRName(); ?>'));
<?php else : ?>
Expand All @@ -59,7 +59,7 @@ public function testGetContainedTypeClassName()

public function testIsContainableResourceWithClassname()
{
<?php foreach($types->getSortedIterator() as $type) :
<?php foreach($types->getNameSortedIterator() as $type) :
if ($type->isContainedType()) : ?>
$this->assertTrue(<?php echo PHPFHIR_CLASSNAME_TYPEMAP; ?>::isContainableResource('<?php echo $type->getFullyQualifiedClassName(false); ?>'));
$this->assertTrue(<?php echo PHPFHIR_CLASSNAME_TYPEMAP; ?>::isContainableResource('<?php echo $type->getFullyQualifiedClassName(true); ?>'));
Expand All @@ -72,7 +72,7 @@ public function testIsContainableResourceWithClassname()

public function testIsContainableResourceWithTypeName()
{
<?php foreach($types->getSortedIterator() as $type) :
<?php foreach($types->getNameSortedIterator() as $type) :
if ($type->isContainedType()) : ?>
$this->assertTrue(<?php echo PHPFHIR_CLASSNAME_TYPEMAP; ?>::isContainableResource('<?php echo $type->getFHIRName(); ?>'));
<?php else : ?>
Expand All @@ -83,7 +83,7 @@ public function testIsContainableResourceWithTypeName()

public function testIsContainableResourceWithInstance()
{
<?php foreach($types->getSortedIterator() as $type) : ?>
<?php foreach($types->getNameSortedIterator() as $type) : ?>
$type = new <?php echo $type->getFullyQualifiedClassName(true); ?>;
<?php if ($type->isContainedType()) : ?>
$this->assertTrue(<?php echo PHPFHIR_CLASSNAME_TYPEMAP; ?>::isContainableResource($type));
Expand Down
4 changes: 2 additions & 2 deletions template/utilities/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ abstract class <?php echo PHPFHIR_CLASSNAME_CONSTANTS; ?>
public const <?php echo PHPFHIR_VALIDATION_MAX_OCCURS_NAME; ?> = '<?php echo PHPFHIR_VALIDATION_MAX_OCCURS; ?>';

// Type names
<?php foreach($types->getSortedIterator() as $type) : ?>
<?php foreach($types->getNameSortedIterator() as $type) : ?>
public const <?php echo $type->getTypeNameConst(false); ?> = '<?php echo $type->getFHIRName(); ?>';
<?php endforeach;?>

// Type classes
<?php foreach($types->getSortedIterator() as $type) : ?>
<?php foreach($types->getNameSortedIterator() as $type) : ?>
public const <?php echo $type->getClassNameConst(false); ?> = '<?php echo str_replace('\\', '\\\\', $type->getFullyQualifiedClassName(true)); ?>';
<?php endforeach;
echo "}\n";
Expand Down
2 changes: 1 addition & 1 deletion template/utilities/typemap_class.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ abstract class <?php echo PHPFHIR_CLASSNAME_TYPEMAP; ?>
* This array represents every type known to this lib
*/
private const TYPE_MAP = [
<?php foreach ($types->getSortedIterator() as $type) : ?>
<?php foreach ($types->getNameSortedIterator() as $type) : ?>
<?php echo $type->getTypeNameConst(true); ?> => <?php echo $type->getClassNameConst(true); ?>,
<?php endforeach; ?> ];

Expand Down

0 comments on commit 237d3da

Please sign in to comment.