rescribet/link-lib

View on GitHub
src/utilities/responses.ts

Summary

Maintainability
B
4 hrs
Test Coverage
B
85%

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

export function contentTypeByMimeString(contentType: string, ext: string): string | undefined {
    if (contentType.includes(F_NTRIPLES) || contentType.includes(F_NTRIPLES_DEP)) {
        return F_NTRIPLES;
    } else if (contentType.includes(F_PLAIN) && ["ntriples", "nt"].indexOf(ext) >= 0) {
        return F_NTRIPLES;
Severity: Minor
Found in src/utilities/responses.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 getContentType has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

export function getContentType(res: ResponseAndFallbacks): string {
    const contentTypeRaw = getHeader(res, "Content-Type");
    if (contentTypeRaw === undefined || contentTypeRaw === null) {
        return "";
    }
Severity: Minor
Found in src/utilities/responses.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 too many return statements within this function.
Open

    return ext;
Severity: Major
Found in src/utilities/responses.ts - About 30 mins to fix

    Avoid too many return statements within this function.
    Open

        return undefined;
    Severity: Major
    Found in src/utilities/responses.ts - About 30 mins to fix

      Avoid too many return statements within this function.
      Open

              return F_RDF_XML;
      Severity: Major
      Found in src/utilities/responses.ts - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return F_JSONLD;
        Severity: Major
        Found in src/utilities/responses.ts - About 30 mins to fix

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

          export function getHeader(res: ResponseAndFallbacks, header: string): string | null {
              if (res instanceof Response) {
                  return res.headers.get(header);
              } else if (typeof XMLHttpRequest !== "undefined" && res instanceof XMLHttpRequest) {
                  return (res as XMLHttpRequest).getResponseHeader(header) || null;
          Severity: Minor
          Found in src/utilities/responses.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

          There are no issues that match your filters.

          Category
          Status