PHP code example of wtyd / githooks

1. Go to this page and download the library: Download wtyd/githooks library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wtyd / githooks example snippets



return [
    // Git hooks: map git events to flows/jobs
    'hooks' => [
        'command'    => 'php7.4 vendor/bin/githooks', // optional: customize the hook script command
        'pre-commit' => ['qa'],
        'pre-push'   => [
            ['flow' => 'full', 'only-on' => ['main', 'develop']], // only on these branches
        ],
    ],

    // Flows: named groups of jobs with shared execution options
    'flows' => [
        'options' => ['fail-fast' => false, 'processes' => 2], // global defaults
        'qa'   => ['jobs' => ['phpcbf_src', 'phpcs_src', 'phpmd_src', 'parallel_lint']],
        'full' => ['jobs' => ['phpstan_src', 'phpunit_all']],

        // CI flow that picks its mode per branch and declares intra-flow dependencies
        'ci' => [
            'on' => [
                'master' => ['execution' => 'full'],          // full on protected branches
                '*'      => ['execution' => 'fast-branch'],   // diff vs base everywhere else
            ],
            'jobs' => [
                'yarn_install',                                                  // installs node_modules
                ['job' => 'eslint_src',  'needs' => ['yarn_install']],            // waits for install
                ['job' => 'phpunit_all', 'only-files' => ['src/**', 'tests/**']], // admission gate
            ],
        ],
    ],

    // Jobs: individual QA tasks with declarative configuration
    'jobs' => [
        'phpcs_src' => [
            'type'     => 'phpcs',
            'paths'    => ['src'],
            'standard' => 'PSR12',
            'ignore'   => ['vendor'],
            // executable-path omitted: auto-detects vendor/bin/phpcs, then system PATH
        ],
        'phpcbf_src' => [
            'extends' => 'phpcs_src', // inherits paths, standard, ignore from phpcs
            'type'    => 'phpcbf',    // overrides type
        ],
        'phpmd_src' => [
            'type'            => 'phpmd',
            'executable-path' => 'tools/phpmd', // explicit path when not in vendor/bin
            'paths'           => ['src'],
            'rules'           => 'cleancode,codesize,naming,unusedcode',
        ],
        'parallel_lint' => [
            'type'    => 'parallel-lint',
            'paths'   => ['src'],
            'exclude' => ['vendor'],
        ],
        'phpstan_src' => [
            'type'  => 'phpstan',
            'level' => 8,
            'paths' => ['src'],
        ],
        'phpunit_all' => [
            'type'   => 'phpunit',
            'config' => 'phpunit.xml',
        ],
        'composer_audit' => [
            'type'   => 'custom', // run any command
            'script' => 'composer audit',
        ],
        'yarn_install' => [
            'type'   => 'script', // one-liner; no path filtering
            'script' => 'yarn install --frozen-lockfile',
        ],
        'eslint_src' => [
            'type'            => 'custom',
            'executable-path' => 'npx eslint',    // structured mode: executable + paths
            'paths'           => ['resources/js'],
            'other-arguments' => '--fix',
            'accelerable'     => true,            // opt-in: filters paths to staged files with --fast
        ],
    ],
];