public static function buildFrom(StreamEvents $events): Aggregate {
        $aggregate = new static;
        $events->each(function (StreamEvent $event) use ($aggregate) {
            $aggregate->apply($event->event());
            if ( ! $event->version()->equals($aggregate->aggregateVersion())) {
                throw new UnexpectedAggregateVersionWhenBuildingFromEvents("When building from stream events aggregate {$aggregate->aggregateId()->toString()} expected version {$event->version()->toInt()} but got {$aggregate->aggregateVersion()->toInt()}.");
            }
        });
        return $aggregate;
    }
public static function buildFrom(StreamEvents $events): Aggregate {
        $aggregate = new static;
        $events->each(function (StreamEvent $event) use ($aggregate) {
            $aggregate->apply($event->event());
            if ( ! $event->version()->equals($aggregate->aggregateVersion())) {
                throw new UnexpectedAggregateVersionWhenBuildingFromEvents("When building from stream events aggregate {$aggregate->aggregateId()->toString()} expected version {$event->version()->toInt()} but got {$aggregate->aggregateVersion()->toInt()}.");
            }
        });
        return $aggregate;
    }
public static function buildFrom ( StreamEvents $ events ) : Aggregate { $ aggregate = new static ; $ events -> each ( function ( StreamEvent $ event ) use ( $ aggregate ) { $ aggregate -> apply ( $ event -> event ( ) ) ; if ( ! $ event -> version ( ) -> equals ( $ aggregate -> aggregateVersion ( ) ) ) { throw new UnexpectedAggregateVersionWhenBuildingFromEvents ( "When building from stream events aggregate {$aggregate->aggregateId()->toString()} expected version {$event->version()->toInt()} but got {$aggregate->aggregateVersion()->toInt()}." ) ; } } ) ; return $ aggregate ; }
reconstruct the aggregate state from domain events

@param StreamEvents $events
@return Aggregate
reconstruct the aggregate state from domain events