Skip to content

Commit

Permalink
tidy up variable naming and scoping, comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jantari committed Mar 8, 2023
1 parent f3b7e4e commit 63a419e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion LSUClient.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ class PackageXmlPointer : PackageFilePointer {
}

# Private
class PackagePhase2Info {
class PackageDependenciesInfo {
[string] $Version
[System.Xml.XmlElement] $Dependencies
[string] $LocalPackageRoot
Expand Down
2 changes: 1 addition & 1 deletion private/Test-MachineSatisfiesDependency.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
return -1
}
'_Coreq' {
$DependencyPackage = $script:AllPackagesDependencyInfo[$Dependency.name]
$DependencyPackage = $AllPackagesDependenciesInfo[$Dependency.name]
if ($DependencyPackage) {
if ($DependencyPackage.IsInstalled) {
Write-Debug "$('- ' * $DebugIndent)[ Got: $($Dependency.name) $($DependencyPackage.Version), Expected: $($Dependency.Version) ]"
Expand Down
30 changes: 12 additions & 18 deletions public/Get-LSUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -162,23 +162,17 @@
throw "No packages for computer model '${Model}' could be retrieved from repository '${Repository}'"
}

# This will hold the packages as they are evaluated in two stages
$PackageList = [System.Collections.Generic.List[LenovoPackage]]::new()

# Information for package dependency evaluation.
# For Dependency and Coreq tests we need all packages:
# - Name
# - Version
# - IsInstalled
# - Dependencies XML
# - LocalPackageRoot
$script:AllPackagesDependencyInfo = [System.Collections.Generic.Dictionary[string, PackagePhase2Info]]::new()

Write-Verbose "A total of $($PackagePointers.Count) driver packages are available for this computer model."

# This variable will hold the LenovoPackage objects as they are processed in two stages
New-Variable -Name PackageList -Option Private -Value ( [System.Collections.Generic.List[LenovoPackage]]::new() )

# This variable will hold additional metadata that needs to be referenced from nested scopes (functions) during dependency tests
New-Variable -Name AllPackagesDependenciesInfo -Option AllScope -Value ( [System.Collections.Generic.Dictionary[string, PackageDependenciesInfo]]::new() )
}

process {
# Process most parts of the packages XML, only dependencies will be resolved separately later to support Coreq
# Stage 1 of 2 : Process most parts of the packages XML, only dependencies will be resolved later to support Coreq (package inter-dependency) tests
foreach ($Package in $PackagePointers) {
Write-Verbose "Processing package $($Package.AbsoluteLocation)"

Expand Down Expand Up @@ -309,28 +303,28 @@
'Files' = $PackageFiles
'Extracter' = $packageXML.Package
'Installer' = [PackageInstallInfo]::new($packageXML.Package)
'IsApplicable' = $null # TBD
'IsApplicable' = $null # Package applicability is determined later in stage 2
'IsInstalled' = $PackageIsInstalled
}

$PackageList.Add($packageObject)
$script:AllPackagesDependencyInfo.Add($packageXML.Package.name, [PackagePhase2Info]@{
$AllPackagesDependenciesInfo.Add($packageXML.Package.name, [PackageDependenciesInfo]@{
'Version' = $packageXML.Package.version
'IsInstalled' = $PackageIsInstalled
'Dependencies' = $packageXML.Package.Dependencies
'LocalPackageRoot' = $LocalPackageRoot
})
}
# Process package dependencies (IsApplicable)
# Stage 2 of 2 : Process package dependencies (determines IsApplicable)
foreach ($Package in $PackageList) {
$PackagePhase2Info = $script:AllPackagesDependencyInfo[$Package.Name]
$CurrentPackageDependenciesInfo = $AllPackagesDependenciesInfo[$Package.Name]

# The explicit $null is to avoid powershell/powershell#13651
[Nullable[bool]]$PackageIsApplicable = if ($NoTestApplicable) {
$null
} else {
Write-Verbose "Parsing dependencies for package: $($Package.ID) ($($Package.Title))"
Resolve-XMLDependencies -XMLIN $PackagePhase2Info.Dependencies -TreatUnsupportedAsPassed:(-not $FailUnsupportedDependencies) -PackagePath $PackagePhase2Info.LocalPackageRoot
Resolve-XMLDependencies -XMLIN $CurrentPackageDependenciesInfo.Dependencies -TreatUnsupportedAsPassed:(-not $FailUnsupportedDependencies) -PackagePath $CurrentPackageDependenciesInfo.LocalPackageRoot
}

$Package.IsApplicable = $PackageIsApplicable
Expand Down

1 comment on commit 63a419e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PSScriptAnalyzer results as of this commit:

  • 2 Information
  • 8 Warning
See details
Location : ./public/Install-LSUpdate.ps1 [135, 21]
RuleName : PSUseOutputTypeCorrectly
Severity : Information
Message  : The cmdlet 'Install-LSUpdate' returns an object of type 'PackageInstallResult
           ' but this type is not declared in the OutputType attribute.

Location : ./public/Install-LSUpdate.ps1 [172, 21]
RuleName : PSUseOutputTypeCorrectly
Severity : Information
Message  : The cmdlet 'Install-LSUpdate' returns an object of type 'PackageInstallResult
           ' but this type is not declared in the OutputType attribute.

Location : ./public/Set-LSUClientConfiguration.ps1 [1, 10]
RuleName : PSUseShouldProcessForStateChangingFunctions
Severity : Warning
Message  : Function 'Set-LSUClientConfiguration' has verb that could change system state
           . Therefore, the function has to support 'ShouldProcess'.

Location : ./private/Compare-Array.ps1 [30, 17]
RuleName : PSReviewUnusedParameter
Severity : Warning
Message  : The parameter 'in' has been declared but not used. 

Location : ./private/Set-BIOSUpdateRegistryFlag.ps1 [1, 10]
RuleName : PSUseShouldProcessForStateChangingFunctions
Severity : Warning
Message  : Function 'Set-BIOSUpdateRegistryFlag' has verb that could change system state
           . Therefore, the function has to support 'ShouldProcess'.

Location : ./private/Split-ExecutableAndArguments.ps1 [1, 10]
RuleName : PSUseSingularNouns
Severity : Warning
Message  : The cmdlet 'Split-ExecutableAndArguments' uses a plural noun. A singular noun
            should be used instead.

Location : ./private/Invoke-PackageCommand.ps1 [293, 25]
RuleName : PSAvoidUsingEmptyCatchBlock
Severity : Warning
Message  : Empty catch block is used. Please use Write-Error or throw statements in catc
           h blocks.

Location : ./private/Debug-LongRunningProcess.ps1 [44, 13]
RuleName : PSAvoidUsingEmptyCatchBlock
Severity : Warning
Message  : Empty catch block is used. Please use Write-Error or throw statements in catc
           h blocks.

Location : ./private/Debug-LongRunningProcess.ps1 [126, 82]
RuleName : PSReviewUnusedParameter
Severity : Warning
Message  : The parameter 'lParam' has been declared but not used. 

Location : ./private/Resolve-XMLDependencies.ps1 [1, 10]
RuleName : PSUseSingularNouns
Severity : Warning
Message  : The cmdlet 'Resolve-XMLDependencies' uses a plural noun. A singular noun shou
           ld be used instead.

Please sign in to comment.