server/pkg/docker/image_build_response.go

Summary

Maintainability
D
1 day
Test Coverage
F
0%

Function ReadTarFromImageBuildResponse has a Cognitive Complexity of 65 (exceeds 20 allowed). Consider refactoring.
Open

func ReadTarFromImageBuildResponse(tarWriter, buildLogWriter io.Writer, response types.ImageBuildResponse) error {
    dec := json.NewDecoder(response.Body)
    currentState := checkingStartCode
    var codeCursor int
    var bufferedData []byte
Severity: Minor
Found in server/pkg/docker/image_build_response.go - About 7 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Function ReadTarFromImageBuildResponse has 73 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func ReadTarFromImageBuildResponse(tarWriter, buildLogWriter io.Writer, response types.ImageBuildResponse) error {
    dec := json.NewDecoder(response.Body)
    currentState := checkingStartCode
    var codeCursor int
    var bufferedData []byte
Severity: Minor
Found in server/pkg/docker/image_build_response.go - About 1 hr to fix

    Avoid deeply nested control flow statements.
    Open

                            if len(artifactsTarStopReadCode) > codeCursor+1 {
                                codeCursor++
                            } else {
                                return nil
                            }
    Severity: Major
    Found in server/pkg/docker/image_build_response.go - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if len(artifactsTarStartReadCode) > codeCursor+1 {
                                  codeCursor++
      
                                  startReadCodeSuspectedBytes = append(startReadCodeSuspectedBytes, b)
                              } else {
      Severity: Major
      Found in server/pkg/docker/image_build_response.go - About 45 mins to fix

        Function ReadTarFromImageBuildResponse has 7 return statements (exceeds 4 allowed).
        Open

        func ReadTarFromImageBuildResponse(tarWriter, buildLogWriter io.Writer, response types.ImageBuildResponse) error {
            dec := json.NewDecoder(response.Body)
            currentState := checkingStartCode
            var codeCursor int
            var bufferedData []byte
        Severity: Major
        Found in server/pkg/docker/image_build_response.go - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              } else if _, err := buildLogWriter.Write([]byte{b}); err != nil {
                                  return fmt.Errorf("build log writer failed: %w", err)
                              }
          Severity: Major
          Found in server/pkg/docker/image_build_response.go - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if _, err := buildLogWriter.Write(append(startReadCodeSuspectedBytes, b)); err != nil {
                                        return fmt.Errorf("build log writer failed: %w", err)
                                    }
            Severity: Major
            Found in server/pkg/docker/image_build_response.go - About 45 mins to fix

              There are no issues that match your filters.

              Category
              Status