<?php
/**
 * Verifies composer-patches applied the Security Ninja scr34m adapter patch.
 *
 * @package security-ninja
 */

$path = dirname( __DIR__ ) . '/vendor/scr34m/php-malware-scanner/scan.php';

if ( ! is_readable( $path ) ) {
	fwrite( STDERR, "verify-malware-scanner-patch: missing {$path}\n" );
	exit( 1 );
}

$src = file_get_contents( $path );
if ( false === $src ) {
	fwrite( STDERR, "verify-malware-scanner-patch: could not read scan.php\n" );
	exit( 1 );
}

// Patch promotes these for MalwareScannerAdapter (parent::scan must call child's printPath).
$needles = array(
	'protected function printPath',
	'protected function process',
	'protected function scanLoop',
);

foreach ( $needles as $needle ) {
	if ( strpos( $src, $needle ) === false ) {
		fwrite( STDERR, "verify-malware-scanner-patch: expected '{$needle}' in scan.php — patch not applied?\n" );
		exit( 1 );
	}
}

echo "verify-malware-scanner-patch: OK\n";
exit( 0 );
