$results * @return array */ public function inspect( ParsedPage $page, array $results ): array { $hits = array(); $counts = array(); foreach ( $page->facts->perf as $fact ) { if ( 'html_bytes' === $fact[0] ) { if ( (int) $fact[1] > self::HTML_LIMIT ) { $hits[] = $this->hit( 'perf.page_size', Priority::LOW, __( 'The page code is very large', 'forensix-digital' ), $page->url, Source::TEMPLATE, '', (int) round( (int) $fact[1] / 1000 ) . ' KB', array( 'kilobytes' => (int) round( (int) $fact[1] / 1000 ) ) ); } continue; } $counts[ $fact[0] ] = ( $counts[ $fact[0] ] ?? 0 ) + 1; if ( $counts[ $fact[0] ] > self::PER_PAGE ) { continue; } if ( 'blocking_script' === $fact[0] ) { $hits[] = $this->hit( 'perf.render_blocking', Priority::LOW, __( 'A script stops the page from showing until it has loaded', 'forensix-digital' ), $fact[1], $fact[2], $fact[3], $fact[1] ); } elseif ( 'lazy_missing' === $fact[0] ) { $hits[] = $this->hit( 'perf.lazy_missing', Priority::LOW, __( 'An image further down the page is not loaded lazily', 'forensix-digital' ), $fact[1], $fact[2], $fact[3], $fact[1] ); } elseif ( 'lazy_first' === $fact[0] ) { $hits[] = $this->hit( 'perf.lazy_first', Priority::MEDIUM, __( 'The first image on the page is loaded lazily', 'forensix-digital' ), $fact[1], $fact[2], $fact[3], $fact[1] ); } } $files = array(); foreach ( $page->references as $reference ) { if ( in_array( $reference->kind, array( Reference::SCRIPT, Reference::STYLE ), true ) ) { $files[ $reference->url ] = true; } } if ( count( $files ) > self::FILE_LIMIT ) { $hits[] = $this->hit( 'perf.many_files', Priority::LOW, __( 'The page asks for many script and style files', 'forensix-digital' ), $page->url, Source::TEMPLATE, '', (string) count( $files ), array( 'files' => count( $files ) ) ); } return $hits; } /** * One suggestion. * * @param string $check_id Finding id. * @param string $severity Priority level. * @param string $title Title. * @param string $target Page or file the finding is about. * @param string $source_type Source type. * @param string $source_ref Source reference. * @param string $context Shown beside the finding. * @param array $details Extra facts. * @phpstan-param array $details * @return array{observation: Observation, context: string} */ private function hit( string $check_id, string $severity, string $title, string $target, string $source_type, string $source_ref, string $context, array $details = array() ): array { return array( 'observation' => new Observation( $check_id, $severity, Priority::SUGGESTION, $title, $target, $source_type, $source_ref, '', $details ), 'context' => $context, ); } }