<commit_before>#!/usr/bin/php
<?php
/**
 * .git/hooks/pre-commit.
 *
 * This pre-commit hooks will check for PHP error (lint), and make sure the code
 * is PSR compliant.
 *
 * Dependecy: PHP-CS-Fixer (https://github.com/fabpot/PHP-CS-Fixer)
 *
 * @author  Mardix  http://github.com/mardix
 *
 * @since   Sept 4 2012
 */

// collect all files which have been added, copied or modified
exec('git diff --cached --name-status --diff-filter=ACM', $output);

foreach ($output as $file) {
    $fileName = trim(substr($file, 1));
    if (pathinfo($fileName, PATHINFO_EXTENSION) == 'php') {

        // Check for lint errors
        $lint_output = array();
        exec('php -l '.escapeshellarg($fileName), $lint_output, $return);

        if ($return === 0) {
            /*
             * PHP-CS-Fixer && add it back
             */
            exec("vendor/bin/php-cs-fixer fix {$fileName} --level=psr2 --fixers=-psr0; git add {$fileName}");
        } else {
            echo implode("\n", $lint_output), "\n";
            exit(1);
        }
    }
}

exit(0);<commit_msg>refactor pre-commit hook to be able to add more linters<commit_after>#!/usr/bin/php
<?php
/**
 * .git/hooks/pre-commit.
 *
 * This pre-commit hooks will check for PHP error (lint), and make sure the code
 * is PSR compliant.
 *
 * Dependecy: PHP-CS-Fixer (https://github.com/fabpot/PHP-CS-Fixer)
 *
 * @author  Mardix  http://github.com/mardix
 *
 * @since   Sept 4 2012
 */

// collect all files which have been added, copied or modified
exec('git diff --cached --name-only --diff-filter=ACM', $output);

foreach ($output as $fileName) {
    $ext = pathinfo($fileName, PATHINFO_EXTENSION);
    $fileName = escapeshellarg($fileName);
    if ($ext === 'php') {
        runCheck("php -l $fileName");
        if (runCheck("vendor/bin/php-cs-fixer fix $fileName --level=psr2 --fixers=-psr0")) {
            exec("git add $fileName");
        }
    }
}

function runCheck($command)
{
    $output = [];
    exec($command, $output, $return);
    $changed = count($output);
    if ($changed) {
        echo implode("\n", $output) . "\n";
    }
    if ($return !== 0) {
        exit($return);
    }
    return $changed;
}

exit(0);
{'fraction_non_alphanumeric': 0.1723034734917733, 'fraction_numerical': 0.009140767824497258, 'mean_word_length': 2.4856687898089174, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4974262', 'n_tokens_mistral': 753, 'n_tokens_neox': 741, 'n_words': 189}