Skip to content
Permalink
Browse files

Collector: refactoring

  • Loading branch information...
dg authored and milo committed Mar 9, 2019
1 parent a49594a commit 3409b622ac0a25d18378d86e6faf584cee67a41d
Showing with 27 additions and 23 deletions.
  1. +27 βˆ’23 src/CodeCoverage/Collector.php
@@ -24,7 +24,7 @@ class Collector
private static $file;
/** @var string */
private static $collector;
private static $engine;
public static function detectEngines(): array
@@ -51,29 +51,15 @@ public static function start(string $file, string $engine): void
{
if (self::isStarted()) {
throw new \LogicException('Code coverage collector has been already started.');
}
self::$file = fopen($file, 'c+');
switch ($engine) {
case self::ENGINE_PCOV:
\pcov\start();
self::$collector = 'collectPCOV';
break;
case self::ENGINE_PHPDBG:
phpdbg_start_oplog();
self::$collector = 'collectPhpDbg';
break;
case self::ENGINE_XDEBUG:
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
self::$collector = 'collectXdebug';
break;
default:
throw new \LogicException("Code coverage engine '$engine' is not supported.");
} elseif (!in_array($engine, self::detectEngines(), true)) {
throw new \LogicException("Code coverage engine '$engine' is not supported.");
}
self::$file = fopen($file, 'c+');
self::$engine = $engine;
self::{'start' . $engine}();
register_shutdown_function(function (): void {
register_shutdown_function([__CLASS__, 'save']);
});
@@ -85,7 +71,7 @@ public static function start(string $file, string $engine): void
*/
public static function flush(): void
{
if (self::isStarted() && self::$collector === 'collectPhpDbg') {
if (self::isStarted() && self::$engine === self::ENGINE_PHPDBG) {
self::save();
}
}
@@ -101,7 +87,7 @@ public static function save(): void
throw new \LogicException('Code coverage collector has not been started.');
}
[$positive, $negative] = [__CLASS__, self::$collector]();
[$positive, $negative] = self::{'collect' . self::$engine}();
flock(self::$file, LOCK_EX);
fseek(self::$file, 0);
@@ -116,6 +102,12 @@ public static function save(): void
}
private static function startPCOV(): void
{
\pcov\start();
}
/**
* Collects information about code coverage.
*/
@@ -143,6 +135,12 @@ private static function collectPCOV(): array
}
private static function startXdebug(): void
{
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
}
/**
* Collects information about code coverage.
*/
@@ -168,6 +166,12 @@ private static function collectXdebug(): array
}
private static function startPhpDbg(): void
{
phpdbg_start_oplog();
}
/**
* Collects information about code coverage.
*/

0 comments on commit 3409b62

Please sign in to comment.
You can’t perform that action at this time.