for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace EdifactParser;
use EdifactParser\Segments\SegmentInterface;
final class TransactionMessage
{
/**
* First string: segment key
* Second key: sub segment key.
*
* @psalm-var array<string, array<string,SegmentInterface>>
*/
private array $segments = [];
public static function withSegments(SegmentInterface...$segments): self
$self = new self();
foreach ($segments as $segment) {
$self->addSegment($segment);
}
return $self;
public function addSegment(SegmentInterface $segment): void
$name = $segment->name();
if (!isset($this->segments[$name])) {
$this->segments[$name] = [];
$this->segments[$name][$segment->subSegmentKey()] = $segment;
public function segments(): array
return $this->segments;