Replace magic number -1 with named constant for better code clarity

Co-authored-by: THoguet <61246905+THoguet@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]andTHoguet committed 2025-11-01 21:07:17 +00:00
1 parent 6061e02835
commit dbf504b060
1 file changed
+8 -5
+8 -5
View File
@@ -292,6 +292,9 @@ export class SelectedDates implements SelectedDateInterface {
private minDate: Date | null = null; private minDate: Date | null = null;
private maxDate: Date | null = null; private maxDate: Date | null = null;
// Constant to indicate no valid strategy was found
private static readonly NO_VALID_STRATEGY_HEURISTIC = -1;
update(): void { update(): void {
this.datesSelected = this._datesSelected.slice(); this.datesSelected = this._datesSelected.slice();
this.grouping(); this.grouping();
@@ -524,21 +527,21 @@ export class SelectedDates implements SelectedDateInterface {
if (calendarSettingsService.samediMalin()) this.samediMalin(vacationsNumber); if (calendarSettingsService.samediMalin()) this.samediMalin(vacationsNumber);
while (vacationsNumber.cp > 0) { while (vacationsNumber.cp > 0) {
const result = this.lookForVacation(DayType.CP); const result = this.lookForVacation(DayType.CP);
if (result.heuristic === -1) { if (result.heuristic === SelectedDates.NO_VALID_STRATEGY_HEURISTIC) {
break; break;
} }
vacationsNumber.cp -= 1; vacationsNumber.cp -= 1;
} }
while (vacationsNumber.rtt > 0) { while (vacationsNumber.rtt > 0) {
const result = this.lookForVacation(DayType.RTT); const result = this.lookForVacation(DayType.RTT);
if (result.heuristic === -1) { if (result.heuristic === SelectedDates.NO_VALID_STRATEGY_HEURISTIC) {
break; break;
} }
vacationsNumber.rtt -= 1; vacationsNumber.rtt -= 1;
} }
while (vacationsNumber.other > 0) { while (vacationsNumber.other > 0) {
const result = this.lookForVacation(DayType.OTHER); const result = this.lookForVacation(DayType.OTHER);
if (result.heuristic === -1) { if (result.heuristic === SelectedDates.NO_VALID_STRATEGY_HEURISTIC) {
break; break;
} }
vacationsNumber.other -= 1; vacationsNumber.other -= 1;
@@ -723,7 +726,7 @@ export class SelectedDates implements SelectedDateInterface {
// Early exit if no candidates // Early exit if no candidates
if (candidateDays.length === 0) { if (candidateDays.length === 0) {
return { apply: () => {}, heuristic: -1 }; return { apply: () => {}, heuristic: SelectedDates.NO_VALID_STRATEGY_HEURISTIC };
} }
const tempDatesBackup = [...this._datesSelected]; const tempDatesBackup = [...this._datesSelected];
@@ -773,6 +776,6 @@ export class SelectedDates implements SelectedDateInterface {
return bestStrategy; return bestStrategy;
} }
return { apply: () => {}, heuristic: -1 }; return { apply: () => {}, heuristic: SelectedDates.NO_VALID_STRATEGY_HEURISTIC };
} }
} }