comparison vendor/phpunit/php-code-coverage/src/Util.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
1 <?php
2 /*
3 * This file is part of the php-code-coverage 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 namespace SebastianBergmann\CodeCoverage;
12
13 /**
14 * Utility methods.
15 */
16 class Util
17 {
18 /**
19 * @param float $a
20 * @param float $b
21 * @param bool $asString
22 * @param bool $fixedWidth
23 *
24 * @return float|int|string
25 */
26 public static function percent($a, $b, $asString = false, $fixedWidth = false)
27 {
28 if ($asString && $b == 0) {
29 return '';
30 }
31
32 $percent = 100;
33
34 if ($b > 0) {
35 $percent = ($a / $b) * 100;
36 }
37
38 if ($asString) {
39 $format = $fixedWidth ? '%6.2F%%' : '%01.2F%%';
40
41 return \sprintf($format, $percent);
42 }
43
44 return $percent;
45 }
46 }