class FightAggregator (View source)

The FightAggregator is responsible for merging two FightDTOs that represent the same fight.

It uses a FighterAggregator to merge the fighter information for both the red and blue corners. The merge function combines two FightDTOs into one, preferring non-null values and resolving conflicts. The isSameFight function determines if two FightDTOs represent the same fight based on their fighters.

Example usage: $agg = new FightAggregator(new FighterAggregator()); $fight1 = new FightDTO(redFighter: new FighterDTO(name: 'Fighter A'), blueFighter: new FighterDTO(name: 'Fighter B')); $fight2 = new FightDTO(redFighter: new FighterDTO(name: 'Fighter A'), blueFighter: new FighterDTO(name: 'Fighter B')); if ($agg->isSameFight($fight1, $fight2)) { $merged = $agg->merge($fight1, $fight2); // $merged will have merged fighter information and other details from both fights }

Methods

__construct(FighterAggregator $fighterAggregator)

Constructs a new FightAggregator with a FighterAggregator dependency.

merge(FightDTO $a, FightDTO $b)

Merges two FightDTOs into one, preferring non-null values and resolving conflicts.

bool
isSameFight(FightDTO $a, FightDTO $b)

Determines if two FightDTOs represent the same fight based on their fighters.

Details

__construct(FighterAggregator $fighterAggregator)

Constructs a new FightAggregator with a FighterAggregator dependency.

Parameters

FighterAggregator $fighterAggregator

The FighterAggregator to use for merging fighter information.

FightDTO merge(FightDTO $a, FightDTO $b)

Merges two FightDTOs into one, preferring non-null values and resolving conflicts.

Throws an exception if the fights are determined to be different.

Parameters

FightDTO $a

The first fight to merge.

FightDTO $b

The second fight to merge.

Return Value

FightDTO

The merged fight.

Exceptions

InvalidArgumentException

bool isSameFight(FightDTO $a, FightDTO $b)

Determines if two FightDTOs represent the same fight based on their fighters.

Parameters

FightDTO $a

The first fight to compare.

FightDTO $b

The second fight to compare.

Return Value

bool

True if the fights are considered the same, false otherwise.