src/Measurements/Time/BonusAdjustmentByTimeTable.php
/**
     * Warning! Only activity with unlimited maximal time can get bonus by taking more time (slowing down),
     * other activities can get only malus by speeding up.
     *
     * @param Time $originalActivityTime
     * @param int |PositiveInteger $hoursPerDay
     * @param bool $activityIsNotLimitedByTime
     * @return Time
     * @throws \DrdPlus\Tables\Measurements\Time\Exceptions\CanNotProlongActivityPerDayWithLimitedTime
     * @throws \DrdPlus\Tables\Measurements\Time\Exceptions\NotApplicableOnShorterThanDay
     * @throws \DrdPlus\Tables\Measurements\Time\Exceptions\UnexpectedHoursPerDayForTimeBonusAdjustment
     * @throws \DrdPlus\Tables\Measurements\Time\Exceptions\CanNotConvertThatBonusToTime
     * @throws \DrdPlus\Tables\Partials\Exceptions\RequiredColumnNotFound
     * @throws \Granam\Integer\Tools\Exceptions\WrongParameterType
     * @throws \Granam\Integer\Tools\Exceptions\ValueLostOnCast
     */
Warning. Only activity with unlimited maximal time can get bonus by taking more time (slowing down),
other activities can get only malus by speeding up.


Warning . Only activity with unlimited maximal time can get bonus by taking more time ( slowing down ) other activities can get only malus by speeding up .
public function adjustTimeByHoursPerDay(
        Time $originalActivityTime,
        $hoursPerDay,
        bool $activityIsNotLimitedByTime
    ): Time
    {
        $inDays = $originalActivityTime->findDays();
        if (($inDays !== null && $inDays->getValue() < 1)
            || (!$inDays instanceof \DrdPlus\Tables\Measurements\Time\Time && $originalActivityTime->findMonths() === null && $originalActivityTime->findYears() === null)
        ) {
            throw new Exceptions\NotApplicableOnShorterThanDay(
                'Only at least one day of activity can be adjusted by change of hours of such activity, got '
                . $originalActivityTime->getValue() . ' ' . $originalActivityTime->getUnit() . '(s)'
            );
        }
        $hoursPerDay = ToInteger::toPositiveInteger($hoursPerDay);
        if (!$activityIsNotLimitedByTime && $hoursPerDay > Time::HOURS_PER_DAY) {
            throw new Exceptions\CanNotProlongActivityPerDayWithLimitedTime(
                'Got request to prolong activity by ' . $hoursPerDay . ' hours per day with original activity time '
                . $originalActivityTime->getValue() . ' ' . $originalActivityTime->getUnit() . '(s)'
            );
        }
        $bonusAdjustment = $this->getBonusAdjustmentForHoursPerDay($hoursPerDay);
        $finalBonusValue = $originalActivityTime->getBonus()->getValue() + $bonusAdjustment;
        $finalBonus = new TimeBonus($finalBonusValue, $this->timeTable);
        $finalTime = $finalBonus->findTime($originalActivityTime->getUnit());
        if ($finalTime !== null) {
            return $finalTime;
        }
        return $finalBonus->getTime();
    }
public function adjustTimeByHoursPerDay ( Time $ originalActivityTime , $ hoursPerDay , bool $ activityIsNotLimitedByTime ) : Time { $ inDays = $ originalActivityTime -> findDays ( ) ; if ( ( $ inDays !== null && $ inDays -> getValue ( ) < 1 ) || ( ! $ inDays instanceof \ DrdPlus \ Tables \ Measurements \ Time \ Time && $ originalActivityTime -> findMonths ( ) === null && $ originalActivityTime -> findYears ( ) === null ) ) { throw new Exceptions \ NotApplicableOnShorterThanDay ( 'Only at least one day of activity can be adjusted by change of hours of such activity, got ' . $ originalActivityTime -> getValue ( ) . ' ' . $ originalActivityTime -> getUnit ( ) . '(s)' ) ; } $ hoursPerDay = ToInteger :: toPositiveInteger ( $ hoursPerDay ) ; if ( ! $ activityIsNotLimitedByTime && $ hoursPerDay > Time :: HOURS_PER_DAY ) { throw new Exceptions \ CanNotProlongActivityPerDayWithLimitedTime ( 'Got request to prolong activity by ' . $ hoursPerDay . ' hours per day with original activity time ' . $ originalActivityTime -> getValue ( ) . ' ' . $ originalActivityTime -> getUnit ( ) . '(s)' ) ; } $ bonusAdjustment = $ this -> getBonusAdjustmentForHoursPerDay ( $ hoursPerDay ) ; $ finalBonusValue = $ originalActivityTime -> getBonus ( ) -> getValue ( ) + $ bonusAdjustment ; $ finalBonus = new TimeBonus ( $ finalBonusValue , $ this -> timeTable ) ; $ finalTime = $ finalBonus -> findTime ( $ originalActivityTime -> getUnit ( ) ) ; if ( $ finalTime !== null ) { return $ finalTime ; } return $ finalBonus -> getTime ( ) ; }
Warning!
Warning!
/** @noinspection ExceptionsAnnotatingAndHandlingInspection */ /** @noinspection ExceptionsAnnotatingAndHandlingInspection */