CMSgov/dpc-app

View on GitHub
dpc-common/src/main/java/gov/cms/dpc/common/utils/MetricMaker.java

Summary

Maintainability
A
0 mins
Test Coverage

T is not used in the method.
Open

    private synchronized <T extends Metric> T registerMetric(String name, MetricRegistry.MetricSupplier<T> supplier) {

Type parameters that aren't used are dead code, which can only distract and possibly confuse developers during maintenance. Therefore, unused type parameters should be removed.

Noncompliant Code Example

int <T> Add(int a, int b) // Noncompliant; <T> is ignored
{
  return a + b;
}

Compliant Solution

int Add(int a, int b)
{
  return a + b;
}

Remove this unused private "CachedGaugeFromSupplier" class.
Open

    private static class CachedGaugeFromSupplier<T> extends CachedGauge<T> {

private classes that are never used are dead code: unnecessary, inoperative code that should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.

Noncompliant Code Example

public class Foo
{
  ...
  private class MyUnusedPrivateClass {...} // Noncompliant
}

Remove this useless assignment to local variable "metrics".
Open

        final var metrics = metricRegistry.getMetrics();

A dead store happens when a local variable is assigned a value that is not read by any subsequent instruction. Calculating or retrieving a value only to then overwrite it or throw it away, could indicate a serious error in the code. Even if it's not an error, it is at best a waste of resources. Therefore all calculated values should be used.

Noncompliant Code Example

i = a + b; // Noncompliant; calculation result not used before value is overwritten
i = compute();

Compliant Solution

i = a + b;
i += compute();

Exceptions

This rule ignores initializations to -1, 0, 1, null, true, false and "".

See

Remove this useless assignment to local variable "metricName".
Open

        final var metricName = MetricRegistry.name(klass, name);

A dead store happens when a local variable is assigned a value that is not read by any subsequent instruction. Calculating or retrieving a value only to then overwrite it or throw it away, could indicate a serious error in the code. Even if it's not an error, it is at best a waste of resources. Therefore all calculated values should be used.

Noncompliant Code Example

i = a + b; // Noncompliant; calculation result not used before value is overwritten
i = compute();

Compliant Solution

i = a + b;
i += compute();

Exceptions

This rule ignores initializations to -1, 0, 1, null, true, false and "".

See

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

    public Map<String, Timer> registerTimers(List<String> names) {
        final var map = new HashMap<String, Timer>();
        for (String name: names) {
            map.put(name, registerTimer(name + "Timer"));
        }
dpc-common/src/main/java/gov/cms/dpc/common/utils/MetricMaker.java on lines 69..75

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

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

    public Map<String, Meter> registerMeters(List<String> names) {
        final var map = new HashMap<String, Meter>();
        for (String name: names) {
            map.put(name, registerMeter(name + "Meter"));
        }
dpc-common/src/main/java/gov/cms/dpc/common/utils/MetricMaker.java on lines 45..51

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

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