<?php
/**
 * Filters out the configuration for tables that are not in the database.
 *
 * @package Ealab\Deployer
 */

namespace Ealab\Deployer\Utility\DeployerConfigRepository;

use Ealab\Deployer\Utility\Database;

/**
 * Filters out the configuration for tables that are not in the database.
 */
class AvailableTrackersConfigFilter implements ConfigFilterInterface {
	/**
	 * {@inheritDoc}
	 */
	public static function filter( $config = null, ?array $options = null ) {
		if ( empty( $config ) || ! is_array( $config ) ) {
			return $config;
		}

		$table_names = Database::getTableNames(
			array(
				'without_prefix'            => true,
				'without_dsc_tables' => true,
			)
		);

		// Filter out the configuration for tables that are not in the database.
		return array_intersect_key( $config, array_flip( $table_names ) );
	}
}
