< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Sorting.DatePlayedComparer
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Sorting/DatePlayedComparer.cs
Line coverage
16%
Covered lines: 1
Uncovered lines: 5
Coverable lines: 6
Total lines: 70
Line coverage: 16.6%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Type()100%11100%
Compare(...)100%210%
GetDate(...)0%2040%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Sorting/DatePlayedComparer.cs

#LineLine coverage
 1#nullable disable
 2
 3using System;
 4using Jellyfin.Data.Entities;
 5using Jellyfin.Data.Enums;
 6using MediaBrowser.Controller.Entities;
 7using MediaBrowser.Controller.Library;
 8using MediaBrowser.Controller.Sorting;
 9using MediaBrowser.Model.Querying;
 10
 11namespace Emby.Server.Implementations.Sorting
 12{
 13    /// <summary>
 14    /// Class DatePlayedComparer.
 15    /// </summary>
 16    public class DatePlayedComparer : IUserBaseItemComparer
 17    {
 18        /// <summary>
 19        /// Gets or sets the user.
 20        /// </summary>
 21        /// <value>The user.</value>
 22        public User User { get; set; }
 23
 24        /// <summary>
 25        /// Gets or sets the user manager.
 26        /// </summary>
 27        /// <value>The user manager.</value>
 28        public IUserManager UserManager { get; set; }
 29
 30        /// <summary>
 31        /// Gets or sets the user data repository.
 32        /// </summary>
 33        /// <value>The user data repository.</value>
 34        public IUserDataManager UserDataRepository { get; set; }
 35
 36        /// <summary>
 37        /// Gets the name.
 38        /// </summary>
 39        /// <value>The name.</value>
 140        public ItemSortBy Type => ItemSortBy.DatePlayed;
 41
 42        /// <summary>
 43        /// Compares the specified x.
 44        /// </summary>
 45        /// <param name="x">The x.</param>
 46        /// <param name="y">The y.</param>
 47        /// <returns>System.Int32.</returns>
 48        public int Compare(BaseItem x, BaseItem y)
 49        {
 050            return GetDate(x).CompareTo(GetDate(y));
 51        }
 52
 53        /// <summary>
 54        /// Gets the date.
 55        /// </summary>
 56        /// <param name="x">The x.</param>
 57        /// <returns>DateTime.</returns>
 58        private DateTime GetDate(BaseItem x)
 59        {
 060            var userdata = UserDataRepository.GetUserData(User, x);
 61
 062            if (userdata is not null && userdata.LastPlayedDate.HasValue)
 63            {
 064                return userdata.LastPlayedDate.Value;
 65            }
 66
 067            return DateTime.MinValue;
 68        }
 69    }
 70}