Automattic\WooCommerce\Internal\Api

QueryComplexityRule::get_coerced_variable_values │ private │ WC 1.0

Coerce the document's variable values against their definitions, once per document.

Method of the class: QueryComplexityRule{}

No Hooks.

Returns

array<string, mixed>. The coerced variable values.

Usage

// private - for code of main (parent) class only
$result = $this->get_coerced_variable_values(): array;

QueryComplexityRule::get_coerced_variable_values() code WC 11.1.2

private function get_coerced_variable_values(): array {
	if ( ! is_null( $this->coerced_variable_values ) ) {
		return $this->coerced_variable_values;
	}

	list( $errors, $variable_values ) = Values::getVariableValues(
		$this->context->getSchema(),
		$this->variableDefs,
		$this->getRawVariableValues()
	);

	if ( ! empty( $errors ) ) {
		// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped -- Not HTML; serialized as JSON by the GraphQL error formatter.
		throw new Error(
			implode(
				"\n\n",
				array_map( static fn( Error $error ): string => $error->getMessage(), $errors )
			)
		);
		// phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped
	}

	$this->coerced_variable_values = $variable_values ?? array();

	return $this->coerced_variable_values;
}