Skip to content

Commit a7940e0

Browse files
committed
Print offending files with php-lint
Fixes #18 and #22. Includes some minor `README.md` cleanup.
1 parent f9f30f8 commit a7940e0

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Pre-commit scripts appropriate for *any* PHP project. These hooks are made as cu
44

55
# Setup
66

7-
See (Adding pre-commit plugins to your project)[https://pre-commit.com/#adding-pre-commit-plugins-to-your-project]
7+
See [Adding pre-commit plugins to your project](https://pre-commit.com/#adding-pre-commit-plugins-to-your-project).
88

99
# Supported Hooks
1010

@@ -32,7 +32,6 @@ A systems hook that just runs `php -l` against stage files that have the `.php`
3232

3333
## php-unit
3434

35-
3635
```yaml
3736
- repo: https://github.com/digitalpulp/pre-commit-php.git
3837
rev: 1.4.0
@@ -74,6 +73,7 @@ The `args` property in your hook declaration can be used for pass any valid PHP
7473
files: \.(php)$
7574
args: [--standard=PSR1 -p]
7675
```
76+
7777
Similar pattern as the php-cs hook. A bash script that will run the appropriate [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer) executable and will try to fix errors if it can using phpcbf.
7878

7979
It will assume that there is a valid PHP Code Beautifier and Fixer executable at these locations, `vendor/bin/phpcbf`, `phpcbf` or `php phpcbf.phar` (in that exact order).
@@ -94,6 +94,7 @@ If you have multiple standards or a comma in your `args` property, escape the co
9494
To install PHP Codesniffer (phpcs & phpcbf), follow the [recommended steps here](https://github.com/squizlabs/PHP_CodeSniffer#installation).
9595

9696
## php-cs-fixer
97+
9798
```yaml
9899
-- repo: https://github.com/digitalpulp/pre-commit-php.git
99100
rev: 1.4.0
@@ -102,15 +103,14 @@ To install PHP Codesniffer (phpcs & phpcbf), follow the [recommended steps here]
102103
files: \.(php)$
103104
args: [--level=PSR2]
104105
```
106+
105107
Similar pattern as the php-cs hook. A bash script that will run the appropriate [PHP Coding Standards Fixer](http://cs.sensiolabs.org/) executable and to fix errors according to the configuration. It accepts all of the args from the `php-cs-fixer` command, in particular the `--level`, `--config`, and `--config-file` options.
106108

107109
The tool will fail a build when it has made changes to the staged files. This allows a developer to do a `git diff` and examine the changes that it has made. Remember that you may omit this if needed with a `SKIP=php-cs-fixer git commit`.
108110

109111
## php-stan
110112

111-
Adds the (PHPStan)[https://phpstan.org/] tool.
112-
113-
113+
Adds the [PHPStan](https://phpstan.org/) tool.
114114

115115
```yaml
116116
-- repo: https://github.com/digitalpulp/pre-commit-php.git

pre_commit_hooks/php-lint.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ while getopts ":s:" optname
5454
esac
5555
done
5656

57+
shift "${arg_lookup_start}"
58+
5759
# Loop through the list of paths to run php lint against
5860
parse_error_count=0
59-
for path in ${*:$arg_lookup_start}
61+
for path in "${@}"
6062
do
61-
php -l "$path" 1> /dev/null
62-
if [ $? -ne 0 ]; then
63+
php -l "$path" | grep -Ev '^No syntax errors detected in '
64+
if [ ${PIPESTATUS[0]} -ne 0 ]; then
6365
# echo "PHP Parse errors were detected" >&2
6466
parse_error_count=$[$parse_error_count +1]
6567
php_errors_found=true

0 commit comments

Comments
 (0)