0

このメソッドの保守性指数 (Visual Studio で計算) が 40 しかない理由がわかりません。60 を超えるには、最初の 2 行を除くほぼすべての行を文字通り削除する必要があります。

    public void getNewPasswordDetails(Int32 newPasswordId)
    {

        int UserId = HttpContext.Current.User.Identity.GetUserId().ToInt();
        bool userIsAdmin = HttpContext.Current.User.IsInRole("Administrator");

        //get a list of userIds that have UserPassword records for this password
        var UserIDList = DatabaseContext.UserPasswords.Where(up => up.PasswordId == newPasswordId).Select(up => up.Id).ToList();

        //Retrive the password -if the user has access
        Password newPassword = DatabaseContext.Passwords
                                                        .Include("Creator")
                                                        .Where(pass => !pass.Deleted
                                                        && (
                                                            (UserIDList.Contains(UserId))
                                                         || (userIsAdmin && ApplicationSettings.Default.AdminsHaveAccessToAllPasswords)
                                                         || pass.Creator_Id == UserId)
                                                            )
                                                            .Include(p => p.Parent_UserPasswords.Select(up => up.UserPasswordUser))
                                                            .SingleOrDefault(p => p.PasswordId == newPasswordId);



        if (newPassword != null)
        {
            //map new password to display view model
            AutoMapper.Mapper.CreateMap<Password, PasswordItem>();
            PasswordItem returnPasswordViewItem = AutoMapper.Mapper.Map<PasswordItem>(newPassword);

            //generate a string based view of the new category
            string passwordPartialView = RenderViewContent.RenderViewToString("Password", "_PasswordItem", returnPasswordViewItem);

            //broadcast the new password details
            PushNotifications.sendAddedPasswordDetails(passwordPartialView, returnPasswordViewItem.Parent_CategoryId, returnPasswordViewItem.PasswordId);
        }
        else
        {
            //we dont have access any more, so tell UI to remove the password
            PushNotifications.sendRemovePasswordAccess(new PasswordDelete()
                                                                { 
                                                                     PasswordId = newPasswordId
                                                                });
        }

    }
4

1 に答える 1