$model * @param int $post_id * @param string $subtree_id * @return array */ protected function analyze( array $model, int $post_id, string $subtree_id ): array { $rows = $model['rows']; if ( count( $rows ) < 4 ) { return array( 'findings' => array(), 'score' => 100, 'message' => __( 'Too few sections for pacing to be meaningful.', 'acrossai-abilities-manager' ), ); } $best_run = 1; $best_shape = ''; $run = 1; for ( $i = 1, $n = count( $rows ); $i < $n; $i++ ) { $same = (string) $rows[ $i ]['ratio'] === (string) $rows[ $i - 1 ]['ratio'] && (int) $rows[ $i ]['lane_count'] === (int) $rows[ $i - 1 ]['lane_count']; $run = $same ? $run + 1 : 1; if ( $run > $best_run ) { $best_run = $run; $best_shape = (string) $rows[ $i ]['ratio']; } } $findings = array(); if ( $best_run >= 4 ) { $findings[] = array( 'type' => 'unbroken_run', 'length' => $best_run, 'shape' => $best_shape, 'severity' => $best_run >= 6 ? 'medium' : 'low', 'message' => sprintf( /* translators: 1: run length, 2: shape */ __( '%1$d consecutive sections use the same %2$s shape without a change of pace.', 'acrossai-abilities-manager' ), $best_run, '' === $best_shape ? __( 'single-lane', 'acrossai-abilities-manager' ) : $best_shape ), ); } return array( 'findings' => $findings, 'recommendations' => array() === $findings ? array() : array( array( 'suggestion' => __( 'Interrupt the run — a full-width section, a different split, or simply more space — so the page has a beat somewhere in the middle.', 'acrossai-abilities-manager' ) ), ), 'score' => max( 0, 100 - max( 0, $best_run - 3 ) * 15 ), 'extras' => array( 'longest_run' => $best_run ), ); } }