livepeer/livepeerjs

View on GitHub
packages/explorer-2.0/apollo/createSchema.ts

Summary

Maintainability
F
1 wk
Test Coverage

Function createSchema has 355 lines of code (exceeds 25 allowed). Consider refactoring.
Open

const createSchema = async () => {
  const executor = async ({ document, variables }) => {
    const query = print(document);
    const fetchResult = await fetch(process.env.NEXT_PUBLIC_SUBGRAPH, {
      method: "POST",
Severity: Major
Found in packages/explorer-2.0/apollo/createSchema.ts - About 1 day to fix

Function createSchema has a Cognitive Complexity of 55 (exceeds 5 allowed). Consider refactoring.
Open

const createSchema = async () => {
  const executor = async ({ document, variables }) => {
    const query = print(document);
    const fetchResult = await fetch(process.env.NEXT_PUBLIC_SUBGRAPH, {
      method: "POST",
Severity: Minor
Found in packages/explorer-2.0/apollo/createSchema.ts - About 1 day 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

Consider simplifying this complex logical expression.
Open

            if (transcoders.filter((a) => a.id === key).length > 0) {
              performanceMetrics.push({
                id: key,
                scores: {
                  global: avg(metrics[key], "score") * 10000,
Severity: Critical
Found in packages/explorer-2.0/apollo/createSchema.ts - About 6 hrs to fix

File createSchema.ts has 385 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import fetch from "isomorphic-unfetch";
import Utils from "web3-utils";
import { createApolloFetch } from "apollo-fetch";
import { applyMiddleware } from "graphql-middleware";
import graphqlFields from "graphql-fields";
Severity: Minor
Found in packages/explorer-2.0/apollo/createSchema.ts - About 5 hrs to fix

Function transcoders has 68 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      transcoders: async (resolve, parent, args, ctx, info) => {
        const selectionSet = Object.keys(graphqlFields(info));
        const transcoders = await resolve(parent, args, ctx, info);
        const prices = [];
        const performanceMetrics = [];
Severity: Major
Found in packages/explorer-2.0/apollo/createSchema.ts - About 2 hrs to fix

Function resolve has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

          async resolve(_poll, _args, _ctx, _info) {
            const { number: blockNumber } = await _ctx.livepeer.rpc.getBlock(
              "latest"
            );
            const isActive = blockNumber <= parseInt(_poll.endBlock);
Severity: Minor
Found in packages/explorer-2.0/apollo/createSchema.ts - About 1 hr to fix

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

                roundTripScores: {
                  global: avg(metrics[key], "round_trip_score") * 10000,
                  fra: (metrics[key].FRA?.round_trip_score || 0) * 10000,
                  mdw: (metrics[key].MDW?.round_trip_score || 0) * 10000,
                  sin: (metrics[key].SIN?.round_trip_score || 0) * 10000,
Severity: Major
Found in packages/explorer-2.0/apollo/createSchema.ts and 2 other locations - About 1 day to fix
packages/explorer-2.0/apollo/createSchema.ts on lines 366..375
packages/explorer-2.0/apollo/createSchema.ts on lines 376..385

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

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

                scores: {
                  global: avg(metrics[key], "score") * 10000,
                  fra: (metrics[key].FRA?.score || 0) * 10000,
                  mdw: (metrics[key].MDW?.score || 0) * 10000,
                  sin: (metrics[key].SIN?.score || 0) * 10000,
Severity: Major
Found in packages/explorer-2.0/apollo/createSchema.ts and 2 other locations - About 1 day to fix
packages/explorer-2.0/apollo/createSchema.ts on lines 376..385
packages/explorer-2.0/apollo/createSchema.ts on lines 386..395

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

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

                successRates: {
                  global: avg(metrics[key], "success_rate") * 100,
                  fra: (metrics[key].FRA?.success_rate || 0) * 100,
                  mdw: (metrics[key].MDW?.success_rate || 0) * 100,
                  sin: (metrics[key].SIN?.success_rate || 0) * 100,
Severity: Major
Found in packages/explorer-2.0/apollo/createSchema.ts and 2 other locations - About 1 day to fix
packages/explorer-2.0/apollo/createSchema.ts on lines 366..375
packages/explorer-2.0/apollo/createSchema.ts on lines 386..395

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

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