Skip to content

Commit

Permalink
Fix DeepSource Issues
Browse files Browse the repository at this point in the history
Fixed issues:
- Parameters marked as in, out or ref should always be placed after all the required parameters CS-R1138 (VideoUtils.cs)
- Abrupt application exit CS-W1005 [ignored issue] (Program.cs)
- Variable is uninitialized CS-W1022 (VideoUtils.cs)
-  if statement can be rewritten using the ternary operator CS-R1105 (VideoUtils.cs)
  • Loading branch information
HEJOK254 committed Jun 17, 2024
1 parent 3bbde4b commit dd000a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
22 changes: 8 additions & 14 deletions Commands/Modules/VideoUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,12 @@ public async Task TrimVideoAsync(
}

// Get TimeSpans
TimeSpan trimStart;
TimeSpan trimEnd;
TimeSpan trimStart = TimeSpan.Zero;
TimeSpan trimEnd = TimeSpan.Zero;
try {
if (!string.IsNullOrEmpty(trimStartString)) // Avoid invalid format exceptions
trimStart = TimeSpanFromHMS(trimStartString);
else
trimStart = TimeSpan.Zero;

if (!string.IsNullOrEmpty(trimEndString)) // Avoid invalid format exceptions
trimEnd = TimeSpanFromHMS(trimEndString);
else
trimEnd = TimeSpan.Zero;
// Avoid invalid format exceptions
if (!string.IsNullOrEmpty(trimStartString)) trimStart = TimeSpanFromHMS(trimStartString);
if (!string.IsNullOrEmpty(trimEndString)) trimEnd = TimeSpanFromHMS(trimEndString);
} catch (Exception e) {
if (e is ArgumentException)
{
Expand All @@ -78,7 +72,7 @@ public async Task TrimVideoAsync(
await DownloadVideoAsync(video.Url, videoInputPath);

var mediaInfo = await FFProbe.AnalyseAsync(videoInputPath);
CheckTimes(ref trimStart, ref trimEnd, mediaInfo.Duration);
CheckTimes(mediaInfo.Duration, ref trimStart, ref trimEnd);

// Check if the temporary directory, where the video is supposed to be exists
if (!Directory.Exists("./tmp"))
Expand All @@ -103,10 +97,10 @@ public async Task TrimVideoAsync(
/// <item>Set <paramref name="trimStart"/> to <c>0</c> if it's greater or equal to the video's <paramref name="duration"/></item>
/// </list>
/// </summary>
/// <param name="duration">Duration of the video</param>
/// <param name="trimStart">Start of the trim</param>
/// <param name="trimEnd">End of the trim</param>
/// <param name="duration">Duration of the video</param>
private static void CheckTimes(ref TimeSpan trimStart, ref TimeSpan trimEnd, TimeSpan duration)
private static void CheckTimes(TimeSpan duration, ref TimeSpan trimStart, ref TimeSpan trimEnd)
{
// Set trimEnd to duration if smaller or equal to trimStart
if (trimEnd <= trimStart)
Expand Down
3 changes: 2 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ private async Task OnReadyAsync()
catch
{
await LogAsync("Program", "Exiting", LogSeverity.Info);
Environment.Exit(1);
// The program cannot continue without the InteractionService, so terminate it. Nothing important should be running at this point.
Environment.Exit(1); // skipcq: CS-W1005
}
}

Expand Down

0 comments on commit dd000a3

Please sign in to comment.