<?php
/**
 * Scoper configuration.
 *
 * @package northmill-online-shared
 */

/**
 * Get WordPress excluded symbols.
 *
 * @param string      $file_name File name.
 * @param string|null $file_path File path.
 *
 * @return array
 */
function get_wp_excluded_symbols( string $file_name, ?string $file_path = null ): array {
	if ( is_null( $file_path ) ) {
		$file_path = constant( 'NORTHMILL_SHARED_SCOPER_ROOT' ) . '/vendor/sniccowp/php-scoper-wordpress-excludes/generated/' . $file_name;
	} else {
		$file_path = ! empty( $file_path ) ? $file_path . '/' : '';
		$file_path = __DIR__ . '/' . $file_path . $file_name;
	}

	return json_decode(
		file_get_contents( $file_path ), // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
		true,
	);
}

$wp_classes   = get_wp_excluded_symbols( 'exclude-wordpress-classes.json' );
$wp_functions = get_wp_excluded_symbols( 'exclude-wordpress-functions.json' );
$wp_constants = get_wp_excluded_symbols( 'exclude-wordpress-constants.json' );

$wc_classes            = include constant( 'NORTHMILL_SHARED_SCOPER_ROOT' ) . '/vendor/sniccwp/php-scoper-woocommerce-excludes/generated/exclude-woocommerce-classes.php';
$wc_constants          = include constant( 'NORTHMILL_SHARED_SCOPER_ROOT' ) . '/vendor/sniccwp/php-scoper-woocommerce-excludes/generated/exclude-woocommerce-constants.php';
$wc_functions          = include constant( 'NORTHMILL_SHARED_SCOPER_ROOT' ) . '/vendor/sniccwp/php-scoper-woocommerce-excludes/generated/exclude-woocommerce-functions.php';
$wc_interfaces         = include constant( 'NORTHMILL_SHARED_SCOPER_ROOT' ) . '/vendor/sniccwp/php-scoper-woocommerce-excludes/generated/exclude-woocommerce-interfaces.php';
$wc_packages_classes   = include constant( 'NORTHMILL_SHARED_SCOPER_ROOT' ) . '/vendor/sniccwp/php-scoper-woocommerce-excludes/generated/exclude-woocommerce-packages-classes.php';
$wc_packages_constants = include constant( 'NORTHMILL_SHARED_SCOPER_ROOT' ) . '/vendor/sniccwp/php-scoper-woocommerce-excludes/generated/exclude-woocommerce-packages-constants.php';
$wc_packages_functions = include constant( 'NORTHMILL_SHARED_SCOPER_ROOT' ) . '/vendor/sniccwp/php-scoper-woocommerce-excludes/generated/exclude-woocommerce-packages-functions.php';

$wc_classes   = array_merge( $wc_classes, $wc_packages_classes, $wc_interfaces );
$wc_constants = array_merge( $wc_constants, $wc_packages_constants );
$wc_functions = array_merge( $wc_functions, $wc_packages_functions );

$nms_monolog_classes     = get_wp_excluded_symbols( 'exclude-monolog-classes.json', '' );
$nms_woocommerce_classes = get_wp_excluded_symbols( 'exclude-woocommerce-classes.json', '' );

$exclude_classes   = array_merge( $wp_classes, $wc_classes, $nms_monolog_classes, $nms_woocommerce_classes );
$exclude_constants = array_merge( $wp_constants, $wc_constants );
$exclude_functions = array_merge( $wp_functions, $wc_functions );

return array(
	'prefix'            => constant( 'NORTHMILL_SHARED_SCOPER_PREFIX' ),
	'php-version'       => '8.2',
	'output-dir'        => '/tmp/northmill-online-shared',
	'finders'           => array(
		\Isolated\Symfony\Component\Finder\Finder::create()
			->files()
			->in( 'vendor/northmill/online-shared' )
			->name( '*.php' ),
	),
	'exclude-classes'   => $exclude_classes,
	'exclude-constants' => $exclude_constants,
	'exclude-functions' => $exclude_functions,
);
