diff --git a/src/Plugins/Tia.php b/src/Plugins/Tia.php index 02dd0887..156247d8 100644 --- a/src/Plugins/Tia.php +++ b/src/Plugins/Tia.php @@ -713,6 +713,6 @@ final class Tia implements AddsOutput, AfterEachable, BeforeEachable, HandlesArg return false; } - return property_exists($coverage, 'coverage') && $coverage->coverage === true; + return $coverage->coverage === true; } } diff --git a/src/Plugins/Tia/Fingerprint.php b/src/Plugins/Tia/Fingerprint.php index 39561468..a978f8d8 100644 --- a/src/Plugins/Tia/Fingerprint.php +++ b/src/Plugins/Tia/Fingerprint.php @@ -19,7 +19,7 @@ final readonly class Fingerprint private const int SCHEMA_VERSION = 2; /** - * @param non-empty-string $projectRoot + * @return array */ public static function compute(string $projectRoot): array { diff --git a/src/Plugins/Tia/Graph.php b/src/Plugins/Tia/Graph.php index 08d46e08..c55d3abf 100644 --- a/src/Plugins/Tia/Graph.php +++ b/src/Plugins/Tia/Graph.php @@ -166,11 +166,17 @@ final class Graph return array_keys($this->edges); } + /** + * @param array $fingerprint + */ public function setFingerprint(array $fingerprint): void { $this->fingerprint = $fingerprint; } + /** + * @return array + */ public function fingerprint(): array { return $this->fingerprint; diff --git a/src/Plugins/Tia/Recorder.php b/src/Plugins/Tia/Recorder.php index bdb7909c..48a88cae 100644 --- a/src/Plugins/Tia/Recorder.php +++ b/src/Plugins/Tia/Recorder.php @@ -69,12 +69,20 @@ final class Recorder $this->driver = 'pcov'; $this->driverAvailable = true; } elseif (function_exists('xdebug_start_code_coverage')) { - // Probe: Xdebug silently emits a warning and refuses to start - // when not in coverage mode. Suppress + check for mode errors. - $ok = @\xdebug_start_code_coverage(); + // Xdebug is loaded. Probe whether coverage mode is active by + // attempting a start — it emits E_WARNING when the mode is off. + // We capture the warning via a temporary error handler. + $probeOk = true; + set_error_handler(static function () use (&$probeOk): bool { + $probeOk = false; - if ($ok === null || $ok) { - @\xdebug_stop_code_coverage(false); + return true; + }); + \xdebug_start_code_coverage(); + restore_error_handler(); + + if ($probeOk) { + \xdebug_stop_code_coverage(false); $this->driver = 'xdebug'; $this->driverAvailable = true; } @@ -195,31 +203,23 @@ final class Recorder return null; } - try { - $reflection = new ReflectionClass($className); - } catch (ReflectionException) { - return null; - } + $reflection = new ReflectionClass($className); if ($reflection->hasProperty('__filename')) { - try { - $property = $reflection->getProperty('__filename'); + $property = $reflection->getProperty('__filename'); - if ($property->isStatic()) { - $value = $property->getValue(); + if ($property->isStatic()) { + $value = $property->getValue(); - if (is_string($value) && $value !== '') { - return $value; - } + if (is_string($value)) { + return $value; } - } catch (ReflectionException) { - // fall through to getFileName() } } $file = $reflection->getFileName(); - return $file !== false && $file !== '' ? $file : null; + return is_string($file) ? $file : null; } /** diff --git a/src/Plugins/Tia/State.php b/src/Plugins/Tia/State.php index 9fee2dbd..48b829e7 100644 --- a/src/Plugins/Tia/State.php +++ b/src/Plugins/Tia/State.php @@ -66,6 +66,7 @@ final class State * Turns on replay mode with the given graph + affected set. * * @param array $affectedFiles + * @param array $previousDefects */ public function activate(string $projectRoot, Graph $graph, array $affectedFiles, array $previousDefects): void {