inventid/live-image-resize

View on GitHub

Showing 43 of 43 total issues

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

export default async function populateUploadedAt() {
  // eslint-disable-next-line no-constant-condition
  while (true) {
    const toEnrich = await database.getTokensWithoutUploadedAt();

Severity: Major
Found in src/migrations/populateTokensUploadedAt.js and 1 other location - About 1 day to fix
src/migrations/deleteTokensWithoutAssociatedFile.js on lines 10..41

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

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

export default async function deleteTokensWithoutAssociatedFile() {
  // eslint-disable-next-line no-constant-condition
  while (true) {
    const toEnrich = await database.getTokensWithoutUploadedAt();

Severity: Major
Found in src/migrations/deleteTokensWithoutAssociatedFile.js and 1 other location - About 1 day to fix
src/migrations/populateTokensUploadedAt.js on lines 10..41

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

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

Function postgresql has 214 lines of code (exceeds 25 allowed). Consider refactoring.
Open

export default function postgresql() {
  const configs = {
    user: config.get('postgresql.user'),
    database: config.get('postgresql.database'),
    password: config.get('postgresql.password'),
Severity: Major
Found in src/databases/postgresql.js - About 1 day to fix

    Function magic has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring.
    Open

    export async function magic(params, method, response, stats = undefined, metric = undefined, shouldBeFresh = false) {
      if (params === null) {
        // Invalid, hence reject
        response.status(400).end();
        if (metric) {
    Severity: Minor
    Found in src/imageResponse.js - About 6 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 magic has 104 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    export async function magic(params, method, response, stats = undefined, metric = undefined, shouldBeFresh = false) {
      if (params === null) {
        // Invalid, hence reject
        response.status(400).end();
        if (metric) {
    Severity: Major
    Found in src/imageResponse.js - About 4 hrs to fix

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

        async function consumeToken(token, id) {
          const vars = [token, id];
          const metric = timingMetric(DATABASE, {tags: {sqlOperation: 'consumeToken'}});
          try {
            const result = await pool.query(consumeTokens, vars);
      Severity: Major
      Found in src/databases/postgresql.js and 1 other location - About 4 hrs to fix
      src/databases/postgresql.js on lines 109..121

      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

        async function markUploadAsCompleted(token, id) {
          const vars = [token, id];
          const metric = timingMetric(DATABASE, {tags: {sqlOperation: 'markUploadAsCompleted'}});
          try {
            const result = await pool.query(markAsCompleted, vars);
      Severity: Major
      Found in src/databases/postgresql.js and 1 other location - About 4 hrs to fix
      src/databases/postgresql.js on lines 89..101

      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

      Function postgresql has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

      export default function postgresql() {
        const configs = {
          user: config.get('postgresql.user'),
          database: config.get('postgresql.database'),
          password: config.get('postgresql.password'),
      Severity: Minor
      Found in src/databases/postgresql.js - About 3 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 redis has 63 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      export default function redis() {
        const url = config.get('redis.url');
      
        const client = redisClient.createClient({url, prefix: 'iaas--'});
        const get = promisify(client.get).bind(client);
      Severity: Major
      Found in src/caches/redis.js - About 2 hrs to fix

        Function uploadImage has 62 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        const uploadImage = async (req, res) => {
          const sentToken = req.headers['x-token'];
          const name = req.params.name;
          log('info', `Requested image upload for image_id ${name} with token ${sentToken}`);
          const metric = timingMetric(UPLOAD, {fields: {name: name}});
        Severity: Major
        Found in src/index.js - About 2 hrs to fix

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

            if (params.width > config.get('constraints.max_width')) {
              params.width = config.get('constraints.max_width');
              if (params.fit === 'crop') {
                params.height = Math.round(params.width / providedRatio);
              }
          Severity: Major
          Found in src/imageResponse.js and 1 other location - About 2 hrs to fix
          src/imageResponse.js on lines 82..87

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

          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 (params.height > config.get('constraints.max_height')) {
              params.height = config.get('constraints.max_height');
              if (params.fit === 'crop') {
                params.width = Math.round(params.height * providedRatio);
              }
          Severity: Major
          Found in src/imageResponse.js and 1 other location - About 2 hrs to fix
          src/imageResponse.js on lines 76..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 84.

          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

          File index.js has 258 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import "babel-polyfill";
          
          import express from "express";
          import config from "config";
          import bodyParser from "body-parser";
          Severity: Minor
          Found in src/index.js - About 2 hrs to fix

            Function setup has 48 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            function setup() {
              const influxConnection = config.get("metrics.influx.dsn");
              const influx = new InfluxDB(influxConnection);
              log('debug', `Connecting influx to ${influxConnection}`);
            
            
            Severity: Minor
            Found in src/metrics/influx.js - About 1 hr to fix

              Function urlToParams has 47 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              export default function urlToParams(req, requireDimensions = true) {
                // The default settings
                const result = {
                  name: null,
                  width: undefined,
              Severity: Minor
              Found in src/urlParameters.js - About 1 hr to fix

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

                export async function getImageFromCache(params) {
                  try {
                    if (cache === null) {
                      return null;
                    }
                Severity: Major
                Found in src/fastCache.js and 1 other location - About 1 hr to fix
                src/fastCache.js on lines 23..33

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

                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

                export async function getSizeFromCache(params) {
                  try {
                    if (cache === null) {
                      return null;
                    }
                Severity: Major
                Found in src/fastCache.js and 1 other location - About 1 hr to fix
                src/fastCache.js on lines 4..14

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

                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

                Function urlToParams has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
                Open

                export default function urlToParams(req, requireDimensions = true) {
                  // The default settings
                  const result = {
                    name: null,
                    width: undefined,
                Severity: Minor
                Found in src/urlParameters.js - 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 writeOriented has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                export async function writeOriented(source, destination, cropParameters) {
                  // if possible, crop first (since the UA had that orientation), then orient
                  if (cropParameters) {
                    const cropped = im(source).options(gmOptions)
                      .crop(cropParameters.width, cropParameters.height, cropParameters.xOffset, cropParameters.yOffset);
                Severity: Minor
                Found in src/image.js - About 1 hr to fix

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

                  export default function integerCounter() {
                    let i = 0;
                  
                    function incrementAndGet() {
                      i = i + 1;
                  Severity: Minor
                  Found in src/integerCounter.js - About 1 hr to fix
                    Severity
                    Category
                    Status
                    Source
                    Language