PHP Classes

PHP Create Badges: Create badges for project coverage

Recommend this page to a friend!
  Info   View files Example   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog (1)    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 38 This week: 1All time: 10,874 This week: 560Up
Version License PHP version Categories
badger 1.0MIT/X Consortium ...5PHP 5, Graphics, Project Management
Description 

Author

This package can create badges for project coverage.

It can read a code coverage report in Clover XML format to extract the coverage value.

The package can generage a JSON definition for a badge from the coverage value and sends a HTTP request to the Shields.io API to generate the badge for the project.

Innovation Award
PHP Programming Innovation award nominee
May 2021
Number 5
Badges are a nice way to show certain metrics about the packages in a graphical way.

This package can generate badges using the Shields.io service. The badges can show the level of test coverage of a package using coverage tools that generate reports in Clover XML format.

Manuel Lemos
Picture of Yousaf Syed
  Performance   Level  
Name: Yousaf Syed <contact>
Classes: 6 packages by
Country: Pakistan Pakistan
Age: 33
All time rank: 232631 in Pakistan Pakistan
Week rank: 411 Up9 in Pakistan Pakistan Up
Innovation award
Innovation award
Nominee: 4x

Winner: 1x

Example

#!/usr/bin/env php
<?php declare(strict_types=1);

if (!
ini_get('date.timezone')) {
   
ini_set('date.timezone', 'UTC');
}

foreach (array(
__DIR__ . '/../../autoload.php', __DIR__ . '/../vendor/autoload.php', __DIR__ . '/vendor/autoload.php') as $file) {
    if (
file_exists($file)) {
       
define('BADGER_COMPOSER_INSTALL', $file);

        break;
    }
}

unset(
$file);

if (!
defined('BADGER_COMPOSER_INSTALL')) {
   
fwrite(
       
STDERR,
       
'You need to set up the project dependencies using Composer:' . PHP_EOL . PHP_EOL .
       
' composer install' . PHP_EOL . PHP_EOL .
       
'You can learn all about Composer on https://getcomposer.org/.' . PHP_EOL
   
);

    die(
1);
}

require
BADGER_COMPOSER_INSTALL;

use
Symfony\Component\Console\Application;
use
Badger\Commands\CoverageBadge;

$application = new Application();

$application->add(new CoverageBadge());

$application->run();


Details

badger

Badger is a small CLI utility for generating a shields.io compatible JSON from clover.xml report and uploading it to a badger-server, see github.com/crowphp/badger-server to read more about the server.

Installing badger from composer

composer require --dev crowphp/badger:dev-master

Notice: At the moment the badger is under development use it with caution.

Usage

Help Document

$ php vendor/bin/badger --help
Console Tool

Usage:
  command [options] [arguments]

Options:
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Available commands:
  help             Displays help for a command
  list             Lists commands
 upload
  upload:coverage  Creates json for coverage badge shields.io and uploads it to a given badger server

Create badge schema on a badger server for a given branch

$ php upload:coverage <server> <branch> <secret-key>

Description:
  Creates json for coverage badge shields.io and uploads it to a given badger server

Usage:
  upload:coverage <server> <branch> <secret-key>

Arguments:
  server                URL for Badger Server
  branch                The branch name for the coverage
  secret-key            Secret api key for badger server

Options:
  -h, --help            Display help for the given command. When no command is given display help for the list command
  -q, --quiet           Do not output any message
  -V, --version         Display this application version
      --ansi            Force ANSI output
      --no-ansi         Disable ANSI output
  -n, --no-interaction  Do not ask any interactive question
  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug


  Files folder image Files  
File Role Description
Files folder imagesrc (1 directory)
Accessible without login Plain text file badger Example Example script
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  src  
File Role Description
Files folder imageBadger (1 directory)

  Files folder image Files  /  src  /  Badger  
File Role Description
Files folder imageCommands (1 file)

  Files folder image Files  /  src  /  Badger  /  Commands  
File Role Description
  Plain text file CoverageBadge.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:38
This week:1
All time:10,874
This week:560Up