@@ -45,7 +45,7 @@ class Type
45
45
private string $ fhirName ;
46
46
47
47
/** @var \DCarbone\PHPFHIR\Enum\TypeKind|null */
48
- private ? TypeKind $ kind = null ;
48
+ private null | TypeKind $ kind = null ;
49
49
50
50
/** @var string */
51
51
private string $ className ;
@@ -54,19 +54,19 @@ class Type
54
54
private Properties $ localProperties ;
55
55
56
56
/** @var null|string */
57
- private ? string $ parentTypeName = null ;
57
+ private null | string $ parentTypeName = null ;
58
58
/** @var null|\DCarbone\PHPFHIR\Definition\Type */
59
- private ? Type $ parentType = null ;
59
+ private null | Type $ parentType = null ;
60
60
61
61
/** @var int */
62
62
private int $ minLength = 0 ;
63
63
/** @var int */
64
64
private int $ maxLength = PHPFHIR_UNLIMITED ;
65
65
/** @var null|string */
66
- private ? string $ pattern = null ;
66
+ private null | string $ pattern = null ;
67
67
68
68
/** @var null|\DCarbone\PHPFHIR\Definition\Type */
69
- private ? Type $ componentOfType = null ;
69
+ private null | Type $ componentOfType = null ;
70
70
71
71
/** @var \DCarbone\PHPFHIR\Definition\Enumeration */
72
72
private Enumeration $ enumeration ;
@@ -78,10 +78,10 @@ class Type
78
78
private PrimitiveType $ primitiveType ;
79
79
80
80
/** @var null|string */
81
- private ? string $ restrictionBaseFHIRName = null ;
81
+ private null | string $ restrictionBaseFHIRName = null ;
82
82
83
83
/** @var null|\DCarbone\PHPFHIR\Definition\Type */
84
- private ? Type $ restrictionBaseFHIRType = null ;
84
+ private null | Type $ restrictionBaseFHIRType = null ;
85
85
86
86
/** @var bool */ // TODO: what the hell is this...?
87
87
private bool $ mixed = false ;
@@ -156,15 +156,19 @@ public function getImports(): TypeImports
156
156
}
157
157
158
158
/**
159
- * @param bool $withClass
159
+ * @param bool $withConstClass
160
160
* @param string $prefix
161
161
* @return string
162
162
*/
163
- public function getConstName (bool $ withClass , string $ prefix = '' ): string
163
+ public function getConstName (bool $ withConstClass , string $ prefix = '' ): string
164
164
{
165
- return ($ withClass ? PHPFHIR_CLASSNAME_CONSTANTS . ':: ' : '' ) . strtoupper ($ prefix ) . NameUtils::getConstName (
166
- $ this ->getFHIRName ()
167
- );
165
+ if ($ withConstClass ) {
166
+ $ cn = sprintf ('%s:: ' , PHPFHIR_CLASSNAME_CONSTANTS );
167
+ } else {
168
+ $ cn = '' ;
169
+ }
170
+
171
+ return sprintf ('%s%s%s ' , $ cn , strtoupper ($ prefix ), NameUtils::getConstName ($ this ->getFHIRName ()));
168
172
}
169
173
170
174
/**
@@ -188,7 +192,7 @@ public function getClassNameConst(bool $withClass): string
188
192
/**
189
193
* @return \DCarbone\PHPFHIR\Enum\TypeKind|null
190
194
*/
191
- public function getKind (): ? TypeKind
195
+ public function getKind (): null | TypeKind
192
196
{
193
197
return $ this ->kind ;
194
198
}
@@ -271,9 +275,12 @@ public function getFullyQualifiedNamespace(bool $leadingSlash): string
271
275
$ ns = $ this ->getConfig ()->getNamespace (false );
272
276
$ typeNS = $ this ->getTypeNamespace ();
273
277
if ('' !== $ typeNS ) {
274
- $ ns = "{ $ ns }\\{ $ typeNS}" ;
278
+ $ ns = sprintf ( ' %s \\ %s ' , $ ns , $ typeNS) ;
275
279
}
276
- return $ leadingSlash ? "\\{$ ns }" : $ ns ;
280
+ return match ($ leadingSlash ) {
281
+ true => sprintf ('\\%s ' , $ ns ),
282
+ false => $ ns ,
283
+ };
277
284
}
278
285
279
286
/**
@@ -286,9 +293,12 @@ public function getFullyQualifiedTestNamespace($testType, bool $leadingSlash): s
286
293
$ ns = $ this ->getConfig ()->getTestsNamespace ($ testType , false );
287
294
$ typeNS = $ this ->getTypeNamespace ();
288
295
if ('' !== $ typeNS ) {
289
- $ ns = "{ $ ns }\\{ $ typeNS}" ;
296
+ $ ns = sprintf ( ' %s \\ %s ' , $ ns , $ typeNS) ;
290
297
}
291
- return $ leadingSlash ? "\\{$ ns }" : $ ns ;
298
+ return match ($ leadingSlash ) {
299
+ true => sprintf ('\\%s ' , $ ns ),
300
+ false => $ ns ,
301
+ };
292
302
}
293
303
294
304
/**
@@ -301,9 +311,12 @@ public function getFullyQualifiedClassName(bool $leadingSlash): string
301
311
if ('' === $ cn ) {
302
312
$ cn = $ this ->getClassName ();
303
313
} else {
304
- $ cn .= "\\{ $ this ->getClassName ()}" ;
314
+ $ cn = sprintf ( ' %s \\ %s ' , $ cn , $ this ->getClassName ()) ;
305
315
}
306
- return $ leadingSlash ? "\\{$ cn }" : $ cn ;
316
+ return match ($ leadingSlash ) {
317
+ true => sprintf ('\\%s ' , $ cn ),
318
+ false => $ cn ,
319
+ };
307
320
}
308
321
309
322
/**
@@ -321,13 +334,16 @@ public function getTestClassName(): string
321
334
*/
322
335
public function getFullyQualifiedTestClassName ($ testType , bool $ leadingSlash ): string
323
336
{
324
- $ ns = $ this ->getFullyQualifiedTestNamespace ($ testType , false );
325
- if ('' === $ ns ) {
337
+ $ cn = $ this ->getFullyQualifiedTestNamespace ($ testType , false );
338
+ if ('' === $ cn ) {
326
339
$ cn = $ this ->getTestClassName ();
327
340
} else {
328
- $ cn = "{ $ ns }\\{ $ this ->getTestClassName ()}" ;
341
+ $ cn = sprintf ( ' %s \\ %s ' , $ cn , $ this ->getTestClassName ()) ;
329
342
}
330
- return $ leadingSlash ? "\\{$ cn }" : $ ns ;
343
+ return match ($ leadingSlash ) {
344
+ true => sprintf ('\\%s ' , $ cn ),
345
+ false => $ cn ,
346
+ };
331
347
}
332
348
333
349
/**
@@ -404,7 +420,7 @@ public function getRootType(): Type
404
420
/**
405
421
* @return \DCarbone\PHPFHIR\Definition\Type|null
406
422
*/
407
- public function getParentType (): ? Type
423
+ public function getParentType (): null | Type
408
424
{
409
425
return $ this ->parentType ;
410
426
}
@@ -441,7 +457,7 @@ public function setParentType(Type $type): Type
441
457
/**
442
458
* @return null|string
443
459
*/
444
- public function getParentTypeName (): ? string
460
+ public function getParentTypeName (): null | string
445
461
{
446
462
return $ this ->parentTypeName ;
447
463
}
@@ -450,7 +466,7 @@ public function getParentTypeName(): ?string
450
466
* @param string|null $parentTypeName
451
467
* @return \DCarbone\PHPFHIR\Definition\Type
452
468
*/
453
- public function setParentTypeName (? string $ parentTypeName ): Type
469
+ public function setParentTypeName (null | string $ parentTypeName ): Type
454
470
{
455
471
$ this ->parentTypeName = $ parentTypeName ;
456
472
return $ this ;
@@ -539,7 +555,7 @@ public function setMaxLength(int $maxLength): Type
539
555
/**
540
556
* @return string|null
541
557
*/
542
- public function getPattern (): ? string
558
+ public function getPattern (): null | string
543
559
{
544
560
return $ this ->pattern ;
545
561
}
@@ -548,7 +564,7 @@ public function getPattern(): ?string
548
564
* @param string|null $pattern
549
565
* @return \DCarbone\PHPFHIR\Definition\Type
550
566
*/
551
- public function setPattern (? string $ pattern ): Type
567
+ public function setPattern (null | string $ pattern ): Type
552
568
{
553
569
$ this ->pattern = $ pattern ;
554
570
return $ this ;
@@ -557,7 +573,7 @@ public function setPattern(?string $pattern): Type
557
573
/**
558
574
* @return \DCarbone\PHPFHIR\Definition\Type|null
559
575
*/
560
- public function getComponentOfType (): ? Type
576
+ public function getComponentOfType (): null | Type
561
577
{
562
578
return $ this ->componentOfType ;
563
579
}
@@ -627,7 +643,7 @@ public function setUnionOf(array $unionOf): Type
627
643
/**
628
644
* @return string|null
629
645
*/
630
- public function getRestrictionBaseFHIRName (): ? string
646
+ public function getRestrictionBaseFHIRName (): null | string
631
647
{
632
648
return $ this ->restrictionBaseFHIRName ;
633
649
}
@@ -645,7 +661,7 @@ public function setRestrictionBaseFHIRName(string $restrictionBaseFHIRName): Typ
645
661
/**
646
662
* @return \DCarbone\PHPFHIR\Definition\Type|null
647
663
*/
648
- public function getRestrictionBaseFHIRType (): ? Type
664
+ public function getRestrictionBaseFHIRType (): null | Type
649
665
{
650
666
return $ this ->restrictionBaseFHIRType ;
651
667
}
@@ -758,13 +774,32 @@ public function getDirectlyUsedTraits(): array
758
774
{
759
775
$ traits = [];
760
776
$ parentType = $ this ->getParentType ();
777
+
761
778
if (null === $ parentType ) {
779
+ // if this type has no parent(s), try to add all traits
780
+
762
781
if ($ this ->isCommentContainer ()) {
763
782
$ traits [] = PHPFHIR_TRAIT_COMMENT_CONTAINER ;
764
783
}
765
- $ traits [] = PHPFHIR_TRAIT_VALIDATION_ASSERTIONS ;
766
- $ traits [] = PHPFHIR_TRAIT_CHANGE_TRACKING ;
767
- $ traits [] = PHPFHIR_TRAIT_XMLNS ;
784
+
785
+ // these must only be added if the type has local properties
786
+ if ($ this ->hasLocalProperties ()) {
787
+ array_push (
788
+ $ traits ,
789
+ PHPFHIR_TRAIT_VALIDATION_ASSERTIONS ,
790
+ PHPFHIR_TRAIT_CHANGE_TRACKING ,
791
+ PHPFHIR_TRAIT_XMLNS ,
792
+ );
793
+ }
794
+ } else if (!$ parentType ->hasLocalProperties ()) {
795
+ // if this type _does_ have a parent, only add these traits if the parent does not have local properties
796
+
797
+ array_push (
798
+ $ traits ,
799
+ PHPFHIR_TRAIT_VALIDATION_ASSERTIONS ,
800
+ PHPFHIR_TRAIT_CHANGE_TRACKING ,
801
+ PHPFHIR_TRAIT_XMLNS ,
802
+ );
768
803
}
769
804
770
805
return $ traits ;
@@ -789,7 +824,7 @@ public function hasCommentContainerParent(): bool
789
824
*/
790
825
public function setCommentContainer (bool $ commentContainer ): Type
791
826
{
792
- $ this ->commentContainer = ( bool ) $ commentContainer ;
827
+ $ this ->commentContainer = $ commentContainer ;
793
828
return $ this ;
794
829
}
795
830
0 commit comments