PHP.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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\Report;
  11. use SebastianBergmann\CodeCoverage\CodeCoverage;
  12. /**
  13. * Uses var_export() to write a SebastianBergmann\CodeCoverage\CodeCoverage object to a file.
  14. */
  15. class PHP
  16. {
  17. /**
  18. * @param CodeCoverage $coverage
  19. * @param string $target
  20. *
  21. * @return string
  22. */
  23. public function process(CodeCoverage $coverage, $target = null)
  24. {
  25. $filter = $coverage->filter();
  26. $output = sprintf(
  27. '<?php
  28. $coverage = new SebastianBergmann\CodeCoverage\CodeCoverage;
  29. $coverage->setData(%s);
  30. $coverage->setTests(%s);
  31. $filter = $coverage->filter();
  32. $filter->setWhitelistedFiles(%s);
  33. return $coverage;',
  34. var_export($coverage->getData(true), 1),
  35. var_export($coverage->getTests(), 1),
  36. var_export($filter->getWhitelistedFiles(), 1)
  37. );
  38. if ($target !== null) {
  39. return file_put_contents($target, $output);
  40. } else {
  41. return $output;
  42. }
  43. }
  44. }