Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Write-CUClassDiagram #98

Open
Stephanevg opened this issue Mar 10, 2019 · 1 comment
Open

Refactor Write-CUClassDiagram #98

Stephanevg opened this issue Mar 10, 2019 · 1 comment

Comments

@Stephanevg
Copy link
Owner

Stephanevg commented Mar 10, 2019

The cmdlet is very big, and contains a lot of repetitive code.
It also calls two child functions, which are probably not necessary (New-GraphPArameters and New-CUGraphExport)

New-CUGraphParameters

  • Doesnt gatehr parameters, but actually generates the Graph (graphviz format).

this is the code of the function:

function New-CUGraphParameters {
    <#
    .SYNOPSIS
        Helper function to generate a Graph, wrap Out-CUPSGraph.
    .DESCRIPTION
        Helper function to generate a Graph, wrap Out-CUPSGraph.
    .NOTES
        Private function for PSClassUtils, used in Write-CUClassDiagram
    #>

    Param (
        $inputobject,
        $ignorecase,
        $showcomposition
    )

    $GraphParams = @{
        InputObject = $inputobject
    }

    If ( $ignorecase ) { $GraphParams.Add('IgnoreCase',$ignorecase) }
    If ( $showcomposition ) { $GraphParams.Add('ShowComposition',$showcomposition) }

    Out-CUPSGraph @GraphParams
    
}

New-CUGraphExport

This function is actually just a wrapper for Export-PSGraph, which needs a 'graph' as input.
In the current version, it is generated using Out-CUGraphParameters. (see above).

This is a wrapper for Out-CUPsGraph.

function New-CUGraphExport {
    <#
    .SYNOPSIS
        Helper function to generate a Graph export file, wraps Export-PSGraph.
    .DESCRIPTION
        Helper function to generate a Graph export file , wraps Export-PSGraph.
    .NOTES
        Private function for PSClassUtils, used in Write-CUClassDiagram
    #>

    param (
        $Graph,
        $PassThru,
        $Path,
        $ChildPath,
        $OutPutFormat,
        [Switch]$Show
    )
    
    $ExportParams = @{
        ShowGraph = $Show
        OutPutFormat = $OutPutFormat
        DestinationPath = Join-Path -Path $Path -ChildPath ($ChildPath+'.'+$OutPutFormat)
    }
    
    If ( $PassThru ) {
        $Graph
        $null = $Graph | Export-PSGraph @ExportParams
    } Else {
        $Graph | Export-PSGraph @ExportParams
    }

}

It would be nice to simplify this function, to enable potential futur extensions to it.
Some thoughts on how to achiev this:

  • Use Splatting
  • remove the two functions above.
  • Add a class CUDiagram --> See Here
@Stephanevg
Copy link
Owner Author

Stephanevg commented Mar 12, 2019

I have advanced pretty well.

It seems like most of the work for [CUDiagram] is done. I managed to keep things simple in this first version by reusing existing functions (Export-PSGraph).

Ideally, Export-PSGraph should also be refactored into a method in CUDiagram.

Open points:

Tests done:

  • One Class in one file

  • Multiple classes in one file
    Every class is displayed as beening in their own subgraph, with the subgraph as name. this is wrong. It should be grouped by the file name.
    image

  • Classses throughout different files
    Every class is in a subgraph with their own name. This is wrong, and should be the name of the file they were in.
    Also, several classes are in the same file (Pester.ps1 for example) and all these classes should be displayed as such.
    image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant