<?php
/**
 * Scan coverage.
 *
 * @package LocalGuardScanner
 */

namespace LocalGuardScanner\Domain\Scan;

/**
 * Tracks inspected and omitted objects with reasons.
 */
final class Coverage {
	/** @var int */
	private $inspected = 0;
	/** @var array<string,int> */
	private $omitted = array();

	/**
	 * @param int $count Number inspected.
	 * @return void
	 */
	public function add_inspected( $count = 1 ) {
		$this->inspected += max( 0, (int) $count );
	}

	/**
	 * @param string $reason Omission reason.
	 * @param int    $count  Number omitted.
	 * @return void
	 */
	public function add_omitted( $reason, $count = 1 ) {
		if ( ! isset( $this->omitted[ $reason ] ) ) {
			$this->omitted[ $reason ] = 0;
		}
		$this->omitted[ $reason ] += max( 0, (int) $count );
	}

	/**
	 * @return bool
	 */
	public function is_complete() {
		return 0 === array_sum( $this->omitted );
	}

	/**
	 * @return array<string,mixed>
	 */
	public function to_array() {
		return array(
			'inspected' => $this->inspected,
			'omitted'   => $this->omitted,
			'complete'  => $this->is_complete(),
		);
	}
}
