Mercurial > hg > isophonics-drupal-site
comparison vendor/phpunit/php-code-coverage/src/CodeCoverage/Util.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 /* | |
3 * This file is part of the PHP_CodeCoverage package. | |
4 * | |
5 * (c) Sebastian Bergmann <sebastian@phpunit.de> | |
6 * | |
7 * For the full copyright and license information, please view the LICENSE | |
8 * file that was distributed with this source code. | |
9 */ | |
10 | |
11 /** | |
12 * Utility methods. | |
13 * | |
14 * @since Class available since Release 1.0.0 | |
15 */ | |
16 class PHP_CodeCoverage_Util | |
17 { | |
18 /** | |
19 * @param float $a | |
20 * @param float $b | |
21 * @return float ($a / $b) * 100 | |
22 */ | |
23 public static function percent($a, $b, $asString = false, $fixedWidth = false) | |
24 { | |
25 if ($asString && $b == 0) { | |
26 return ''; | |
27 } | |
28 | |
29 if ($b > 0) { | |
30 $percent = ($a / $b) * 100; | |
31 } else { | |
32 $percent = 100; | |
33 } | |
34 | |
35 if ($asString) { | |
36 if ($fixedWidth) { | |
37 return sprintf('%6.2F%%', $percent); | |
38 } | |
39 | |
40 return sprintf('%01.2F%%', $percent); | |
41 } else { | |
42 return $percent; | |
43 } | |
44 } | |
45 } |