Skip to content

Add templated types to getSegmentsByClass and getFirstSegmentInstanceByClass - #145

Merged
senaranya merged 1 commit into
senaranya:masterfrom
jay-knight:feature/template-types-for-getSegmentsByClass
Aug 18, 2026
Merged

senaranya merged 1 commit into
senaranya:masterfrom
jay-knight:feature/template-types-for-getSegmentsByClass

Conversation

@jay-knight

Copy link
Copy Markdown
Contributor

Consider code like

$ORC = $message->getFirstSegmentInstanceByClass(ORC::class);
$ORC->getOrderControl();

PHPStan will complain that Call to an undefined method Aranyasen\HL7\Segment::getOrderControl(). This is because that function declares that it will return a Segment object, but it doesn't specify which subclass of Segment, so it doesn't know to look in the ORC class for the method. Using the @template phpdoc annotation, you can specify that the return type will be the same as the class string you pass in.

This PR adds this, which resolves a lot of PHPstan errors in our codebase.

@senaranya senaranya self-assigned this Aug 18, 2026
@senaranya senaranya changed the title Add templated types to getSegmentsByClass and getFirstSegmentInstanceByClass Add generics to getSegmentsByClass & getFirstSegmentInstanceByClass Aug 18, 2026
@senaranya
senaranya merged commit 8dfc721 into senaranya:master Aug 18, 2026
4 checks passed
@senaranya senaranya changed the title Add generics to getSegmentsByClass & getFirstSegmentInstanceByClass Add templated types to getSegmentsByClass and getFirstSegmentInstanceByClass Aug 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants