smashah/wa-decrypt

View on GitHub

Showing 3 of 3 total issues

Function decryptMedia has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

export const decryptMedia :  (message: DecryptableMessage | Message | boolean, useragentOverride?: string) => Promise<Buffer> = async (message: DecryptableMessage | Message | boolean, useragentOverride?: string) => {
  const options = makeOptions(useragentOverride);
  if(!message || (message as any) === false || typeof message === "boolean") return new Error("Message is not a valid message");
  let missingProps = [];
  message = message as DecryptableMessage;
Severity: Minor
Found in src/decrypt.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 decryptMedia has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export const decryptMedia :  (message: DecryptableMessage | Message | boolean, useragentOverride?: string) => Promise<Buffer> = async (message: DecryptableMessage | Message | boolean, useragentOverride?: string) => {
  const options = makeOptions(useragentOverride);
  if(!message || (message as any) === false || typeof message === "boolean") return new Error("Message is not a valid message");
  let missingProps = [];
  message = message as DecryptableMessage;
Severity: Minor
Found in src/decrypt.ts - About 1 hr to fix

    Consider simplifying this complex logical expression.
    Open

      if (!message || !message.mediaKey || !message.filehash || !message.mimetype || !message.type || !message.size) {
        if (missingProps.length == 1 && missingProps[0]==="size") {
          if(!nonSizeTypes.includes(message.type)) console.warn("@open-wa/wa-decrypt - WARN: size property is missing. File will fail an integrity check.")
        } 
        else throw new MissingCriticalDataError(`Message is missing critical data: ${missingProps.join(', ')}`);
    Severity: Major
    Found in src/decrypt.ts - About 40 mins to fix
      Severity
      Category
      Status
      Source
      Language