MyPhpRules implements RulesDefinition, PHPCustomRuleRepository { @Override public void define(Context context) { NewRepository repository = context.createRepository(repositoryKey(), "php").setName("MyCompany Custom Repository"); RulesDefinitionAnnotationLoader annotationLoader = new RulesDefinitionAnnotationLoader(); checkClasses().forEach(ruleClass -> annotationLoader.load(repository, ruleClass)); repository.rules().forEach(rule -> rule.setHtmlDescription(loadResource("/org/sonar/l10n/php/rules/custom/" + rule.key() + ".html"))); Map<String, String> remediationCosts = new HashMap<>(); remediationCosts.put(ForbiddenFunctionUseCheck.KEY, "5min"); remediationCosts.put(OtherForbiddenFunctionUseCheck.KEY, "5min"); repository.rules().forEach(rule -> rule.setDebtRemediationFunction( rule.debtRemediationFunctions().constantPerIssue(remediationCosts.get(rule.key())))); repository.done(); }  @Override String repositoryKey(); @Override ImmutableList<Class> checkClasses(); @Override void define(Context context);  }
@Test public void rules() { MyPhpRules rulesDefinition = new MyPhpRules(); RulesDefinition.Context context = new RulesDefinition.Context(); rulesDefinition.define(context); RulesDefinition.Repository repository = context.repository("custom"); assertEquals(2, repository.rules().size()); }