fisharebest / badge
Generate SVG badges from PHP CI results without an external service
1.0.3
2026-11-19 13:13 UTC
Requires
- php: ^8.3
- composer-runtime-api: ^2.2
- ext-ctype: *
- ext-mbstring: *
- ext-simplexml: *
- nette/neon: ^3.0
Requires (Dev)
- infection/infection: ^0.35
- phpstan/phpstan: ^2.2
- phpunit/phpunit: ^12.5
- squizlabs/php_codesniffer: ^4.0
- vimeo/psalm: ^7.11
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Generate SVG badges for your CI status locally - without external services or network requests.
Update them automatically, each time you run your CI.
Installation
composer require --dev fisharebest/badge
CLI usage
vendor/bin/badge --help
vendor/bin/badge filename.svg [options]
| Option | Default | Description |
|---|---|---|
--label=TEXT | status | Badge label |
--value=TEXT | unknown | Badge value |
--colour=COLOUR | unknown | pass, fail, warning, info, unknown, CSS colour name or #RRGGBB |
--infection=PATH | None | Read Infection JSON (stats.msi) |
--licence[=PATH] | composer.json | Read Composer's license code with a Licence label |
--clover-coverage=PATH | None | Read statement coverage from Clover XML |
--junit=PATH | None | Read passed, failed and skipped test counts from JUnit XML |
--psalm[=PATH] | Auto-discover | Read Psalm's configured error level |
--phpstan[=PATH] | Auto-discover | Read PHPStan's configured level |
--help | Show help without writing a badge |
NOTE: US spellings of licence/license, grey/gray and colour/color are also accepted.
Examples
| Command/options | Badge |
|---|---|
badge example1.svg | |
badge example2.svg --label=tests --value=passing --colour=pass | |
badge example3.svg --label=tests --value=failing --colour=fail | |
badge example4.svg --label=build --value=unstable --colour=warning | |
badge example5.svg --label=release --value=1.0 --colour=info | |
badge example6.svg --label=CSS --value=green --colour=green | |
badge example7.svg --label=CSS --value=rebeccapurple --colour=rebeccapurple | |
badge example8.svg --label=custom --value=hex --colour='#ff69b4' | |
badge example9.svg --label=CSS --value=lightgrey --colour=lightgrey | |
badge example10.svg --psalm | |
badge example11.svg --phpstan | |
badge example12.svg --infection=build/infection.json | |
badge example13.svg --clover-coverage=build/coverage.xml | |
badge example14.svg --junit=build/junit.xml | |
badge example15.svg --licence | |
badge example16.svg --label=Release --value=1.0 --colour='#67ac09' |
CI usage
Initialise each badge as unknown before running checks, then update it only when its check succeeds.
vendor/bin/badge phpcs.svg --label=CodeStyle
vendor/bin/badge phpunit.svg --label=PHPUnit
vendor/bin/badge coverage.svg --label="Test coverage"
vendor/bin/badge infection.svg --label=Infection
vendor/bin/phpcs
vendor/bin/badge phpcs.svg --label=CodeStyle --value=success --colour=pass
vendor/bin/phpunit --coverage-clover build/coverage.xml --log-junit build/junit.xml
vendor/bin/badge phpunit.svg --junit=build/junit.xml --label=PHPUnit
vendor/bin/badge coverage.svg --clover-coverage=build/coverage.xml
vendor/bin/infection
vendor/bin/badge infection.svg --infection=build/mutations.json
PHP API
use Fisharebest\Badge\Badge;
use Fisharebest\Badge\Colour;
$svg = Badge::render(label: 'Release', value: '1.2.3', colour: new Colour(colour: 'pass'));
file_put_contents('release.svg', $svg);