dotcloud/docker

View on GitHub
daemon/images/image.go

Summary

Maintainability
C
1 day
Test Coverage

Method ImageService.manifestMatchesPlatform has a Cognitive Complexity of 35 (exceeds 20 allowed). Consider refactoring.
Open

func (i *ImageService) manifestMatchesPlatform(ctx context.Context, img *image.Image, platform ocispec.Platform) (bool, error) {
    ls, err := i.leases.ListResources(ctx, leases.Lease{ID: imageKey(img.ID().String())})
    if err != nil {
        if cerrdefs.IsNotFound(err) {
            return false, nil
Severity: Minor
Found in daemon/images/image.go - About 2 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

Method ImageService.manifestMatchesPlatform has 88 lines of code (exceeds 50 allowed). Consider refactoring.
Open

func (i *ImageService) manifestMatchesPlatform(ctx context.Context, img *image.Image, platform ocispec.Platform) (bool, error) {
    ls, err := i.leases.ListResources(ctx, leases.Lease{ID: imageKey(img.ID().String())})
    if err != nil {
        if cerrdefs.IsNotFound(err) {
            return false, nil
Severity: Major
Found in daemon/images/image.go - About 2 hrs to fix

    Method ImageService.GetImage has 11 return statements (exceeds 4 allowed).
    Open

    func (i *ImageService) GetImage(ctx context.Context, refOrID string, options backend.GetImageOpts) (retImg *image.Image, retErr error) {
        defer func() {
            if retErr != nil || retImg == nil || options.Platform == nil {
                return
            }
    Severity: Major
    Found in daemon/images/image.go - About 1 hr to fix

      Method ImageService.GetImage has 52 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func (i *ImageService) GetImage(ctx context.Context, refOrID string, options backend.GetImageOpts) (retImg *image.Image, retErr error) {
          defer func() {
              if retErr != nil || retImg == nil || options.Platform == nil {
                  return
              }
      Severity: Minor
      Found in daemon/images/image.go - About 1 hr to fix

        Method ImageService.PrepareSnapshot has 5 arguments (exceeds 4 allowed). Consider refactoring.
        Open

        func (i *ImageService) PrepareSnapshot(ctx context.Context, id string, parentImage string, platform *ocispec.Platform, setupInit func(string) error) error {
        Severity: Minor
        Found in daemon/images/image.go - About 35 mins to fix

          Method ImageService.GetImage has a Cognitive Complexity of 22 (exceeds 20 allowed). Consider refactoring.
          Open

          func (i *ImageService) GetImage(ctx context.Context, refOrID string, options backend.GetImageOpts) (retImg *image.Image, retErr error) {
              defer func() {
                  if retErr != nil || retImg == nil || options.Platform == nil {
                      return
                  }
          Severity: Minor
          Found in daemon/images/image.go - About 35 mins 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

          Method ImageService.manifestMatchesPlatform has 5 return statements (exceeds 4 allowed).
          Open

          func (i *ImageService) manifestMatchesPlatform(ctx context.Context, img *image.Image, platform ocispec.Platform) (bool, error) {
              ls, err := i.leases.ListResources(ctx, leases.Lease{ID: imageKey(img.ID().String())})
              if err != nil {
                  if cerrdefs.IsNotFound(err) {
                      return false, nil
          Severity: Major
          Found in daemon/images/image.go - About 35 mins to fix

            There are no issues that match your filters.

            Category
            Status