<?php
/**
 * Site configuration change detector.
 *
 * @package LocalGuardScanner
 */

namespace LocalGuardScanner\Detection\Database;

use LocalGuardScanner\Domain\Detection\Detector;
use LocalGuardScanner\Domain\Detection\Evidence;
use LocalGuardScanner\Domain\Detection\ScannableObject;

/**
 * Reports historically changed security-sensitive options.
 */
final class SiteConfigurationDetector implements Detector {
	/** @return string */
	public function id() {
		return 'database.site_configuration';
	}

	/** @inheritDoc */
	public function inspect( ScannableObject $scanned_object ) {
		if ( 'db_option' !== $scanned_object->type() ) {
			return array();
		}
		$data = $scanned_object->attributes();
		if ( empty( $data['changed_from_baseline'] ) ) {
			return array();
		}
		$name    = isset( $data['option_name'] ) ? (string) $data['option_name'] : '';
		$weights = array(
			'admin_email'    => 55,
			'siteurl'        => 55,
			'home'           => 55,
			'active_plugins' => 42,
		);
		if ( ! isset( $weights[ $name ] ) ) {
			return array();
		}
		return array( new Evidence( 'database.changed_' . $name, $weights[ $name ], 90, 'sensitive_option_changed', $name ) );
	}
}
