Search by

Generate SVG badges from PHP CI results without an external service

1.0.3 2026-11-19 13:13 UTC

This package is auto-updated.

Last update: 2026-11-19 14:47:56 UTC


README

CodeStyle PHPStan Psalm PHPUnit Test coverage Infection Licence

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]
OptionDefaultDescription
--label=TEXTstatusBadge label
--value=TEXTunknownBadge value
--colour=COLOURunknownpass, fail, warning, info, unknown, CSS colour name or #RRGGBB
--infection=PATHNoneRead Infection JSON (stats.msi)
--licence[=PATH]composer.jsonRead Composer's license code with a Licence label
--clover-coverage=PATHNoneRead statement coverage from Clover XML
--junit=PATHNoneRead passed, failed and skipped test counts from JUnit XML
--psalm[=PATH]Auto-discoverRead Psalm's configured error level
--phpstan[=PATH]Auto-discoverRead PHPStan's configured level
--helpShow help without writing a badge

NOTE: US spellings of licence/license, grey/gray and colour/color are also accepted.

Examples

Command/optionsBadge
badge example1.svgDefault unknown status
badge example2.svg --label=tests --value=passing --colour=passSemantic pass
badge example3.svg --label=tests --value=failing --colour=failSemantic fail
badge example4.svg --label=build --value=unstable --colour=warningSemantic warning
badge example5.svg --label=release --value=1.0 --colour=infoSemantic info
badge example6.svg --label=CSS --value=green --colour=greenCSS green
badge example7.svg --label=CSS --value=rebeccapurple --colour=rebeccapurpleCSS rebeccapurple
badge example8.svg --label=custom --value=hex --colour='#ff69b4'Custom hex colour
badge example9.svg --label=CSS --value=lightgrey --colour=lightgreyCSS lightgrey
badge example10.svg --psalmPsalm configured level
badge example11.svg --phpstanPHPStan configured level
badge example12.svg --infection=build/infection.jsonInfection mutation score
badge example13.svg --clover-coverage=build/coverage.xmlClover statement coverage
badge example14.svg --junit=build/junit.xmlJUnit test results
badge example15.svg --licenceLicence from the default Composer file
badge example16.svg --label=Release --value=1.0 --colour='#67ac09'Release with custom hex colour

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);