PcovDriver.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php declare(strict_types=1);
  2. /*
  3. * This file is part of phpunit/php-code-coverage.
  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\Driver;
  11. use const pcov\inclusive;
  12. use function array_intersect;
  13. use function extension_loaded;
  14. use function pcov\clear;
  15. use function pcov\collect;
  16. use function pcov\start;
  17. use function pcov\stop;
  18. use function pcov\waiting;
  19. use function phpversion;
  20. use SebastianBergmann\CodeCoverage\Filter;
  21. use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
  22. /**
  23. * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
  24. */
  25. final class PcovDriver extends Driver
  26. {
  27. /**
  28. * @var Filter
  29. */
  30. private $filter;
  31. /**
  32. * @throws PcovNotAvailableException
  33. */
  34. public function __construct(Filter $filter)
  35. {
  36. if (!extension_loaded('pcov')) {
  37. throw new PcovNotAvailableException;
  38. }
  39. $this->filter = $filter;
  40. }
  41. public function start(): void
  42. {
  43. start();
  44. }
  45. public function stop(): RawCodeCoverageData
  46. {
  47. stop();
  48. $filesToCollectCoverageFor = waiting();
  49. $collected = [];
  50. if ($filesToCollectCoverageFor) {
  51. if (!$this->filter->isEmpty()) {
  52. $filesToCollectCoverageFor = array_intersect($filesToCollectCoverageFor, $this->filter->files());
  53. }
  54. $collected = collect(inclusive, $filesToCollectCoverageFor);
  55. clear();
  56. }
  57. return RawCodeCoverageData::fromXdebugWithoutPathCoverage($collected);
  58. }
  59. public function nameAndVersion(): string
  60. {
  61. return 'PCOV ' . phpversion('pcov');
  62. }
  63. }