@Override
  public Measure calculate(FormulaData data, FormulaContext context) {

    Double criticalCount = MeasureUtils.getValue(data.getMeasure(FortifyMetrics.CFPO), null);
    Double highCount = MeasureUtils.getValue(data.getMeasure(FortifyMetrics.HFPO), null);
    Double mediumCount = MeasureUtils.getValue(data.getMeasure(FortifyMetrics.MFPO), null);
    Double lowCount = MeasureUtils.getValue(data.getMeasure(FortifyMetrics.LFPO), null);

    if (criticalCount != null && highCount != null && mediumCount != null && lowCount != null) {
      Double securityRatingLevel;
      if (criticalCount > 0) {
        securityRatingLevel = SecurityRatingFormula.BLOCKER_SECURITY_RATING_LEVEL;
      } else if (highCount > 0) {
        securityRatingLevel = SecurityRatingFormula.CRITICAL_SECURITY_RATING_LEVEL;
      } else if (mediumCount > 0) {
        securityRatingLevel = SecurityRatingFormula.MAJOR_SECURITY_RATING_LEVEL;
      } else if (lowCount > 0) {
        securityRatingLevel = SecurityRatingFormula.MINOR_SECURITY_RATING_LEVEL;
      } else {
        securityRatingLevel = SecurityRatingFormula.DEFAULT_SECURITY_RATING_LEVEL;
      }

      return new Measure(context.getTargetMetric(), securityRatingLevel);
    }
    return null;
  }
  /**
   * @param context the context
   * @return the valid lines of the component, i.e. the real number of lines
   */
  protected double getValidLines(DecoratorContext context) {
    double duplicatedLines =
        MeasureUtils.getValue(context.getMeasure(CoreMetrics.DUPLICATED_LINES), 0.0);
    double totalLines = MeasureUtils.getValue(context.getMeasure(CoreMetrics.NCLOC), 0.0);
    double validLines = totalLines - duplicatedLines;

    return validLines > 0 ? validLines : 1.0;
  }
 @Override
 protected Double countCoveredElements(DecoratorContext context) {
   double uncoveredLines =
       MeasureUtils.getValue(context.getMeasure(JaCoCoItMetrics.IT_UNCOVERED_LINES), 0.0);
   double lines =
       MeasureUtils.getValue(context.getMeasure(JaCoCoItMetrics.IT_LINES_TO_COVER), 0.0);
   return lines - uncoveredLines;
 }
 /** {@inheritDoc} */
 public void decorate(Resource resource, DecoratorContext context) {
   if (!shouldDecorateResource(resource, context)) {
     return;
   }
   Double functions = MeasureUtils.getValue(context.getMeasure(CoreMetrics.FUNCTIONS), null);
   Double complexity = MeasureUtils.getValue(context.getMeasure(CoreMetrics.COMPLEXITY), null);
   if (complexity != null && functions != null && functions > 0.0) {
     context.saveMeasure(CoreMetrics.FUNCTION_COMPLEXITY, complexity / functions);
   }
 }
  @Override
  public void checkResource(
      Resource resource,
      DecoratorContext context,
      RuleKey rule,
      ResourcePerspectives perspectives) {
    double lineCoverage =
        MeasureUtils.getValue(context.getMeasure(CoreMetrics.BRANCH_COVERAGE), 0.0);
    if (context.getMeasure(CoreMetrics.BRANCH_COVERAGE) != null
        && lineCoverage < minimumBranchCoverageRatio) {
      double uncoveredConditions =
          MeasureUtils.getValue(context.getMeasure(CoreMetrics.UNCOVERED_CONDITIONS), 0.0);
      double conditionsToCover =
          MeasureUtils.getValue(context.getMeasure(CoreMetrics.CONDITIONS_TO_COVER), 0.0);
      double conditionsToCoverToReachThreshold =
          Math.ceil(
              (conditionsToCover * minimumBranchCoverageRatio / 100)
                  - (conditionsToCover - uncoveredConditions));

      createIssue(resource, rule, conditionsToCoverToReachThreshold, perspectives);
    }
  }
 @Override
 protected Double countElements(DecoratorContext context) {
   return MeasureUtils.getValue(context.getMeasure(JaCoCoItMetrics.IT_LINES_TO_COVER), 0.0);
 }