<?php

namespace SugarCalendarBookings\Support\DataProcessing;

/**
 * Trait RulesTrait.
 *
 * Common functionality for rule-based data processing classes.
 *
 * @since 1.0.0
 */
trait RulesTrait {

	/**
	 * Parse rules into array.
	 *
	 * @since 1.0.0
	 *
	 * @param string|array $field_rules Field rules as string or array.
	 *
	 * @return array
	 */
	protected static function parse_rules( $field_rules ) {

		if ( is_string( $field_rules ) ) {
			return array_map( 'trim', explode( '|', $field_rules ) );
		}

		return (array) $field_rules;
	}

	/**
	 * Check if field uses wildcard notation.
	 *
	 * @since 1.0.0
	 *
	 * @param string $field Field name.
	 *
	 * @return bool
	 */
	protected static function is_wildcard( $field ) {

		return strpos( $field, '.*.' ) !== false || substr( $field, -2 ) === '.*';
	}
}
