Automattic\WooCommerce\Internal\PushNotifications\Services

StepLogQuery::count_outcomes │ private static │ WC 1.0

Counts rows per step and outcome, as step:outcome keys.

A failure is logged twice, as an error line and as an info step line, so each step line cancels one error line for the same notification, step and outcome, and the failure counts once.

Метод класса: StepLogQuery{}

Хуков нет.

Возвращает

array<string, int>.

Использование

$result = StepLogQuery::count_outcomes( $rows ): array;
$rows(массив) (обязательный)
The rows.

Код StepLogQuery::count_outcomes() WC 11.3.0

private static function count_outcomes( array $rows ): array {
	$step_lines = array();

	foreach ( $rows as $row ) {
		$failure = self::get_failure_key( $row );

		if ( null !== $failure && 'info' === $row['level'] ) {
			$step_lines[ $failure ] = ( $step_lines[ $failure ] ?? 0 ) + 1;
		}
	}

	$counts = array();

	foreach ( $rows as $row ) {
		if ( ! isset( $row['context']['step'], $row['context']['outcome'] ) ) {
			continue;
		}

		$failure = self::get_failure_key( $row );

		if ( null !== $failure && 'info' !== $row['level'] && ( $step_lines[ $failure ] ?? 0 ) > 0 ) {
			--$step_lines[ $failure ];
			continue;
		}

		$key            = $row['context']['step'] . ':' . $row['context']['outcome'];
		$counts[ $key ] = ( $counts[ $key ] ?? 0 ) + 1;
	}

	return $counts;
}