Skip to content

Commit 8f20636

Browse files
authored
feat(ci): add scripts to quickly check and fix code styles (#8469)
1 parent 4677d86 commit 8f20636

2 files changed

Lines changed: 37 additions & 4 deletions

File tree

CONTRIBUTING.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,35 @@ Please note that because Datastore and Firestore cannot be active in the same pr
106106
$ export GOOGLE_CLOUD_PHP_FIRESTORE_TESTS_KEY_PATH='/path/to/keyfile.json'
107107
```
108108

109-
## Coding Style
109+
### Coding Style
110110

111111
Please follow the established coding style in the library. Google Cloud PHP follows the [PSR-2](https://www.php-fig.org/psr/psr-2/) Coding Style.
112+
This is enforced using both [PHP CS Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer) and [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer).
112113

113-
You can check your code against these rules by running PHPCS with the proper ruleset, like this:
114+
You can run both of these checks using the `style-check` composer script:
114115

115116
```sh
116-
$ composer style
117+
$ composer style-check
117118
```
118119

120+
If these changes look correct, you can automatically fix the issues by running this command:
121+
122+
```sh
123+
$ composer style-fix
124+
```
125+
126+
### Static Analysis
127+
128+
Run PHPStan for static analysis with the following command.
129+
130+
```sh
131+
$ composer phpstan
132+
```
133+
134+
Any errors here will have to be fixed manually.
135+
136+
**NOTE**: PHP CS Fixer does not check for or fix line lengths or trailing whitespace, which is the primary reason we use both libraries.
137+
119138
## Owlbot
120139

121140
This repository is using OwlBot for copying code from the generated library in

composer.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22
"name": "google/cloud",
33
"type": "library",
44
"description": "Google Cloud Client Library",
5+
"scripts": {
6+
"style-check": [
7+
"vendor/bin/php-tools cs-fixer googleapis/google-cloud-php --ref $(git rev-parse --abbrev-ref HEAD)",
8+
"vendor/bin/phpcs --standard=phpcs-ruleset.xml -p"
9+
],
10+
"style-fix": [
11+
"vendor/bin/php-tools cs-fixer googleapis/google-cloud-php --ref $(git rev-parse --abbrev-ref HEAD) --flags \"\"",
12+
"vendor/bin/phpcbf --standard=phpcs-ruleset.xml -p"
13+
],
14+
"phpstan": [
15+
"dev/sh/static-analysis"
16+
]
17+
},
518
"keywords": [
619
"google apis client",
720
"google api client",
@@ -64,7 +77,8 @@
6477
"phpspec/prophecy-phpunit": "^2.1",
6578
"kreait/firebase-php": "^6.9",
6679
"psr/log": "^2.0||^3.0",
67-
"dg/bypass-finals": "^1.7"
80+
"dg/bypass-finals": "^1.7",
81+
"squizlabs/php_codesniffer": "3.*"
6882
},
6983
"replace": {
7084
"google/access-context-manager": "1.0.4",

0 commit comments

Comments
 (0)