CocoonIO/cocoon-xml-sugar

View on GitHub
src/lib/xml-sugar.ts

Summary

Maintainability
F
5 days
Test Coverage

File xml-sugar.ts has 548 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"use strict";

import * as detectNode from "detect-node";
import * as xmldom from "xmldom";

Severity: Major
Found in src/lib/xml-sugar.ts - About 1 day to fix

    XMLSugar has 55 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export default class XMLSugar {
        private static encode(str: string): string {
            if (!str) {
                return str;
            }
    Severity: Major
    Found in src/lib/xml-sugar.ts - About 7 hrs to fix

      Function setEnvironment has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          public setEnvironment(value: Environment, platform?: Platform) {
              const names = platform ? [platform] : ["android", "ios"];
      
              for (const name of names) {
                  let info: any;
      Severity: Minor
      Found in src/lib/xml-sugar.ts - 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

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

          public getEnvironment(platform?: Platform): Environment {
              if (!platform) {
                  const environments = [this.getEnvironment(Platform.IOS), this.getEnvironment(Platform.Android)];
                  for (let j = 1; j < environments.length; ++j) {
                      if (environments[j] !== environments[j - 1]) {
      Severity: Minor
      Found in src/lib/xml-sugar.ts - 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 replaceOldPluginSyntax has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          private static replaceOldPluginSyntax(doc: Document): Document {
              const plugins = Array.prototype.slice.call(doc.getElementsByTagNameNS(cocoonNS, "plugin"));
      
              for (const plugin of plugins) {
                  const pluginEle = doc.createElementNS(null, "plugin");
      Severity: Minor
      Found in src/lib/xml-sugar.ts - 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 replaceOldPlatformSyntax has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          private static replaceOldPlatformSyntax(doc: Document): Document {
              const platforms = Array.prototype.slice.call(doc.getElementsByTagNameNS(cocoonNS, "platform"));
      
              for (const platform of platforms) {
                  const platformEle: Element = doc.createElementNS(null, "platform");
      Severity: Minor
      Found in src/lib/xml-sugar.ts - 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 setEnvironment has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public setEnvironment(value: Environment, platform?: Platform) {
              const names = platform ? [platform] : ["android", "ios"];
      
              for (const name of names) {
                  let info: any;
      Severity: Minor
      Found in src/lib/xml-sugar.ts - About 1 hr to fix

        Function replaceOldPlatformSyntax has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static replaceOldPlatformSyntax(doc: Document): Document {
                const platforms = Array.prototype.slice.call(doc.getElementsByTagNameNS(cocoonNS, "platform"));
        
                for (const platform of platforms) {
                    const platformEle: Element = doc.createElementNS(null, "platform");
        Severity: Minor
        Found in src/lib/xml-sugar.ts - About 1 hr to fix

          Function setBundleId has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public setBundleId(value: string, platform?: Platform) {
                  if (platform) {
                      const name = BundleIdAlias[platform];
                      if (name) {
                          if (value) {
          Severity: Minor
          Found in src/lib/xml-sugar.ts - 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 getVersionCode has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public getVersionCode(platform?: Platform, fallback: boolean = true): string {
                  if (platform) {
                      const name = VersionCodeAlias[platform];
                      if (name) {
                          const version = this.root.getAttribute(name);
          Severity: Minor
          Found in src/lib/xml-sugar.ts - 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 addPluginVariable has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public addPluginVariable(pluginName: string, varName: string, varValue: string) {
                  this.addPlugin(pluginName);
                  const plugin = this.findPlugin(pluginName);
                  if (plugin) {
                      const nodes = Array.prototype.slice.call(plugin.childNodes);
          Severity: Minor
          Found in src/lib/xml-sugar.ts - 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 setVersionCode has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              public setVersionCode(value: string, platform?: Platform) {
                  if (platform) {
                      const name = VersionCodeAlias[platform];
                      if (name) {
                          if (value) {
          Severity: Minor
          Found in src/lib/xml-sugar.ts - About 45 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

          Avoid deeply nested control flow statements.
          Open

                              if (!info) {
                                  continue;
                              }
          Severity: Major
          Found in src/lib/xml-sugar.ts - About 45 mins to fix

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

                public setVersion(value: string, platform?: Platform) {
                    if (platform) {
                        const name = platform + "-version";
                        if (name) {
                            if (value) {
            Severity: Minor
            Found in src/lib/xml-sugar.ts - 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

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

                public findPluginVariable(pluginName: string, varName: string): string {
                    const plugin = this.findPlugin(pluginName);
                    let result: string;
                    if (plugin) {
                        const nodes = Array.prototype.slice.call(plugin.childNodes);
            Severity: Minor
            Found in src/lib/xml-sugar.ts - 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

            Function getVersion has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                public getVersion(platform?: Platform, fallback: boolean = true): string {
                    if (platform) {
                        const version = this.root.getAttribute(platform + "-version");
                        if (version) {
                            return version;
            Severity: Minor
            Found in src/lib/xml-sugar.ts - About 25 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

                public getCocoonEngine(platform: Platform): Element {
                    const filter = {
                        attributes: [
                            {name: "name", value: platform},
                        ],
            Severity: Major
            Found in src/lib/xml-sugar.ts and 1 other location - About 1 hr to fix
            src/lib/xml-sugar.ts on lines 508..516

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

            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

                public getCocoonPlatform(platform: Platform): Element {
                    const filter = {
                        attributes: [
                            {name: "name", value: platform},
                        ],
            Severity: Major
            Found in src/lib/xml-sugar.ts and 1 other location - About 1 hr to fix
            src/lib/xml-sugar.ts on lines 542..550

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

            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

                private static encode(str: string): string {
                    if (!str) {
                        return str;
                    }
                    return str.replace(/&/g, "&amp;")
            Severity: Major
            Found in src/lib/xml-sugar.ts and 1 other location - About 1 hr to fix
            src/lib/xml-sugar.ts on lines 28..37

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

            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

                private static decode(str: string): string {
                    if (!str) {
                        return str;
                    }
                    return str.replace(/&apos;/g, "\"")
            Severity: Major
            Found in src/lib/xml-sugar.ts and 1 other location - About 1 hr to fix
            src/lib/xml-sugar.ts on lines 17..26

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

            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 (value === Environment.WEBVIEW_PLUS) {
                            info = webviewplusPlugins[name];
                            if (info) {
                                this.addPlugin(info.plugin);
                                this.removePlugin(canvasplusPlugins[name].plugin);
            Severity: Major
            Found in src/lib/xml-sugar.ts and 1 other location - About 1 hr to fix
            src/lib/xml-sugar.ts on lines 676..697

            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

                        if (value === Environment.CANVAS_PLUS) {
                            info = canvasplusPlugins[name];
                            if (info) {
                                this.addPlugin(info.plugin);
                                this.removePlugin(webviewplusPlugins[name].plugin);
            Severity: Major
            Found in src/lib/xml-sugar.ts and 1 other location - About 1 hr to fix
            src/lib/xml-sugar.ts on lines 682..697

            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

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

                        if (name) {
                            if (value) {
                                this.root.setAttribute(name, value);
                            } else {
                                this.root.removeAttribute(name);
            Severity: Minor
            Found in src/lib/xml-sugar.ts and 1 other location - About 35 mins to fix
            src/lib/xml-sugar.ts on lines 385..394

            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

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

                        if (name) {
                            if (value) {
                                this.root.setAttribute(name, value);
                            } else {
                                this.root.removeAttribute(name);
            Severity: Minor
            Found in src/lib/xml-sugar.ts and 1 other location - About 35 mins to fix
            src/lib/xml-sugar.ts on lines 338..345

            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

            There are no issues that match your filters.

            Category
            Status