digitalheir/rechtspraak-js

View on GitHub

Showing 16 of 24 total issues

Function xmlToJson has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
Open

export function xmlToJson(parent: Node, depth: number = 0): any {
    // Create the return object
    let obj: any = {}; // TODO formalize type?

    if (parent.nodeType === 1) { // element Node.ELEMENT_NODE
Severity: Minor
Found in src/model/json-ld/to-json-ld.ts - 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 refineMetadata2 has 107 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function refineMetadata2(meta: any): RechtspraakMetadata {
    if (typeof meta !== "object") throw new Error("Expected meta to be of type 'object'");


    const _id = throwIfNotString(meta["dcterms:identifier"]);
Severity: Major
Found in src/model/convert-to-typed.ts - About 4 hrs to fix

    Function xmlToJson has 91 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export function xmlToJson(parent: Node, depth: number = 0): any {
        // Create the return object
        let obj: any = {}; // TODO formalize type?
    
        if (parent.nodeType === 1) { // element Node.ELEMENT_NODE
    Severity: Major
    Found in src/model/json-ld/to-json-ld.ts - About 3 hrs to fix

      Function mergeDescriptionTags has 79 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      function mergeDescriptionTags(rdf: any) {
          let description = rdf["rdf:Description"];
          if (Object.prototype.toString.call(description) !== "[object Array]") description = [description, {}];
          if (description.length !== 2) throw new Error("Expected 2 descriptions");
          const description0 = description[0];
      Severity: Major
      Found in src/model/convert-to-typed.ts - About 3 hrs to fix

        Function refineMetadata2 has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

        function refineMetadata2(meta: any): RechtspraakMetadata {
            if (typeof meta !== "object") throw new Error("Expected meta to be of type 'object'");
        
        
            const _id = throwIfNotString(meta["dcterms:identifier"]);
        Severity: Minor
        Found in src/model/convert-to-typed.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

        File convert-to-typed.ts has 260 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import {
            Creator,
            Date,
            RechtspraakMetadata,
            UriWithProtocol
        Severity: Minor
        Found in src/model/convert-to-typed.ts - About 2 hrs to fix

          Function resourceObject has 37 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          function resourceObject(idIsUri = true,
                                  hasLabels = true,
                                  extraMandatoryProperties: any = {}, // todo
                                  extraOptionalProperties: any = {} // todo
          ): SchemaTypeDefinition {
          Severity: Minor
          Found in src/model/json-ld/schema/resource-object.ts - About 1 hr to fix

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

            export function getResourceId(attrz: any/*todo*/, key?: string): string {
                if (!attrz)
                    throw new Error("No attributes found!" + (key ? " (" + key + ")" : ""));
                if (attrz["resourceIdentifier"])
                    if (!!attrz["psi:resourceIdentifier"])
            Severity: Minor
            Found in src/model/convert-to-typed.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 getGevolg has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

            function getGevolg(gevolgUri?: string, label?: string): Gevolg | undefined {
                if (!gevolgUri)
                    return undefined;
                else {
                    const id = gevolgUri.replace(/^http:\/\/psi\.rechtspraak\.nl\//, "");
            Severity: Minor
            Found in src/model/fields/relation.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 (typeof(obj[childNodeName]) === "undefined") {
                                        // child doesn't exist yet
                                        obj[childNodeName] = xmlToJson(item, depth + 1);
                                    } else {
                                        // Add child to array
            Severity: Major
            Found in src/model/json-ld/to-json-ld.ts - About 45 mins to fix

              Function getRelation has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

              export const getRelation = (arr: any[]): Relation[] | undefined => arr ? arr.map((rel: any) => {
                  const attrs = [
                      "rdfs:label",
                      ["ecli:resourceIdentifier"/*, "bwb:resourceIdentifier"*/],
                      "psi:type",
              Severity: Minor
              Found in src/model/fields/relation.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 (!!item.textContent)
                                          obj.textContent = item.textContent.trim().replace(/\s\s+/g, " ");
              Severity: Major
              Found in src/model/json-ld/to-json-ld.ts - About 45 mins to fix

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

                function mergeDescriptionTags(rdf: any) {
                    let description = rdf["rdf:Description"];
                    if (Object.prototype.toString.call(description) !== "[object Array]") description = [description, {}];
                    if (description.length !== 2) throw new Error("Expected 2 descriptions");
                    const description0 = description[0];
                Severity: Minor
                Found in src/model/convert-to-typed.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 mustHaveTextAndAttributes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                export function mustHaveTextAndAttributes(object: any/*todo*/, mustHaveText: boolean, ...attrs: (string | string[])[]) {
                    if (attrs.length > 0) {
                        if (!object["@attributes"])
                            throw new Error("Expected object to have " + attrs.length + " attributes: " + JSON.stringify(object));
                        if (attrs.length != Object.keys(object["@attributes"]).length)
                Severity: Minor
                Found in src/util/validations.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 getTitle has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                export function getTitle(t: any, id: string, creator: Creator, issued: string): LabelWithLanguage {
                
                    if (!t) {
                        const title = [id];
                        const creatorLabels = creator['rdfs:label'];
                Severity: Minor
                Found in src/model/fields/title.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

                Avoid too many return statements within this function.
                Open

                    else return "nl";
                Severity: Major
                Found in src/model/fields/creator.ts - About 30 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language