Skip to content

Commit 6df4dba

Browse files
committed
first release
0 parents  commit 6df4dba

15 files changed

Lines changed: 779 additions & 0 deletions

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/vendor
2+
/composer.lock
3+
/node_modules
4+
/.idea
5+
/.vscode

.styleci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
preset: laravel
2+
3+
disabled:
4+
- concat_without_spaces
5+
- not_operator_with_successor_space
6+
- cast_spaces

.travis.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
language: php
2+
php:
3+
- 7.1
4+
- 7.2
5+
- 7.3
6+
7+
env:
8+
matrix:
9+
- COMPOSER_FLAGS="--prefer-lowest"
10+
- COMPOSER_FLAGS=""
11+
12+
before_script:
13+
- travis_retry composer self-update
14+
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-source
15+
16+
script:
17+
- ./vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover
18+
19+
after_script:
20+
- php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Phi Hoang.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Laravel Pre-commit
2+
3+
[![Latest Version on Packagist](https://img.shields.io/packagist/v/hoangphi/pre-commit.svg?style=flat-square)](https://packagist.org/packages/hoangphi/pre-commit)
4+
[![Total Downloads](https://img.shields.io/packagist/dt/hoangphi/pre-commit.svg?style=flat-square)](https://packagist.org/packages/hoangphi/pre-commit)
5+
[![Quality Score](https://img.shields.io/scrutinizer/g/hoangphi/pre-commit.svg?style=flat-square)](https://scrutinizer-ci.com/g/hoangphi/pre-commit)
6+
7+
## Installation
8+
9+
```bash
10+
composer require hoangphi/pre-commit
11+
```
12+
13+
Publish the configuration:
14+
15+
```bash
16+
php artisan vendor:publish --provider="HoangPhi\PreCommit\Providers\PreCommitServiceProvider" --tag=config
17+
```
18+
19+
### Config pre-commit hooks
20+
```bash
21+
php artisan pre-commit:install
22+
```
23+
24+
- Create PSR default config `phpcs.xml` in your root project.
25+
26+
```bash
27+
php artisan pre-commit:create-phpcs
28+
```
29+
30+
- Added all changed files to git stage and run test manually.
31+
32+
```bash
33+
php artisan pre-commit:check
34+
```

composer.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
{
2+
"name": "hoangphi/pre-commit",
3+
"description": "Check coding standard & code syntax before commit.",
4+
"type": "library",
5+
"license": "MIT",
6+
"keywords": [
7+
"git pre-commit",
8+
"php coding standard",
9+
"php code syntax",
10+
"php git commit checker"
11+
],
12+
"authors": [
13+
{
14+
"name": "Phi Hoang",
15+
"email": "hoangphi.dev@gmail.com"
16+
}
17+
],
18+
"minimum-stability": "dev",
19+
"autoload": {
20+
"psr-4": {
21+
"HoangPhi\\PreCommit\\": "src"
22+
}
23+
},
24+
"autoload-dev": {
25+
"psr-4": {
26+
"HoangPhi\\PreCommit\\Tests\\": "tests"
27+
}
28+
},
29+
"require": {
30+
"php": "^7.1.3|^8.0|^8.1",
31+
"laravel/framework": "^5.6|^6|^7|^8|^9",
32+
"php-parallel-lint/php-parallel-lint": "^1.0",
33+
"squizlabs/php_codesniffer": "^3.3"
34+
},
35+
"require-dev": {
36+
"phpunit/phpunit": "^6.1|^7.0|^8.0|^9.0"
37+
},
38+
"extra": {
39+
"laravel": {
40+
"providers": [
41+
"HoangPhi\\PreCommit\\Providers\\PreCommitServiceProvider"
42+
]
43+
}
44+
},
45+
"config": {
46+
"sort-packages": true
47+
}
48+
}

config/pre-commit.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
use HoangPhi\PreCommit\Commands\PreCommitHookCommand;
4+
5+
return [
6+
7+
'enabled' => env('PRE_COMMIT_ENABLED', true),
8+
9+
'psr2' => [
10+
'standard' => __DIR__ . '/../phpcs.xml',
11+
'ignored' => [
12+
'*/database/*',
13+
'*/public/*',
14+
'*/assets/*',
15+
'*/vendor/*',
16+
],
17+
],
18+
19+
'hooks' => [
20+
'pre-commit' => PreCommitHookCommand::class,
21+
],
22+
];

phpcs.xml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset name="pcsg-generated-ruleset">
3+
<description>Created with the PHP Coding Standard Generator. http://edorian.github.com/php-coding-standard-generator/
4+
</description>
5+
<rule ref="Generic.Classes.DuplicateClassName"/>
6+
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
7+
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
8+
<rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>
9+
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
10+
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
11+
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
12+
<rule ref="Generic.Commenting.Todo"/>
13+
<rule ref="Generic.Commenting.Fixme"/>
14+
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
15+
<rule ref="Generic.Files.ByteOrderMark"/>
16+
<rule ref="Generic.Files.LineEndings"/>
17+
<rule ref="Generic.Files.OneClassPerFile"/>
18+
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
19+
<rule ref="Generic.Functions.CallTimePassByReference"/>
20+
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
21+
<rule ref="Generic.NamingConventions.ConstructorName"/>
22+
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
23+
<rule ref="Generic.PHP.DeprecatedFunctions"/>
24+
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
25+
<rule ref="Generic.PHP.ForbiddenFunctions"/>
26+
<rule ref="Generic.PHP.LowerCaseConstant"/>
27+
<rule ref="Generic.PHP.NoSilencedErrors"/>
28+
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
29+
<rule ref="Generic.WhiteSpace.ScopeIndent"/>
30+
<rule ref="MySource.PHP.EvalObjectFactory"/>
31+
<rule ref="PSR1.Classes.ClassDeclaration"/>
32+
<rule ref="PSR1.Files.SideEffects"/>
33+
<rule ref="PSR2.Classes.ClassDeclaration"/>
34+
<rule ref="PSR2.Classes.PropertyDeclaration"/>
35+
<rule ref="PSR2.ControlStructures.ControlStructureSpacing"/>
36+
<rule ref="PSR2.ControlStructures.ElseIfDeclaration"/>
37+
<rule ref="PSR2.ControlStructures.SwitchDeclaration"/>
38+
<rule ref="PSR2.Methods.MethodDeclaration"/>
39+
<rule ref="PSR2.Namespaces.NamespaceDeclaration"/>
40+
<rule ref="PSR2.Namespaces.UseDeclaration"/>
41+
<rule ref="Squiz.PHP.DiscouragedFunctions"/>
42+
<rule ref="Squiz.PHP.EmbeddedPhp"/>
43+
<rule ref="Squiz.PHP.Eval"/>
44+
<rule ref="Squiz.PHP.GlobalKeyword"/>
45+
<rule ref="Squiz.PHP.InnerFunctions"/>
46+
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
47+
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
48+
<rule ref="Squiz.PHP.NonExecutableCode"/>
49+
<rule ref="Squiz.Scope.StaticThisUsage"/>
50+
<rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/>
51+
<rule ref="Zend.Files.ClosingTag"/>
52+
</ruleset>

phpunit.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit bootstrap="vendor/autoload.php"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
colors="true"
6+
verbose="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false">
12+
<testsuites>
13+
<testsuite name="Pre-commit Test Suite">
14+
<directory>tests</directory>
15+
</testsuite>
16+
</testsuites>
17+
<filter>
18+
<whitelist>
19+
<directory suffix=".php">src/</directory>
20+
</whitelist>
21+
</filter>
22+
</phpunit>

scrutinizer.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
filter:
2+
excluded_paths: [tests/*]
3+
4+
checks:
5+
php:
6+
remove_extra_empty_lines: true
7+
remove_php_closing_tag: true
8+
remove_trailing_whitespace: true
9+
fix_use_statements:
10+
remove_unused: true
11+
preserve_multiple: false
12+
preserve_blanklines: true
13+
order_alphabetically: true
14+
fix_php_opening_tag: true
15+
fix_linefeed: true
16+
fix_line_ending: true
17+
fix_identation_4spaces: true
18+
fix_doc_comments: true

0 commit comments

Comments
 (0)