I want to access the value return by the child function when I call the parent function which also have a return value.
public function getUnitAndTotal(GetBillInfoRequest $request){ $data['unit_charge'] = (new CalculateMeterReadingUnitChargeTask($bill))->execute();
Parent Function: 1. public function execute() { $this->fetchChargeRange();
return $this->calculate();
}
-
public function calculate() { $amount = $this->getBill()->minimum_charge; $unitAndRange = $this->generateUnitAndRangeArray(); foreach ($unitAndRange as $u) $amount += ($u['unit'] * $u['range']->rate); // partial total return $amount; }
-
public function generateUnitAndRangeArray() { $unit = $this->calculateConsumeUnit(); $unitAndRange = []; foreach ($this->ranges as $range) { if($range->start < $unit) { if($range->end && $range->end < $unit) $unitAndRange[] = ['range' => $range, 'unit' => ($range->end - $range->start)]; else { $unitAndRange[] = ['range' => $range, 'unit' => ($unit - $range->start)]; break; } } }
return $unitAndRange;}
-
public function calculateConsumeUnit() { //TODO what if current reading is smaller than previous reading (new meter setup)? $unit = $this->getBill()->current_reading - $this->getBill()->previous_reading; return $unit; }
Since there are multiple function I want access the $unit return by the last function ( calculateConsumeUnit() ).
Aucun commentaire:
Enregistrer un commentaire