portainer/portainer

View on GitHub
app/kubernetes/services/applicationService.js

Summary

Maintainability
F
3 days
Test Coverage

File applicationService.js has 374 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import _ from 'lodash-es';
import angular from 'angular';
import PortainerError from 'Portainer/error';

import { KubernetesApplicationDeploymentTypes, KubernetesApplicationTypes } from 'Kubernetes/models/application/models/appConstants';
Severity: Minor
Found in app/kubernetes/services/applicationService.js - About 5 hrs to fix

    Function patchAsync has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

      async patchAsync(oldFormValues, newFormValues, originalServicePorts) {
        const [oldApp, oldHeadlessService, oldServices, , oldClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(oldFormValues);
        const [newApp, newHeadlessService, newServices, , newClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(newFormValues);
        const oldApiService = this._getApplicationApiService(oldApp);
        const newApiService = this._getApplicationApiService(newApp);
    Severity: Minor
    Found in app/kubernetes/services/applicationService.js - About 3 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 patchAsync has 92 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      async patchAsync(oldFormValues, newFormValues, originalServicePorts) {
        const [oldApp, oldHeadlessService, oldServices, , oldClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(oldFormValues);
        const [newApp, newHeadlessService, newServices, , newClaims] = KubernetesApplicationConverter.applicationFormValuesToApplication(newFormValues);
        const oldApiService = this._getApplicationApiService(oldApp);
        const newApiService = this._getApplicationApiService(newApp);
    Severity: Major
    Found in app/kubernetes/services/applicationService.js - About 3 hrs to fix

      Function getAsync has 46 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        async getAsync(namespace, name) {
          const [deployment, daemonSet, statefulSet, pod, pods, autoScalers, ingresses] = await Promise.allSettled([
            this.KubernetesDeploymentService.get(namespace, name),
            this.KubernetesDaemonSetService.get(namespace, name),
            this.KubernetesStatefulSetService.get(namespace, name),
      Severity: Minor
      Found in app/kubernetes/services/applicationService.js - About 1 hr to fix

        Function getAllAsync has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          async getAllAsync(namespace) {
            const namespaces = namespace ? [namespace] : _.map(await this.KubernetesNamespaceService.get(), 'Name');
        
            const convertToApplication = (item, converterFunc, services, pods, ingresses) => {
              const service = KubernetesServiceHelper.findApplicationBoundService(services, item);
        Severity: Minor
        Found in app/kubernetes/services/applicationService.js - About 1 hr to fix

          Function createAsync has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            async createAsync(formValues, hideStacks) {
              // formValues -> Application
              let [app, headlessService, services, , claims] = KubernetesApplicationConverter.applicationFormValuesToApplication(formValues);
          
              if (hideStacks) {
          Severity: Minor
          Found in app/kubernetes/services/applicationService.js - About 1 hr to fix

            Function createAsync has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
            Open

              async createAsync(formValues, hideStacks) {
                // formValues -> Application
                let [app, headlessService, services, , claims] = KubernetesApplicationConverter.applicationFormValuesToApplication(formValues);
            
                if (hideStacks) {
            Severity: Minor
            Found in app/kubernetes/services/applicationService.js - About 1 hr 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 res has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                  _.map(namespaces, async (ns) => {
                    const [deployments, daemonSets, statefulSets, services, pods, ingresses, autoScalers] = await Promise.all([
                      this.KubernetesDeploymentService.get(ns),
                      this.KubernetesDaemonSetService.get(ns),
                      this.KubernetesStatefulSetService.get(ns),
            Severity: Minor
            Found in app/kubernetes/services/applicationService.js - About 1 hr to fix

              Function deleteAsync has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                async deleteAsync(application) {
                  const payload = {
                    Namespace: application.ResourcePool || application.Namespace,
                    Name: application.Name,
                  };
              Severity: Minor
              Found in app/kubernetes/services/applicationService.js - About 1 hr to fix

                Function getAsync has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                  async getAsync(namespace, name) {
                    const [deployment, daemonSet, statefulSet, pod, pods, autoScalers, ingresses] = await Promise.allSettled([
                      this.KubernetesDeploymentService.get(namespace, name),
                      this.KubernetesDaemonSetService.get(namespace, name),
                      this.KubernetesStatefulSetService.get(namespace, name),
                Severity: Minor
                Found in app/kubernetes/services/applicationService.js - About 1 hr 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 deleteAsync has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                  async deleteAsync(application) {
                    const payload = {
                      Namespace: application.ResourcePool || application.Namespace,
                      Name: application.Name,
                    };
                Severity: Minor
                Found in app/kubernetes/services/applicationService.js - About 55 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

                Function _getApplicationApiService has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  _getApplicationApiService(app) {
                    let apiService;
                    if (app.ApplicationType === KubernetesApplicationTypes.Deployment) {
                      apiService = this.KubernetesDeploymentService;
                    } else if (app.ApplicationType === KubernetesApplicationTypes.DaemonSet) {
                Severity: Minor
                Found in app/kubernetes/services/applicationService.js - 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

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

                      newServices.forEach(async (service) => {
                        try {
                          await this.KubernetesServiceService.create(service);
                        } catch (error) {
                          notifyError('Unable to create service', error);
                Severity: Major
                Found in app/kubernetes/services/applicationService.js and 1 other location - About 1 hr to fix
                app/kubernetes/services/applicationService.js on lines 220..226

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

                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

                      services.forEach(async (service) => {
                        try {
                          await this.KubernetesServiceService.create(service);
                        } catch (error) {
                          notifyError('Unable to create service', error);
                Severity: Major
                Found in app/kubernetes/services/applicationService.js and 1 other location - About 1 hr to fix
                app/kubernetes/services/applicationService.js on lines 325..331

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

                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

                        } else if (!newClaim.Id) {
                          const oldClaim = _.find(oldClaims, { Name: newClaim.PreviousName });
                          return this.KubernetesPersistentVolumeClaimService.patch(oldClaim, newClaim);
                        }
                Severity: Minor
                Found in app/kubernetes/services/applicationService.js and 1 other location - About 30 mins to fix
                app/kubernetes/services/applicationService.js on lines 76..79

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

                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

                    return _.map(newIngresses, (newIng) => {
                      const oldIng = _.find(oldIngresses, { Name: newIng.Name });
                      return this.KubernetesIngressService.patch(oldIng, newIng);
                    });
                Severity: Minor
                Found in app/kubernetes/services/applicationService.js and 1 other location - About 30 mins to fix
                app/kubernetes/services/applicationService.js on lines 313..316

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

                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