<commit_before><?php

namespace Lechimp\Dicto\Report;

/**
 * Shows the diff in violations between two commits per rule.
 */
class DiffPerRuleReport extends Report {
    /**
     * @inheritdoc
     */
    protected function default_template() {
        return "diff_per_rule";
    }

    /**
     * @return  string|null
     */
    protected function source_url() {
        return $this->custom_config_value("source_url", null);
    }

    /**
     * @inheritdoc
     */
    public function generate() {
        $cur_run = $this->queries->last_run();
        $prev_run = $this->queries->run_with_different_commit_before($cur_run);
        $source_url = $this->source_url();
        $current = $this->queries->run_info($cur_run);
        return
            [ "run_id"  => $cur_run
            , "current" => $current
            , "previous" => $this->queries->run_info($prev_run)
            , "violations" =>
                [ "total" => $this->queries->count_violations_in($cur_run)
                , "added" => $this->queries->count_added_violations($prev_run, $cur_run)
                , "resolved" => $this->queries->count_resolved_violations($prev_run, $cur_run)
                ]
            , "rules" => array_map
                ( function($rule) use ($cur_run, $prev_run, $current, $source_url) {
                    $rule_info = $this->queries->rule_info($rule);
                    return
                        [ "rule" => $rule_info["rule"]
                        , "explanation" => $rule_info["explanation"]
                        , "violations" =>
                            [ "total" => $this->queries->count_violations_in($cur_run, $rule)
                            , "added" => $this->queries->count_added_violations($prev_run, $cur_run, $rule)
                            , "resolved" => $this->queries->count_resolved_violations($prev_run, $cur_run, $rule)
                            , "list" => array_map
                                ( function($v) use ($current, $source_url) {
                                    if ($source_url !== null) {
                                        $v["url"] = $this->make_url
                                                        ( $source_url
                                                        , (isset($v["resolved_in"])) ? $v["resolved_in"] : $current["commit_hash"]
                                                        , $v["file"]
                                                        , $v["line_no"]
                                                        );
                                    }
                                    else {
                                        $v["url"] = null;
                                    }
                                    return $v;
                                }
                                ,
                                array_merge(
                                    $this->queries->violations_of($rule, $cur_run),
                                    $this->queries->resolved_violations_of($rule, $cur_run)
                                )
                            )
                            ]
                        ];
                }
                , $this->queries->analyzed_rules($cur_run)
                )
            ];
    }

    protected function make_url($source_url, $commit_hash, $file, $line) {
        return
            str_replace("{COMMIT}", $commit_hash,
            str_replace("{FILE}", $file,
            str_replace("{LINE}", $line,
                $source_url)));
    }
}
<commit_msg>adjusted DiffPerRuleReport class to changes in Queries::resolved_violations<commit_after><?php

namespace Lechimp\Dicto\Report;

/**
 * Shows the diff in violations between two commits per rule.
 */
class DiffPerRuleReport extends Report {
    /**
     * @inheritdoc
     */
    protected function default_template() {
        return "diff_per_rule";
    }

    /**
     * @return  string|null
     */
    protected function source_url() {
        return $this->custom_config_value("source_url", null);
    }

    /**
     * @inheritdoc
     */
    public function generate() {
        $cur_run = $this->queries->last_run();
        $prev_run = $this->queries->run_with_different_commit_before($cur_run);
        $source_url = $this->source_url();
        $current = $this->queries->run_info($cur_run);
        $previous = $this->queries->run_info($prev_run);
        return
            [ "run_id"  => $cur_run
            , "current" => $current
            , "previous" => $this->queries->run_info($prev_run)
            , "violations" =>
                [ "total" => $this->queries->count_violations_in($cur_run)
                , "added" => $this->queries->count_added_violations($prev_run, $cur_run)
                , "resolved" => $this->queries->count_resolved_violations($prev_run, $cur_run)
                ]
            , "rules" => array_map
                ( function($rule) use ($cur_run, $prev_run, $current, $previous, $source_url) {
                    $rule_info = $this->queries->rule_info($rule);
                    return
                        [ "rule" => $rule_info["rule"]
                        , "explanation" => $rule_info["explanation"]
                        , "violations" =>
                            [ "total" => $this->queries->count_violations_in($cur_run, $rule)
                            , "added" => $this->queries->count_added_violations($prev_run, $cur_run, $rule)
                            , "resolved" => $this->queries->count_resolved_violations($prev_run, $cur_run, $rule)
                            , "list" => array_map
                                ( function($v) use ($current, $previous, $source_url) {
                                    if ($source_url !== null) {
                                        $v["url"] = $this->make_url
                                                        ( $source_url
                                                        , (isset($v["last_seen_in"])) ? $v["last_seen_in"] : $previous["commit_hash"]
                                                        , $v["file"]
                                                        , $v["line_no"]
                                                        );
                                    }
                                    else {
                                        $v["url"] = null;
                                    }
                                    return $v;
                                }
                                ,
                                array_merge(
                                    $this->queries->violations_of($rule, $cur_run),
                                    $this->queries->resolved_violations($rule, $prev_run, $cur_run)
                                )
                            )
                            ]
                        ];
                }
                , $this->queries->analyzed_rules($cur_run)
                )
            ];
    }

    protected function make_url($source_url, $commit_hash, $file, $line) {
        return
            str_replace("{COMMIT}", $commit_hash,
            str_replace("{FILE}", $file,
            str_replace("{LINE}", $line,
                $source_url)));
    }
}

{'fraction_non_alphanumeric': 0.12445115257958288, 'fraction_numerical': 0.0, 'mean_word_length': 1.0915351506456241, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 40, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5694915', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1795, 'n_words': 267}