Няма описание

Util.php 1013B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. namespace SebastianBergmann\CodeCoverage;
  11. /**
  12. * Utility methods.
  13. */
  14. class Util
  15. {
  16. /**
  17. * @param float $a
  18. * @param float $b
  19. * @param bool $asString
  20. * @param bool $fixedWidth
  21. *
  22. * @return float|int|string
  23. */
  24. public static function percent($a, $b, $asString = false, $fixedWidth = false)
  25. {
  26. if ($asString && $b == 0) {
  27. return '';
  28. }
  29. if ($b > 0) {
  30. $percent = ($a / $b) * 100;
  31. } else {
  32. $percent = 100;
  33. }
  34. if ($asString) {
  35. if ($fixedWidth) {
  36. return sprintf('%6.2F%%', $percent);
  37. }
  38. return sprintf('%01.2F%%', $percent);
  39. } else {
  40. return $percent;
  41. }
  42. }
  43. }