Skip to content

Commit

Permalink
comment and simplify flow a bit after 485be02
Browse files Browse the repository at this point in the history
  • Loading branch information
jantari committed Jan 20, 2024
1 parent a5cf2d3 commit 2381f5a
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions private/Resolve-XMLDependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,38 +23,42 @@
Write-Debug "$('- ' * $XMLTreeDepth)Switched state to: $ParserState"
}

$Result = if ($XMLTREE.SchemaInfo.Name -like "_*") {
switch (Test-MachineSatisfiesDependency -Dependency $XMLTREE -PackagePath $PackagePath -DebugIndent $XMLTreeDepth -FailInboxDrivers:$FailInboxDrivers) {
0 {
$true
}
-1 {
$false
}
-2 {
Write-Debug "$('- ' * $XMLTreeDepth)Something unsupported encountered in: $($XMLTREE.SchemaInfo.Name)"
if ($TreatUnsupportedAsPassed) { $true } else { $false }
$Result = switch -Wildcard ($XMLTREE.SchemaInfo.Name) {
'_*' {
switch (Test-MachineSatisfiesDependency -Dependency $XMLTREE -PackagePath $PackagePath -DebugIndent $XMLTreeDepth -FailInboxDrivers:$FailInboxDrivers) {
0 {
$true
}
-1 {
$false
}
-2 {
Write-Debug "$('- ' * $XMLTreeDepth)Something unsupported encountered in: $($XMLTREE.SchemaInfo.Name)"
if ($TreatUnsupportedAsPassed) { $true } else { $false }
}
}
}
} else {
$SubtreeResults = Resolve-XMLDependencies -XMLIN $XMLTREE.ChildNodes -PackagePath $PackagePath -TreatUnsupportedAsPassed:$TreatUnsupportedAsPassed -FailInboxDrivers:$FailInboxDrivers -ParentNodeIsAnd:($XMLTREE.SchemaInfo.Name -eq 'And')
switch ($XMLTREE.SchemaInfo.Name) {
'And' {
Write-Debug "$('- ' * $XMLTreeDepth)Tree was AND: Results: $subtreeresults"
if ($subtreeresults -contains $false) { $false } else { $true }
}
default {
Write-Debug "$('- ' * $XMLTreeDepth)Tree was OR: Results: $subtreeresults"
if ($subtreeresults -contains $true ) { $true } else { $false }
}
'And' {
$SubtreeResults = Resolve-XMLDependencies -XMLIN $XMLTREE.ChildNodes -PackagePath $PackagePath -TreatUnsupportedAsPassed:$TreatUnsupportedAsPassed -FailInboxDrivers:$FailInboxDrivers -ParentNodeIsAnd
Write-Debug "$('- ' * $XMLTreeDepth)Tree was AND: Results: $SubtreeResults"
if ($SubtreeResults -contains $false) { $false } else { $true }
}
default {
$SubtreeResults = Resolve-XMLDependencies -XMLIN $XMLTREE.ChildNodes -PackagePath $PackagePath -TreatUnsupportedAsPassed:$TreatUnsupportedAsPassed -FailInboxDrivers:$FailInboxDrivers
Write-Debug "$('- ' * $XMLTreeDepth)Tree was OR: Results: $SubtreeResults"
if ($SubtreeResults -contains $true ) { $true } else { $false }
}
}

Write-Debug "$('- ' * $XMLTreeDepth)< Returning $($Result -bxor $ParserState) from node $($XMLTREE.SchemaInfo.Name)"

$Result -bxor $ParserState

# If we're evaluating the children of an And-node, and we get a negative result before the last child-element,
# we can stop and don't have to process the remaining children anymore as the And-result will always be false.
# This speeds things up but it can also avoid even running problematic tests, e.g. some ExternalDetections.
if ($ParentNodeIsAnd -and $i -ne $XMLIN.Count -and -not ($Result -bxor $ParserState)) {
Write-Debug "$('- ' * $XMLTreeDepth)Quitting AND evaluation early because we already got one FALSE."
Write-Debug "$('- ' * $XMLTreeDepth)Stopping AND evaluation early"
$ParserState = 0 # DO_HAVE
break;
}
Expand Down

1 comment on commit 2381f5a

@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 : ./private/Compare-Array.ps1 [30, 17]
RuleName : PSReviewUnusedParameter
Severity : Warning
Message  : The parameter 'in' has been declared but not used. 

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

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/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.

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 [139, 82]
RuleName : PSReviewUnusedParameter
Severity : Warning
Message  : The parameter 'lParam' 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 : ./public/Install-LSUpdate.ps1 [152, 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 [189, 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'.

Please sign in to comment.