-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9776667
Showing
11 changed files
with
1,005 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
trim_trailing_whitespace = true | ||
|
||
[*.php] | ||
indent_size = 4 | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: "tests" | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
jobs: | ||
tests: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
php-version: | ||
- php8.0 | ||
- php8.1 | ||
steps: | ||
- uses: actions/checkout@v1 | ||
- name: "Cache dependencies installed with composer" | ||
uses: actions/cache@v1 | ||
with: | ||
path: ~/.composer/cache | ||
key: php${{ matrix.php-version }}-composer-${{ hashFiles('**/composer.json') }} | ||
restore-keys: | | ||
php${{ matrix.php-version }}-composer- | ||
- name: "Validate composer.json file" | ||
run: composer validate | ||
- name: "Install PHP coding style checker" | ||
run: composer require "squizlabs/php_codesniffer":"^3.0" | ||
- name: "Check coding style after PSR-12 standard" | ||
run: php ./vendor/bin/phpcs --standard=PSR12 --encoding=utf-8 -n ./src |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/vendor | ||
/.idea | ||
index.php | ||
composer.phar | ||
composer.lock | ||
.DS_Store | ||
.phpunit.result.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Morten Rugaard | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# 🪝 Git Hooks for PHP [![GitHub Actions (tests)](https://github.com/rugaard/git-hooks-php/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/rugaard/git-hooks-php/actions/workflows/tests.yml) | ||
|
||
This is a "plugin" package which seamlessly integrates with the [Git Hooks](https://github.com/rugaard/git-hooks) package. | ||
|
||
It will install `git` hooks, that will automatically run multiple checks on your projects PHP files, to make sure they do not contain errors and follow the expected coding standards. | ||
|
||
## 📦 Installation | ||
|
||
You install the package via [Composer](https://getcomposer.org/) by using the following command: | ||
|
||
```shell | ||
composer require rugaard/git-hooks rugaard/git-hooks-php | ||
``` | ||
|
||
## 📝 Configuration | ||
|
||
To change the default configuration of one or more script, you need to have a `git-hooks.config.json` file in your project root. If you don't, you can create it with the following command: | ||
|
||
```shell | ||
./vendor/bin/git-hooks config | ||
``` | ||
|
||
### `Rugaard\GitHooks\PHP\Hooks\PreCommit\PhpCodeStyleCommand` | ||
|
||
Checks all staged `.php` files for coding style errors. | ||
|
||
| Parameter | Description | Default | | ||
| :--- | :--- | :---: | | ||
| `encoding` | Encoding of the files being checked | `utf-8` | | ||
| `hideWarnings` | Hide code style warnings | `true` | | ||
| `onlyStaged` | Only check code style on staged PHP files. | `true` | | ||
| `paths` | Paths to directories/files that should be checked. _Only used when `onlyStaged` is set to `false`_. | `[]` | | ||
| `config` | Path to custom configuration file.| `null` | | ||
|
||
**Note:** By default, if a valid `config` has not been provided, this command will look for `phpcs.xml` or `phpcs.xml.dist` as an alternative. | ||
|
||
If it finds any of those options, the above paramters will be ignored, and the configuration file will take priority. | ||
|
||
### `Rugaard\GitHooks\PHP\Hooks\PreCommit\PhpLintCommand` | ||
|
||
Checks all staged `.php` files for syntax errors. | ||
|
||
_**Script has nothing to configure**_ | ||
|
||
### `Rugaard\GitHooks\PHP\Hooks\PreCommit\PhpStaticAnalysisCommand` | ||
|
||
Statically analyzes all (or staged) `.php` files for errors. | ||
|
||
| Parameter | Description | Default | | ||
| :--- | :--- | :---: | | ||
| `level` | Level of strictness to use. From `0` to `9`. | `8` | | ||
| `onlyStaged` | Only analyze staged PHP files. | `true` | | ||
| `paths` | Only the following directories/files should be checked. | `[]` | | ||
| `memory-limit` | Set memory limit of process. Fx. `512M` for 512 MB. | `null` | | ||
| `config` | Path to custom configuration file. | `null` | | ||
|
||
**Note:** By default, if a valid `config` has not been provided, this command will look for `phpstan.neon` or `phpstan.neon.dist` as an alternative. | ||
|
||
If it finds any of those options, the above paramters will be ignored, and the configuration file will take priority. | ||
|
||
### `Rugaard\GitHooks\PHP\Hooks\PrePush\PhpTestSuiteCommand` | ||
|
||
Runs the projects test suite(s). | ||
|
||
| Parameter | Description | Default | | ||
| :--- | :--- | :---: | | ||
| `driver` | Application to run test suite(s). Supports: `phpunit` or `pest`* | `phpunit` | | ||
| `printer` | Change printer used by `driver` application | `\\NunoMaduro\\Collision\\Adapters\\Phpunit\\Printer` | | ||
| `config` | Path to custom configuration file | `null` | | ||
|
||
_* Requires `pest` to be installed in your project_ | ||
|
||
**Note:** By default, if a valid `config` has not been provided, this command will look for `phpunit.xml` or `phpunit.xml.dist` as an alternative. | ||
|
||
If it finds any of those options, the above paramters will be ignored, and the configuration file will take priority. | ||
|
||
## 🚓 License | ||
|
||
This package is licensed under [MIT](https://github.com/rugaard/git-hooks-php/blob/main/LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
{ | ||
"name": "rugaard/git-hooks-php", | ||
"type": "git-hook", | ||
"description": "PHP related Git hooks.", | ||
"keywords": [ | ||
"morten", | ||
"rugaard", | ||
"morten rugaard", | ||
"composer", | ||
"plugin", | ||
"composer plugin", | ||
"git", | ||
"hooks", | ||
"git hooks", | ||
"php", | ||
"php git hooks" | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Morten Rugaard", | ||
"email": "[email protected]", | ||
"homepage": "https://github.com/rugaard", | ||
"role": "Developer" | ||
} | ||
], | ||
"license": "MIT", | ||
"homepage": "https://github.com/rugaard", | ||
"support": { | ||
"issues": "https://github.com/rugaard/git-hooks-php/issues", | ||
"source": "https://github.com/rugaard/git-hooks-php" | ||
}, | ||
"require": { | ||
"php": "^8.0", | ||
"ext-json": "*", | ||
"phpstan/phpstan": "^1.0", | ||
"phpunit/phpunit": "^9.0", | ||
"rugaard/git-hooks": "^1.0", | ||
"squizlabs/php_codesniffer": "^3.0" | ||
}, | ||
"require-dev": { | ||
"roave/security-advisories": "dev-latest" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Rugaard\\GitHooks\\PHP\\": "src" | ||
} | ||
}, | ||
"config": { | ||
"optimize-autoloader": true, | ||
"preferred-install": "dist", | ||
"sort-packages": true, | ||
"allow-plugins": { | ||
"rugaard/git-hooks": true | ||
} | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rugaard\GitHooks\PHP\Exception; | ||
|
||
use Rugaard\GitHooks\Exception\GitHookException; | ||
|
||
/** | ||
* Class NoPathsProvidedException. | ||
* | ||
* @package Rugaard\GitHooks\PHP\Exception | ||
*/ | ||
class NoPathsProvidedException extends GitHookException | ||
{ | ||
} |
Oops, something went wrong.