Repository: PowerShell/PowerShell
File: src/System.Management.Automation/engine/CommandCompletion/CompletionCompleters.cs (C#)

Code before:
            string[] moduleNames;
            WildcardPattern shortNamePattern;
            if (shortNameSearch)
            {
                moduleNames = new string[] { wordToComplete, "*." + wordToComplete };
                shortNamePattern = new WildcardPattern(wordToComplete, WildcardOptions.IgnoreCase);
            }
            else
            {
                moduleNames = new string[] { wordToComplete };
                shortNamePattern = null;
            }

            var powershell = context.Helper.AddCommandWithPreferenceSetting("Get-Module", typeof(GetModuleCommand)).AddParameter("Name", moduleNames);
            if (!loadedModulesOnly)
            {
                powershell.AddParameter("ListAvailable", true);

                // -SkipEditionCheck should only be set or apply to -ListAvailable
                if (skipEditionCheck)
                {
                    powershell.AddParameter("SkipEditionCheck", true);
                }
            }

            var psObjects = context.Helper.ExecuteCurrentPowerShell(out _);

            if (psObjects != null)
            {
                foreach (PSObject item in psObjects)
                {
                    var moduleInfo = (PSModuleInfo)item.BaseObject;
                    var completionText = moduleInfo.Name;
                    var listItemText = completionText;
                    if (shortNameSearch
                        && completionText.Contains('.')
                        && !shortNamePattern.IsMatch(completionText.Substring(completionText.LastIndexOf('.') + 1))
                        && !shortNamePattern.IsMatch(completionText))
                    {
                        continue;
                    }

                    var toolTip = "Description: " + moduleInfo.Description + "\r\nModuleType: "
                                  + moduleInfo.ModuleType.ToString() + "\r\nPath: "
                                  + moduleInfo.Path;

                    if (CompletionRequiresQuotes(completionText, false))
                    {
                        var quoteInUse = quote == string.Empty ? "'" : quote;
                        if (quoteInUse == "'")
                            completionText = completionText.Replace("'", "''");

Review comment (refactor):
It is not clear for reader that we get a collection of PSObjects. Please use explicit type.
```suggestion
            Collection<PSObject> psObjects = context.Helper.ExecuteCurrentPowerShell(out _);
```

Code after:
            string[] moduleNames;
            WildcardPattern shortNamePattern;
            if (shortNameSearch)
            {
                moduleNames = new string[] { wordToComplete, "*." + wordToComplete };
                shortNamePattern = new WildcardPattern(wordToComplete, WildcardOptions.IgnoreCase);
            }
            else
            {
                moduleNames = new string[] { wordToComplete };
                shortNamePattern = null;
            }

            var powershell = context.Helper.AddCommandWithPreferenceSetting("Get-Module", typeof(GetModuleCommand)).AddParameter("Name", moduleNames);
            if (!loadedModulesOnly)
            {
                powershell.AddParameter("ListAvailable", true);

                // -SkipEditionCheck should only be set or apply to -ListAvailable
                if (skipEditionCheck)
                {
                    powershell.AddParameter("SkipEditionCheck", true);
                }
            }

            Collection<PSObject> psObjects = context.Helper.ExecuteCurrentPowerShell(out _);

            if (psObjects != null)
            {
                foreach (PSObject item in psObjects)
                {
                    var moduleInfo = (PSModuleInfo)item.BaseObject;
                    var completionText = moduleInfo.Name;
                    var listItemText = completionText;
                    if (shortNameSearch
                        && completionText.Contains('.')
                        && !shortNamePattern.IsMatch(completionText.Substring(completionText.LastIndexOf('.') + 1))
                        && !shortNamePattern.IsMatch(completionText))
                    {
                        continue;
                    }

                    var toolTip = "Description: " + moduleInfo.Description + "\r\nModuleType: "
                                  + moduleInfo.ModuleType.ToString() + "\r\nPath: "
                                  + moduleInfo.Path;

                    if (CompletionRequiresQuotes(completionText, false))
                    {
                        var quoteInUse = quote == string.Empty ? "'" : quote;
                        if (quoteInUse == "'")
                            completionText = completionText.Replace("'", "''");