portainer/portainer

View on GitHub
app/docker/views/services/create/createServiceController.js

Summary

Maintainability
F
4 days
Test Coverage

File createServiceController.js has 566 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import _ from 'lodash-es';

import * as envVarsUtils from '@/react/components/form-components/EnvironmentVariablesFieldset/utils';
import { PorImageRegistryModel } from 'Docker/models/porImageRegistry';
import { AccessControlFormData } from '../../../../portainer/components/accessControlForm/porAccessControlFormModel';
Severity: Major
Found in app/docker/views/services/create/createServiceController.js - About 1 day to fix

    Function prepareConfiguration has 34 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        function prepareConfiguration() {
          var input = $scope.formValues;
          var config = {
            Name: input.Name,
            TaskTemplate: {
    Severity: Minor
    Found in app/docker/views/services/create/createServiceController.js - About 1 hr to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          $scope.checkIfConfigDuplicated = function () {
            $scope.formValues.Configs.$invalid = false;
            [...$scope.formValues.Configs]
              .sort((a, b) => a.model.Id.localeCompare(b.model.Id))
              .sort((a, b) => {
      Severity: Major
      Found in app/docker/views/services/create/createServiceController.js and 1 other location - About 1 day to fix
      app/docker/views/services/create/createServiceController.js on lines 228..241

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 223.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          $scope.checkIfSecretDuplicated = function () {
            $scope.formValues.Secrets.$invalid = false;
            [...$scope.formValues.Secrets]
              .sort((a, b) => a.model.Id.localeCompare(b.model.Id))
              .sort((a, b) => {
      Severity: Major
      Found in app/docker/views/services/create/createServiceController.js and 1 other location - About 1 day to fix
      app/docker/views/services/create/createServiceController.js on lines 243..256

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 223.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

                if (Object.keys(logOpts).length !== 0 && logOpts.constructor === Object) {
                  config.TaskTemplate.LogDriver.Options = logOpts;
                }
      Severity: Minor
      Found in app/docker/views/services/create/createServiceController.js and 1 other location - About 55 mins to fix
      app/docker/views/services/edit/serviceController.js on lines 542..544

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 54.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          function volumesAreValid() {
            const volumes = $scope.formValues.Volumes;
            return volumes.every((volume) => volume.Target && volume.Source);
          }
      Severity: Minor
      Found in app/docker/views/services/create/createServiceController.js and 1 other location - About 45 mins to fix
      app/docker/views/services/edit/serviceController.js on lines 438..441

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 50.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

            if (maxCpus > 0) {
              $scope.state.sliderMaxCpu = maxCpus / 1000000000;
            } else {
              $scope.state.sliderMaxCpu = 32;
            }
      Severity: Minor
      Found in app/docker/views/services/create/createServiceController.js and 1 other location - About 40 mins to fix
      app/docker/views/services/edit/serviceController.js on lines 835..839

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 49.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          $scope.removeSecret = function (index) {
            $scope.formValues.Secrets.splice(index, 1);
            $scope.checkIfSecretDuplicated();
          };
      Severity: Minor
      Found in app/docker/views/services/create/createServiceController.js and 1 other location - About 35 mins to fix
      app/docker/views/services/create/createServiceController.js on lines 174..177

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 47.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          $scope.removeConfig = function (index) {
            $scope.formValues.Configs.splice(index, 1);
            $scope.checkIfConfigDuplicated();
          };
      Severity: Minor
      Found in app/docker/views/services/create/createServiceController.js and 1 other location - About 35 mins to fix
      app/docker/views/services/create/createServiceController.js on lines 183..186

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 47.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 8 locations. Consider refactoring.
      Open

          $scope.addContainerLabel = function () {
            $scope.formValues.ContainerLabels.push({ key: '', value: '' });
          };
      Severity: Major
      Found in app/docker/views/services/create/createServiceController.js and 7 other locations - About 35 mins to fix
      app/docker/views/networks/create/createNetworkController.js on lines 63..68
      app/docker/views/networks/create/createNetworkController.js on lines 74..79
      app/docker/views/secrets/create/createSecretController.js on lines 34..36
      app/docker/views/services/create/createServiceController.js on lines 196..198
      app/docker/views/services/create/createServiceController.js on lines 204..206
      app/docker/views/services/create/createServiceController.js on lines 220..222
      app/docker/views/volumes/create/createVolumeController.js on lines 36..38

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 46.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 8 locations. Consider refactoring.
      Open

          $scope.addLabel = function () {
            $scope.formValues.Labels.push({ key: '', value: '' });
          };
      Severity: Major
      Found in app/docker/views/services/create/createServiceController.js and 7 other locations - About 35 mins to fix
      app/docker/views/networks/create/createNetworkController.js on lines 63..68
      app/docker/views/networks/create/createNetworkController.js on lines 74..79
      app/docker/views/secrets/create/createSecretController.js on lines 34..36
      app/docker/views/services/create/createServiceController.js on lines 196..198
      app/docker/views/services/create/createServiceController.js on lines 212..214
      app/docker/views/services/create/createServiceController.js on lines 220..222
      app/docker/views/volumes/create/createVolumeController.js on lines 36..38

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 46.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 8 locations. Consider refactoring.
      Open

          $scope.addLogDriverOpt = function () {
            $scope.formValues.LogDriverOpts.push({ name: '', value: '' });
          };
      Severity: Major
      Found in app/docker/views/services/create/createServiceController.js and 7 other locations - About 35 mins to fix
      app/docker/views/networks/create/createNetworkController.js on lines 63..68
      app/docker/views/networks/create/createNetworkController.js on lines 74..79
      app/docker/views/secrets/create/createSecretController.js on lines 34..36
      app/docker/views/services/create/createServiceController.js on lines 196..198
      app/docker/views/services/create/createServiceController.js on lines 204..206
      app/docker/views/services/create/createServiceController.js on lines 212..214
      app/docker/views/volumes/create/createVolumeController.js on lines 36..38

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 46.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 8 locations. Consider refactoring.
      Open

          $scope.addPlacementPreference = function () {
            $scope.formValues.PlacementPreferences.push({ strategy: 'spread', value: '' });
          };
      Severity: Major
      Found in app/docker/views/services/create/createServiceController.js and 7 other locations - About 35 mins to fix
      app/docker/views/networks/create/createNetworkController.js on lines 63..68
      app/docker/views/networks/create/createNetworkController.js on lines 74..79
      app/docker/views/secrets/create/createSecretController.js on lines 34..36
      app/docker/views/services/create/createServiceController.js on lines 204..206
      app/docker/views/services/create/createServiceController.js on lines 212..214
      app/docker/views/services/create/createServiceController.js on lines 220..222
      app/docker/views/volumes/create/createVolumeController.js on lines 36..38

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 46.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

              if (nodes[n].Memory && nodes[n].Memory > maxMemory) {
                maxMemory = nodes[n].Memory;
              }
      Severity: Minor
      Found in app/docker/views/services/create/createServiceController.js and 1 other location - About 35 mins to fix
      app/docker/views/services/create/createServiceController.js on lines 585..587

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 46.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

              if (nodes[n].CPUs && nodes[n].CPUs > maxCpus) {
                maxCpus = nodes[n].CPUs;
              }
      Severity: Minor
      Found in app/docker/views/services/create/createServiceController.js and 1 other location - About 35 mins to fix
      app/docker/views/services/create/createServiceController.js on lines 588..590

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 46.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      There are no issues that match your filters.

      Category
      Status