Skip to content

Commit e6c8a03

Browse files
committed
Add phpcs-baseline command for convenience
1 parent 7d57c3f commit e6c8a03

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ to the root of the project and name it `phpcs.baseline.xml`.
2020
```bash
2121
php vendor/bin/phpcs src tests --report=\\DR\\CodeSnifferBaseline\\Reports\\Baseline --report-file=phpcs.baseline.xml --basepath=.
2222
```
23+
Or convenient wrapper for the above command:
24+
```bash
25+
php vendor/bin/phpcs-baseline src tests
26+
```
2327

2428
## Usage
2529
Use phpcs like you normally would. With `phpcs.baseline.xml` in the root of your project, the baseline extension will automatically read the config

bin/phpcs-baseline

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
declare(strict_types=1);
5+
6+
// set default arguments next to src locations
7+
$_SERVER['argc'] += 3;
8+
$_SERVER['argv'][] = '--report=\\DR\\CodeSnifferBaseline\\Reports\\Baseline';
9+
$_SERVER['argv'][] = '--report-file=phpcs.baseline.xml';
10+
$_SERVER['argv'][] = '--basepath=.';
11+
12+
// invoke phpcs. find it next to this file or in vendor/bin
13+
foreach([__DIR__ . '/phpcs', __DIR__ . '/../vendor/bin/phpcs'] as $path) {
14+
if (file_exists($path)) {
15+
require $path;
16+
return;
17+
}
18+
}
19+
20+
// failed to find phpcs
21+
fwrite(STDERR, 'Could not find `vendor/bin/phpcs`. Make sure to run `composer require squizlabs/php_codesniffer`' . PHP_EOL);
22+
exit(1);

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,8 @@
5757
"DR\\CodeSnifferBaseline\\Tests\\Unit\\": "tests/Unit/",
5858
"DR\\CodeSnifferBaseline\\Tests\\": "tests/"
5959
}
60-
}
60+
},
61+
"bin": [
62+
"bin/phpcs-baseline"
63+
]
6164
}

0 commit comments

Comments
 (0)