Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,39 +75,39 @@ jobs:
- name: "Install dependencies"
run: "composer install --no-interaction --prefer-dist"

- run: "mkdir -p .phpunit.cache"
- run: "mkdir -p var/.phpunit.cache"

- name: "Run PHPUnit (console)"
run: "vendor/bin/phpunit --configuration phpunit.xml.dist --colors=always"

- name: "Generate coverage summary"
if: ${{ ! cancelled() }}
run: |
echo '```' > .phpunit.cache/coverage.txt
echo '```' > var/.phpunit.cache/coverage.txt
vendor/bin/phpunit \
--configuration phpunit.xml.dist \
--colors=never \
--coverage-text >> .phpunit.cache/coverage.txt
echo '```' >> .phpunit.cache/coverage.txt
--coverage-text >> var/.phpunit.cache/coverage.txt
echo '```' >> var/.phpunit.cache/coverage.txt

- name: "Report test results"
uses: "mikepenz/action-junit-report@v6"
if: ${{ ! cancelled() }}
with:
report_paths: ".phpunit.cache/junit.xml"
report_paths: "var/.phpunit.cache/junit.xml"
annotate_only: true

- name: "Post coverage summary"
if: ${{ ! cancelled() }}
run: 'cat .phpunit.cache/coverage.txt >> "$GITHUB_STEP_SUMMARY"'
run: 'cat var/.phpunit.cache/coverage.txt >> "$GITHUB_STEP_SUMMARY"'

- name: "Upload coverage report"
uses: "actions/upload-artifact@v7"
if: ${{ ! cancelled() }}
with:
name: "coverage-report"
path: |
.phpunit.cache/coverage-html
.phpunit.cache/coverage.xml
.phpunit.cache/junit.xml
var/.phpunit.cache/coverage-html
var/.phpunit.cache/coverage.xml
var/.phpunit.cache/junit.xml
retention-days: 7
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/vendor/
/.phpunit.cache/
/.phpstan.cache/
/composer.lock
/.phpcs-cache.json

# ------------------------------------------------------------------------------
# Editor configuration directories
# ------------------------------------------------------------------------------
/.idea/
/.vscode/
/.zed/
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@ Implement `DocbookCS\Sniff\SniffInterface` (or extend `AbstractSniff`):
namespace Acme\DocbookSniffs;

use DocbookCS\Sniff\AbstractSniff;
use DocbookCS\Source\File;

final class MySniff extends AbstractSniff
{
public function getCode(): string
public static function getCode(): string
{
return 'Acme.MySniff';
}

public function process(\DOMDocument $document, string $content, string $filePath): array
public function process(\DOMDocument $document, File $file): array
{
$violations = [];
// ... inspect $document, add violations via $this->createViolation(...)
Expand All @@ -63,6 +64,27 @@ Register it in your config:
<sniff class="Acme\DocbookSniffs\MySniff" />
```

## CLI Scope

By default, DocbookCS checks the current Git diff from its upstream branch point
through the working tree. Alternatively, a unified diff can be piped or file and
directory paths passed. The inspection scope is limited to the given diff or the
full contents of the given file paths.

XML references are expanded by default, but violations and fixes remain limited
to the given scope. With `--wide`, every file, inferred from paths or diff, as
a whole will be checked and referenced `SYSTEM` XML files recursively included
in violation reports and fixing.

| Input | `--wide` | Full File(s) | References |
|------------|---------:|-------------:|-----------:|
| none | no | no | no |
| none | yes | yes | yes |
| path | no | yes | no |
| path | yes | yes | yes |
| piped diff | no | no | no |
| piped diff | yes | yes | yes |

## License

Apache 2.0
11 changes: 9 additions & 2 deletions bin/docbook-cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use DocbookCS\Application;

foreach ($candidates as $file) {
if (!is_file($file)) {
continue;
continue;
}

require $file;
Expand All @@ -25,4 +25,11 @@ use DocbookCS\Application;
exit(2);
})();

new Application($argv ?? [])->run();
try {
$application = Application::fromGlobals($argv ?? []);
} catch (\RuntimeException $e) {
fwrite(STDERR, $e->getMessage() . PHP_EOL);
exit(2);
}

exit($application->run());
13 changes: 12 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"phpunit/php-code-coverage": "^14.1",
"squizlabs/php_codesniffer": "^4.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0"
"phpstan/phpstan-phpunit": "^2.0",
"shipmonk/dead-code-detector": "^1.3"
},
"autoload": {
"psr-4": {
Expand All @@ -28,6 +29,16 @@
"DocbookCS\\Tests\\": "tests/"
}
},
"scripts": {
"test": "@php -r \"exit(extension_loaded('xdebug') || extension_loaded('pcov') ? 0 : 1);\" && XDEBUG_MODE=coverage ./vendor/bin/phpunit --configuration phpunit.xml.dist || ./vendor/bin/phpunit --configuration phpunit.xml.dist --no-coverage",
"phpstan": "./vendor/bin/phpstan analyse --no-progress",
"phpcs": "./vendor/bin/phpcs",
"quality": [
"@phpcs",
"@phpstan",
"@test"
]
},
"authors": [
{
"name": "Jordi Kroon",
Expand Down
5 changes: 4 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
<ruleset name="PHP_CodeSniffer" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/refs/heads/master/phpcs.xsd">
<description>DocbookCS Coding Standard</description>
<rule ref="PSR12"/>
<rule ref="PSR2.Methods.FunctionCallSignature.SpaceBeforeCloseBracket">
<exclude-pattern type="relative">tests/*</exclude-pattern>
</rule>

<arg name="cache" value=".phpcs-cache.json"/>
<arg name="cache" value="var/.phpcs-cache.json"/>
<arg name="basepath" value="./"/>
<arg name="colors"/>
<arg value="p"/>
Expand Down
4 changes: 3 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/shipmonk/dead-code-detector/rules.neon

parameters:
level: max

paths:
- bin/
- src/
- tests/

tmpDir: .phpstan.cache
tmpDir: var/.phpstan.cache

treatPhpDocTypesAsCertain: false

Expand Down
14 changes: 10 additions & 4 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
cacheDirectory="var/.phpunit.cache"
executionOrder="depends,defects"
requireCoverageMetadata="true"
beStrictAboutCoverageMetadata="true"
Expand All @@ -18,6 +18,12 @@
<testsuite name="unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="integration">
<directory>tests/Integration</directory>
</testsuite>
<testsuite name="feature">
<directory>tests/Feature</directory>
</testsuite>
</testsuites>

<source restrictNotices="true" restrictWarnings="true">
Expand All @@ -28,13 +34,13 @@

<coverage>
<report>
<html outputDirectory=".phpunit.cache/coverage-html" />
<clover outputFile=".phpunit.cache/coverage.xml" />
<html outputDirectory="var/.phpunit.cache/coverage-html" />
<clover outputFile="var/.phpunit.cache/coverage.xml" />
<text outputFile="php://stdout" showOnlySummary="true" />
</report>
</coverage>

<logging>
<junit outputFile=".phpunit.cache/junit.xml" />
<junit outputFile="var/.phpunit.cache/junit.xml" />
</logging>
</phpunit>
Loading