PHPackages                             cihispano/git-hooks - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. cihispano/git-hooks

ActiveLibrary[Testing &amp; Quality](/categories/testing)

cihispano/git-hooks
===================

Automated Git Hooks for CodeIgniter 4 projects with PHPStan, PHP CS Fixer, and quality checks

v1.1.0(3mo ago)01MITPHPPHP ^8.1CI passing

Since Mar 20Pushed 3mo agoCompare

[ Source](https://github.com/cihispano/git-hooks)[ Packagist](https://packagist.org/packages/cihispano/git-hooks)[ Docs](https://github.com/cihispano/git-hooks)[ RSS](/packages/cihispano-git-hooks/feed)WikiDiscussions main Synced 3w ago

READMEChangelogDependencies (7)Versions (5)Used By (0)

Git Hooks for CodeIgniter 4
===========================

[](#git-hooks-for-codeigniter-4)

[![Latest Version](https://camo.githubusercontent.com/a161b63580d8bf2b9f1ff91779338bc2f75da3cbe84b62fea2d638e61062a59b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636968697370616e6f2f6769742d686f6f6b732e737667)](https://packagist.org/packages/cihispano/git-hooks)[![Total Downloads](https://camo.githubusercontent.com/d4551b7576ab113a8a25f982879a97f933246a7d60b2fa98b4c14dd5a7eb1b88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636968697370616e6f2f6769742d686f6f6b732e737667)](https://packagist.org/packages/cihispano/git-hooks)[![License](https://camo.githubusercontent.com/31d5fb3612d4534156eee5f1dc0ac42d56f45aeea29ee515987a5ad255f60d21/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f636968697370616e6f2f6769742d686f6f6b732e737667)](https://packagist.org/packages/cihispano/git-hooks)[![PHP Version](https://camo.githubusercontent.com/ddf9fbbd5179ff6569e2db1c18c489408d560331c2c506cafcf8b19f9721befb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f636968697370616e6f2f6769742d686f6f6b732e737667)](https://packagist.org/packages/cihispano/git-hooks)

Automated Git Hooks for CodeIgniter 4 projects. This package ensures your code meets the highest quality standards by running automated checks before every commit.

✨ Features
----------

[](#-features)

- 🔍 **PHP Syntax Check** - Validates PHP syntax (lint) on all staged files.
- 📊 **PHPStan Analysis** - Performs deep static analysis to find potential bugs (Level: Max).
- 👃 **PHP\_CodeSniffer** - Validates PSR-12 compliance and coding standards.
- 🎨 **PHP CS Fixer** - Automatically formats code to follow defined styles.
- 🎯 **Smart Scope** - Only analyzes staged files to keep your workflow fast.
- 🌈 **Termwind Output** - Beautiful, colorful console feedback with icons.
- 🔧 **Zero Config** - Works out of the box with sensible defaults for CI4.

📋 Requirements
--------------

[](#-requirements)

- **PHP 8.1** to **8.4**
- **Git 2.0** or higher
- **Composer 2.0** or higher

Compatibility policy
--------------------

[](#compatibility-policy)

- Runtime compatibility: the package is supported on PHP 8.1 through 8.4.
- Development dependency resolution: `composer.lock` is generated with `config.platform.php=8.1.0`.
- CI validation: tests and static analysis run on PHP 8.1, 8.2, 8.3, and 8.4 in both GitHub Actions and GitLab CI.
- Coding style checks (`composer sniff` and `composer cs`) run on PHP 8.1 to keep formatter and sniffer output aligned with the minimum supported runtime.
- When running `composer cs` on PHP newer than 8.1, PHP CS Fixer may show a warning. This is expected; use PHP 8.1 locally if you want warning-free style checks.

📦 Installation
--------------

[](#-installation)

Install the package as a development dependency:

```
composer require --dev cihispano/git-hooks
```

The hooks will be installed automatically after installation.

### Manual Installation

[](#manual-installation)

If you need to reinstall the hooks:

```
composer install-hooks
```

🚀 Usage
-------

[](#-usage)

Once installed, the hooks work automatically.

### `pre-commit`

[](#pre-commit)

Every time you commit code, the `pre-commit` hook will:

1. ✅ Check PHP syntax on all staged `.php` files
2. ✅ Run PHPStan analysis (if installed)
3. ✅ Check PSR-12 compliance with PHP\_CodeSniffer (if installed)
4. ✅ Verify formatting with PHP CS Fixer (if installed)

### `commit-msg`

[](#commit-msg)

The `commit-msg` hook validates the first line of your commit message:

1. ✅ Minimum 10 characters
2. ✅ Maximum 100 characters
3. ✅ Conventional Commits format

See [`docs/CONVENTIONAL_COMMITS.md`](docs/CONVENTIONAL_COMMITS.md) for examples and guidance.

### `pre-push`

[](#pre-push)

Before pushing, the `pre-push` hook runs a full-project validation:

1. ✅ PHPUnit, if available in the target project
2. ✅ Full PHPStan analysis

This repository ships its own PHPUnit suite for the package itself. The installed `pre-push` hook is also designed for consumer projects and will run PHPUnit there when it is available. If PHPUnit is not installed in the target project, the hook skips that step and continues with the remaining checks.

### Example Output

[](#example-output)

```
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Starting CodeIgniter pre-commit checks...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

[1/4] Checking PHP syntax...
✓ Syntax check passed

[2/4] Running PHPStan analysis...
✓ Analysis passed

[3/4] Sniffing code style (PHPCS)...
✓ PSR-12 compliance verified

[4/4] Verifying formatting (PHP CS Fixer)...
✓ Style check passed

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✓ All checks passed! Proceeding with commit...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```

### When a Check Fails

[](#when-a-check-fails)

If any check fails, the commit will be blocked:

```
[4/4] Verifying formatting (PHP CS Fixer)...
✗ Code style issues in: app/Controllers/Home.php
Run: php vendor/bin/php-cs-fixer fix app/Controllers/Home.php
```

Fix the issues and try again:

```
# Fix code style automatically
composer cs:fix

# Stage the fixed files
git add .

# Try committing again
git commit -S -m "Your message"
```

🛠️ Configuration
----------------

[](#️-configuration)

### Skipping Hooks (Not Recommended)

[](#skipping-hooks-not-recommended)

If you need to commit without running the hooks:

```
git commit --no-verify -m "Emergency fix"
```

⚠️ **Warning:** Only use this in emergencies. Your code should always pass the quality checks.

### Uninstalling Hooks

[](#uninstalling-hooks)

To remove the Git hooks:

```
composer uninstall-hooks
```

### Customizing the Hooks

[](#customizing-the-hooks)

The hooks are located in your project's `.git/hooks/` directory after installation. You can modify them if needed, but keep in mind they will be overwritten when you update the package.

📊 Composer Scripts
------------------

[](#-composer-scripts)

This package provides the following Composer scripts:

```
{
    "scripts": {
        "install-hooks": "CiHispano\\ComposerScripts::install",
        "uninstall-hooks": "CiHispano\\ComposerScripts::uninstall",
        "analyze": "@php -d xdebug.mode=off -d xdebug.log= vendor/bin/phpstan analyze --verbose",
        "check:all": [
            "@analyze",
            "@sniff",
            "@cs",
            "@test"
        ],
        "cs": "@php -d xdebug.mode=off -d xdebug.log= vendor/bin/php-cs-fixer fix --ansi --verbose --dry-run --diff",
        "cs:fix": "@php -d xdebug.mode=off -d xdebug.log= vendor/bin/php-cs-fixer fix --ansi --verbose --diff",
        "sniff": "@php -d xdebug.mode=off -d xdebug.log= vendor/bin/phpcs",
        "sniff:fix": "@php -d xdebug.mode=off -d xdebug.log= vendor/bin/phpcbf",
        "test": "@php -d xdebug.mode=off -d xdebug.log= vendor/bin/phpunit --configuration phpunit.xml.dist --colors=always",
        "test:coverage": "@php -d xdebug.mode=coverage -d xdebug.start_with_request=yes vendor/bin/phpunit --configuration phpunit.xml.dist --colors=always --coverage-text --coverage-html build/coverage"
    }
}
```

Add these to your `composer.json` to access them easily:

```
composer install-hooks
composer uninstall-hooks
composer analyze
composer check:all
composer sniff
composer cs
composer cs:fix
composer sniff:fix
composer test
composer test:coverage
```

🔧 Integration with Existing Projects
------------------------------------

[](#-integration-with-existing-projects)

### With PHPStan

[](#with-phpstan)

Add PHPStan to your project:

```
composer require --dev phpstan/phpstan
```

Create `phpstan.neon`:

```
parameters:
    level: max
    paths:
        - app
```

### With PHP CS Fixer

[](#with-php-cs-fixer)

Add PHP CS Fixer to your project:

```
composer require --dev friendsofphp/php-cs-fixer
```

Create `.php-cs-fixer.dist.php`:

```
