<?php

/**
 * Context passed to static safety rules during analysis.
 *
 * @package LolaCore\Builder\Safety
 * @license GPL-2.0-or-later
 */

declare(strict_types=1);

namespace LolaCore\Builder\Safety;

if (! defined('ABSPATH')) {
	exit;
}

/**
 * Immutable analysis context for a single built artifact.
 */
class SafetyContext {

	/** @var array<int, string> */
	private array $dependencies;

	/**
	 * @param array<int, string> $dependencies Declared plugin dependencies (e.g. woocommerce).
	 */
	public function __construct(
		private string $slug = '',
		array $dependencies = array()
	) {
		$this->dependencies = array_values(
			array_filter(
				array_map('strval', $dependencies),
				static fn( string $dep ): bool => $dep !== ''
			)
		);
	}

	public function getSlug(): string {
		return $this->slug;
	}

	/**
	 * @return array<int, string>
	 */
	public function getDependencies(): array {
		return $this->dependencies;
	}

	public function hasDependency( string $dependency ): bool {
		return in_array($dependency, $this->dependencies, true);
	}
}
