Skip to content

Commit 4512f99

Browse files
committed
Add composer scripts
1 parent 33e23ae commit 4512f99

File tree

2 files changed

+38
-15
lines changed

2 files changed

+38
-15
lines changed

CONTRIBUTING.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Composer.
2626

2727
The test suite may be executed with:
2828

29-
```
30-
$ vendor/bin/simple-phpunit
29+
```console
30+
$ composer run test
3131
```
3232

3333
The `phpunit.xml.dist` file is used as the default configuration file for the
@@ -47,7 +47,7 @@ By default, the `simple-phpunit` binary chooses the correct PHPUnit version for
4747
the PHP version you are running. To run tests against a specific PHPUnit
4848
version, use the `SYMFONY_PHPUNIT_VERSION` environment variable:
4949

50-
```
50+
```console
5151
$ SYMFONY_PHPUNIT_VERSION=7.5 vendor/bin/simple-phpunit
5252
```
5353

@@ -108,55 +108,63 @@ The following environment variables are used for [CSFLE testing](https://github.
108108
* `KMS_TLS_CA_FILE`
109109
* `KMS_TLS_CERTIFICATE_KEY_FILE`
110110

111-
## Checking coding standards
111+
## Code quality
112+
113+
Before submitting a pull request, please ensure that your code adheres to the
114+
coding standards and passes static analysis checks.
115+
116+
```console
117+
$ composer run checks
118+
```
119+
120+
### Coding standards
112121

113122
The library's code is checked using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer),
114123
which is installed as a development dependency by Composer. To check the code
115124
for style errors, run the `phpcs` binary:
116125

117-
118-
```
126+
```console
119127
$ vendor/bin/phpcs
120128
```
121129

122130
To automatically fix all fixable errors, use the `phpcbf` binary:
123131

124-
```
132+
```console
125133
$ vendor/bin/phpcbf
126134
```
127135

128-
## Running static analysis
136+
### Static analysis
129137

130138
The library uses [psalm](https://psalm.dev) to run static analysis on the code
131139
and ensure an additional level of type safety. New code is expected to adhere
132140
to level 1, with a baseline covering existing issues. To run static analysis
133141
checks, run the `psalm` binary:
134142

135-
```
143+
```console
136144
$ vendor/bin/psalm
137145
```
138146

139147
To remove fixed errors from the baseline, you can use the `update-baseline`
140148
command-line argument:
141149

142-
```
150+
```console
143151
$ vendor/bin/psalm --update-baseline
144152
```
145153

146154
Note that this will not add new errors to the baseline. New errors should be
147155
fixed instead of being added to the technical debt, but in case this isn't
148156
possible it can be added to the baseline using `set-baseline`:
149157

150-
```
158+
```console
151159
$ vendor/bin/psalm --set-baseline=psalm-baseline.xml
152160
```
153161

154-
## Automatic code refactoring
162+
### Refactoring
155163

156164
The library uses [rector](https://getrector.com/) to refactor the code for new features.
157165
To run automatic refactoring, use the `rector` command:
158166

159-
```
167+
```console
160168
$ vendor/bin/rector
161169
```
162170

@@ -178,7 +186,7 @@ repository:
178186
repository.
179187
* Create and activate Python 2.7 virtual environment if necessary.
180188

181-
```
189+
```console
182190
$ virtualenv -p python2.7 venv
183191
$ source venv/bin/activate
184192
```

composer.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"license": "Apache-2.0",
77
"authors": [
88
{ "name": "Andreas Braun", "email": "andreas.braun@mongodb.com" },
9-
{ "name": "Jeremy Mikola", "email": "jmikola@gmail.com" }
9+
{ "name": "Jeremy Mikola", "email": "jmikola@gmail.com" },
10+
{ "name": "Jérôme Tamarelle", "email": "jerome.tamarelle@mongodb.com" }
1011
],
1112
"require": {
1213
"php": "^7.2 || ^8.0",
@@ -33,6 +34,20 @@
3334
"psr-4": { "MongoDB\\Tests\\": "tests/" },
3435
"files": [ "tests/PHPUnit/Functions.php" ]
3536
},
37+
"scripts": {
38+
"checks": [
39+
"@check:cs",
40+
"@check:psalm",
41+
"@check:rector"
42+
],
43+
"check:cs": "phpcs",
44+
"check:psalm": "psalm",
45+
"check:rector": "rector --ansi --dry-run",
46+
"fix:cs": "phpcbf",
47+
"fix:psalm:baseline": "psalm --set-baseline=psalm-baseline.xml",
48+
"fix:rector": "rector process --ansi",
49+
"test": "simple-phpunit"
50+
},
3651
"extra": {
3752
"branch-alias": {
3853
"dev-master": "1.17.x-dev"

0 commit comments

Comments
 (0)