<?php
/**
 * @package Hafenstudios\Wellenbrecher
 */

namespace Hafenstudios\Wellenbrecher\Rules;

use Hafenstudios\Wellenbrecher\Engine\Context;
use Hafenstudios\Wellenbrecher\Engine\RuleResult;

defined( 'ABSPATH' ) || exit;

/**
 * 30 und mehr Konsonanten am Stueck (Zufalls-Strings aus Bot-Generatoren).
 */
class ConsonantRule extends AbstractRule {

	public const ID             = 'consonants';
	public const DEFAULT_POINTS = 15;

	public const MIN_RUN = 30;

	public function __construct( int $points = self::DEFAULT_POINTS ) {
		parent::__construct( $points );
	}

	public function id(): string {
		return self::ID;
	}

	public function stage(): int {
		return 2;
	}

	public function evaluate( Context $context ): RuleResult {
		$text    = $context->field( 'content' ) . ' ' . $context->field( 'author_name' );
		$pattern = '/[bcdfghjklmnpqrstvwxz]{' . self::MIN_RUN . ',}/i';
		return preg_match( $pattern, $text ) ? $this->hit() : $this->miss();
	}
}
