< Summary

Information
Class: Punch.CLI.PunchSettings
Assembly: punch
File(s): /home/runner/work/punch/punch/src/Punch.CLI/PunchSettings.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 32
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_TargetHours()100%11100%
get_TargetHoursByDay()100%11100%
GetTargetHours(...)100%66100%

File(s)

/home/runner/work/punch/punch/src/Punch.CLI/PunchSettings.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3
 4namespace Punch.CLI;
 5
 6// User-configurable settings, loaded from ~/.punch/settings.json. Also serves as
 7// the JSON serialization shape. Missing or invalid values fall back to defaults.
 8internal sealed class PunchSettings
 9{
 10    // The daily workday goal in whole hours, used for the status-bar percentage.
 2511    public int TargetHours { get; set; } = 8;
 12
 13    // Optional per-day overrides keyed by day name ("monday".."sunday",
 14    // case-insensitive). Days not listed fall back to TargetHours. A value of 0
 15    // marks a day off (the status bar then omits the percentage).
 1416    public Dictionary<string, int>? TargetHoursByDay { get; set; }
 17
 18    // Resolves the target for a given weekday: the per-day override if one is
 19    // present (clamped to >= 0), otherwise the flat TargetHours.
 20    public int GetTargetHours(DayOfWeek day)
 621    {
 622        if (TargetHoursByDay is not null)
 523        {
 2524            foreach (var (key, value) in TargetHoursByDay)
 725            {
 726                if (string.Equals(key, day.ToString(), StringComparison.OrdinalIgnoreCase))
 427                    return Math.Max(0, value);
 328            }
 129        }
 230        return TargetHours;
 631    }
 32}