mongaku/mongaku

View on GitHub
src/schemas/types/Dimension.js

Summary

Maintainability
F
6 days
Test Coverage

File Dimension.js has 268 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const pd = require("parse-dimensions");

const numRange = bucket =>
    bucket.to
        ? `${bucket.from || 0}-${bucket.to}${bucket.unit}`
Severity: Minor
Found in src/schemas/types/Dimension.js - About 2 hrs to fix

    Function facet has 59 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        facet() {
            const defaultUnit = this.defaultUnit;
            const unit = this.defaultSearchUnit || this.defaultUnit;
    
            const formatFacetBucket = bucket => {
    Severity: Major
    Found in src/schemas/types/Dimension.js - About 2 hrs to fix

      Function filter has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          filter(value) {
              const filters = [];
      
              if (value.widthMin) {
                  filters.push({
      Severity: Major
      Found in src/schemas/types/Dimension.js - About 2 hrs to fix

        Function schema has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            schema(Schema) {
                const DimensionSchema = new Schema({
                    // An ID for the dimension, computed from the original +
                    // width/height properties before validation.
                    _id: String,
        Severity: Minor
        Found in src/schemas/types/Dimension.js - About 1 hr to fix

          Function breadcrumbs has 32 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              breadcrumbs(value, i18n) {
                  const breadcrumbs = [];
          
                  if (value.heightMin || value.heightMax) {
                      const title = this.options.heightTitle(i18n);
          Severity: Minor
          Found in src/schemas/types/Dimension.js - About 1 hr to fix

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

                fields(value) {
                    const ret = {};
                    const defaultUnit = this.defaultSearchUnit || this.defaultUnit;
            
                    if (value.height) {
            Severity: Minor
            Found in src/schemas/types/Dimension.js - About 1 hr to fix

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

                  fields(value) {
                      const ret = {};
                      const defaultUnit = this.defaultSearchUnit || this.defaultUnit;
              
                      if (value.height) {
              Severity: Minor
              Found in src/schemas/types/Dimension.js - 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

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

                      if (value.heightMin || value.heightMax) {
                          const title = this.options.heightTitle(i18n);
                          const range = numRange({
                              from: value.heightMin,
                              to: value.heightMax,
              Severity: Major
              Found in src/schemas/types/Dimension.js and 1 other location - About 5 hrs to fix
              src/schemas/types/Dimension.js on lines 132..148

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

              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.widthMin || value.widthMax) {
                          const title = this.options.widthTitle(i18n);
                          const range = numRange({
                              from: value.widthMin,
                              to: value.widthMax,
              Severity: Major
              Found in src/schemas/types/Dimension.js and 1 other location - About 5 hrs to fix
              src/schemas/types/Dimension.js on lines 114..130

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

              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.widthMin || value.widthMax) {
                          const name = this.options.widthTitle(i18n);
                          const range = numRange({
                              from: pd.convertNumber(value.widthMin, unit, expectedUnit),
                              to: pd.convertNumber(value.widthMax, unit, expectedUnit),
              Severity: Major
              Found in src/schemas/types/Dimension.js and 1 other location - About 4 hrs to fix
              src/schemas/types/Dimension.js on lines 51..59

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

              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.heightMin || value.heightMax) {
                          const name = this.options.heightTitle(i18n);
                          const range = numRange({
                              from: pd.convertNumber(value.heightMin, unit, expectedUnit),
                              to: pd.convertNumber(value.heightMax, unit, expectedUnit),
              Severity: Major
              Found in src/schemas/types/Dimension.js and 1 other location - About 4 hrs to fix
              src/schemas/types/Dimension.js on lines 61..69

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

              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.options.name}.height`]: {
                              title: i18n => this.options.heightTitle(i18n),
              
                              facet: () => ({
                                  range: {
              Severity: Major
              Found in src/schemas/types/Dimension.js and 1 other location - About 3 hrs to fix
              src/schemas/types/Dimension.js on lines 258..269

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

              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.options.name}.width`]: {
                              title: i18n => this.options.widthTitle(i18n),
              
                              facet: () => ({
                                  range: {
              Severity: Major
              Found in src/schemas/types/Dimension.js and 1 other location - About 3 hrs to fix
              src/schemas/types/Dimension.js on lines 271..282

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

              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 4 locations. Consider refactoring.
              Open

                      if (value.widthMin) {
                          filters.push({
                              range: {
                                  [`${this.options.name}.width`]: {
                                      gte: pd.convertNumber(
              Severity: Major
              Found in src/schemas/types/Dimension.js and 3 other locations - About 2 hrs to fix
              src/schemas/types/Dimension.js on lines 170..182
              src/schemas/types/Dimension.js on lines 184..196
              src/schemas/types/Dimension.js on lines 198..210

              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 4 locations. Consider refactoring.
              Open

                      if (value.widthMax) {
                          filters.push({
                              range: {
                                  [`${this.options.name}.width`]: {
                                      lte: pd.convertNumber(
              Severity: Major
              Found in src/schemas/types/Dimension.js and 3 other locations - About 2 hrs to fix
              src/schemas/types/Dimension.js on lines 156..168
              src/schemas/types/Dimension.js on lines 184..196
              src/schemas/types/Dimension.js on lines 198..210

              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 4 locations. Consider refactoring.
              Open

                      if (value.heightMax) {
                          filters.push({
                              range: {
                                  [`${this.options.name}.height`]: {
                                      lte: pd.convertNumber(
              Severity: Major
              Found in src/schemas/types/Dimension.js and 3 other locations - About 2 hrs to fix
              src/schemas/types/Dimension.js on lines 156..168
              src/schemas/types/Dimension.js on lines 170..182
              src/schemas/types/Dimension.js on lines 184..196

              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 4 locations. Consider refactoring.
              Open

                      if (value.heightMin) {
                          filters.push({
                              range: {
                                  [`${this.options.name}.height`]: {
                                      gte: pd.convertNumber(
              Severity: Major
              Found in src/schemas/types/Dimension.js and 3 other locations - About 2 hrs to fix
              src/schemas/types/Dimension.js on lines 156..168
              src/schemas/types/Dimension.js on lines 170..182
              src/schemas/types/Dimension.js on lines 198..210

              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

                      if (value.width) {
                          ret[`${this.searchName()}.widthMin`] = value.width;
                          ret[`${this.searchName()}.widthMax`] = value.width;
                      }
              Severity: Major
              Found in src/schemas/types/Dimension.js and 1 other location - About 1 hr to fix
              src/schemas/types/Dimension.js on lines 78..81

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

              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.height) {
                          ret[`${this.searchName()}.heightMin`] = value.height;
                          ret[`${this.searchName()}.heightMax`] = value.height;
                      }
              Severity: Major
              Found in src/schemas/types/Dimension.js and 1 other location - About 1 hr to fix
              src/schemas/types/Dimension.js on lines 91..94

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

              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

                      DimensionSchema.methods = {
                          toJSON() {
                              const obj = this.toObject();
                              delete obj.original;
                              return obj;
              Severity: Minor
              Found in src/schemas/types/Dimension.js and 1 other location - About 30 mins to fix
              src/schemas/types/YearRange.js on lines 246..252

              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