elninotech/uppload

View on GitHub
src/uppload.ts

Summary

Maintainability
F
1 wk
Test Coverage

File uppload.ts has 702 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import { UpploadService } from "./service";
import { UpploadEffect } from "./effect";
import { setI18N, translate } from "./helpers/i18n";
import { compressImage, getElements, safeListen } from "./helpers/elements";
import { colorSVG } from "./helpers/assets";
Severity: Major
Found in src/uppload.ts - About 1 day to fix

    Uppload has 32 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class Uppload implements IUppload {
      services: UpploadService[] = [new DefaultService(), new UploadingService()];
      effects: UpploadEffect[] = [];
      isOpen = false;
      error?: string;
    Severity: Minor
    Found in src/uppload.ts - About 4 hrs to fix

      Function handlers has 96 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        private handlers() {
          const openFunction = () => this.open();
          const closeFunction = () => this.close();
      
          /**
      Severity: Major
      Found in src/uppload.ts - About 3 hrs to fix

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

          private update() {
            if (!this.container) return;
            this.hideHelp();
            if (this.settings.customClass)
              this.container.classList.add(this.settings.customClass);
        Severity: Minor
        Found in src/uppload.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 update has 59 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private update() {
            if (!this.container) return;
            this.hideHelp();
            if (this.settings.customClass)
              this.container.classList.add(this.settings.customClass);
        Severity: Major
        Found in src/uppload.ts - About 2 hrs to fix

          Function upload has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            upload(file: File | Blob): Promise<string> {
              this.emitter.emit("before-upload", file);
              return new Promise((resolve, reject) => {
                this.navigate("uploading");
                let upploadFile = blobToUpploadFile(file);
          Severity: Minor
          Found in src/uppload.ts - About 1 hr to fix

            Function getNavbar has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              private getNavbar(sidebar = false) {
                return `<${sidebar ? "nav" : "div"} class="uppload-services">
                  ${this.services
                    .filter(service => !service.invisible)
                    .map(
            Severity: Minor
            Found in src/uppload.ts - About 1 hr to fix

              Function renderContainer has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                private renderContainer() {
                  if (this.container)
                    this.container.innerHTML = `
                    <div class="uppload-modal">
                      <div class="processing-loader"></div>
              Severity: Minor
              Found in src/uppload.ts - About 1 hr to fix

                Function getEffectsNavbar has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  private getEffectsNavbar() {
                    return `<div class="effects-continue">
                    <button class="effects-continue--cancel">${translate("cancel")}</button>
                  </div><div class="effects-tabs"><div class="effects-tabs-flow">
                      ${this.effects
                Severity: Minor
                Found in src/uppload.ts - About 1 hr to fix

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

                    showHelp(url: string) {
                      this.emitter.emit("help", url);
                      const aside = this.container.querySelector("aside");
                      if (aside) aside.style.display = "none";
                      const section = this.container.querySelector("section");
                  Severity: Minor
                  Found in src/uppload.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 render has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                    private render() {
                      return `
                        ${this.error ? `<div class="uppload-error">${this.error}</div>` : ""}
                        ${
                          this.activeEffect
                  Severity: Minor
                  Found in src/uppload.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 renderActiveEffect has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    private renderActiveEffect(file: IUpploadFile) {
                      const activeEffects = this.effects.filter(
                        effect => effect.name === this.activeEffect
                      );
                      if (!activeEffects.length) {
                  Severity: Minor
                  Found in src/uppload.ts - About 1 hr to fix

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

                          const linkFunction = (e: Event) => {
                            const service = link.getAttribute("data-uppload-service");
                            if (service) {
                              this.navigate(service);
                              const serviceDiv = this.container.querySelector(
                    Severity: Minor
                    Found in src/uppload.ts - About 1 hr to fix

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

                        private install(plugin: UpploadService | UpploadEffect) {
                          // Check if the browser supports this plugin
                          if (!plugin.supports()) return;
                          if (plugin.type === "service") {
                            // Install this service if it isn't already installed
                      Severity: Minor
                      Found in src/uppload.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 handlers has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                      Open

                        private handlers() {
                          const openFunction = () => this.open();
                          const closeFunction = () => this.close();
                      
                          /**
                      Severity: Minor
                      Found in src/uppload.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

                          requestAnimationFrame(() => {
                            if (typeof activeService.handlers === "function")
                              activeService.handlers({
                                next: this.next.bind(this),
                                upload: this.upload.bind(this),
                      Severity: Major
                      Found in src/uppload.ts and 1 other location - About 4 hrs to fix
                      src/uppload.ts on lines 507..518

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

                      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

                          requestAnimationFrame(() => {
                            if (typeof activeEffect.handlers === "function")
                              activeEffect.handlers({
                                next: this.next.bind(this),
                                upload: this.upload.bind(this),
                      Severity: Major
                      Found in src/uppload.ts and 1 other location - About 4 hrs to fix
                      src/uppload.ts on lines 477..488

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

                      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

                                  this.lang.effects &&
                                  this.lang.effects[effect.name] &&
                                  this.lang.effects[effect.name].title
                                    ? this.lang.effects[effect.name].title
                                    : effect.name
                      Severity: Major
                      Found in src/uppload.ts and 1 other location - About 2 hrs to fix
                      src/uppload.ts on lines 357..361

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

                      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

                                    this.lang.services &&
                                    this.lang.services[service.name] &&
                                    this.lang.services[service.name].title
                                      ? this.lang.services[service.name].title
                                      : service.name
                      Severity: Major
                      Found in src/uppload.ts and 1 other location - About 2 hrs to fix
                      src/uppload.ts on lines 390..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 83.

                      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

                          this.emitter.on("process", () => {
                            const loader =
                              this.container.querySelector<HTMLDivElement>(".processing-loader");
                            if (loader) loader.classList.remove("visible");
                          });
                      Severity: Major
                      Found in src/uppload.ts and 1 other location - About 1 hr to fix
                      src/uppload.ts on lines 82..86

                      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

                          this.emitter.on("processing", () => {
                            const loader =
                              this.container.querySelector<HTMLDivElement>(".processing-loader");
                            if (loader) loader.classList.add("visible");
                          });
                      Severity: Major
                      Found in src/uppload.ts and 1 other location - About 1 hr to fix
                      src/uppload.ts on lines 87..91

                      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

                        off(type: string, handler: (event?: any) => void) {
                          return this.emitter.off(type, handler);
                        }
                      Severity: Minor
                      Found in src/uppload.ts and 1 other location - About 40 mins to fix
                      src/uppload.ts on lines 862..864

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

                      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

                        on(type: string, handler: (event?: any) => void) {
                          return this.emitter.on(type, handler);
                        }
                      Severity: Minor
                      Found in src/uppload.ts and 1 other location - About 40 mins to fix
                      src/uppload.ts on lines 871..873

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

                      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

                                  effect.icon.indexOf("http") === 0
                                    ? `<img class="effect-icon" alt="" src="${effect.icon}">`
                                    : colorSVG(effect.icon, effect)
                      Severity: Minor
                      Found in src/uppload.ts and 1 other location - About 30 mins to fix
                      src/uppload.ts on lines 352..354

                      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

                                    service.icon.indexOf("http") === 0
                                      ? `<img class="service-icon" alt="" src="${service.icon}">`
                                      : colorSVG(service.icon, service)
                      Severity: Minor
                      Found in src/uppload.ts and 1 other location - About 30 mins to fix
                      src/uppload.ts on lines 385..387

                      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