results; } /** @return string[] */ public function pack_ids(): array { return $this->pack_ids; } /** @return string[] */ public function reason_codes(): array { return $this->reason_codes; } public function resolution_mode(): string { return $this->resolution_mode; } public function ruleset_hash(): string { return $this->ruleset_hash; } public function generated_at(): string { return $this->generated_at; } /** @return array{pass:int,warning:int,blocker:int,not_applicable:int} */ public function counts(): array { $counts = array( 'pass' => 0, 'warning' => 0, 'blocker' => 0, 'not_applicable' => 0, ); foreach ( $this->results as $result ) { $status = $result->get_status(); if ( isset( $counts[ $status ] ) ) { ++$counts[ $status ]; } } return $counts; } public function has_blockers(): bool { return $this->counts()['blocker'] > 0; } /** @return array */ public function to_array(): array { return array( 'generated_at' => $this->generated_at, 'pack_ids' => $this->pack_ids, 'reason_codes' => $this->reason_codes, 'resolution_mode' => $this->resolution_mode, 'ruleset_hash' => $this->ruleset_hash, 'counts' => $this->counts(), 'has_blockers' => $this->has_blockers(), 'results' => array_map( static fn( ValidationResult $result ): array => $result->to_array(), $this->results ), ); } /** * @param array $data Cached report. */ public static function from_array( array $data ): ?self { if ( ! isset( $data['results'], $data['pack_ids'], $data['reason_codes'] ) || ! is_array( $data['results'] ) ) { return null; } $results = array(); foreach ( $data['results'] as $row ) { if ( ! is_array( $row ) || empty( $row['code'] ) || empty( $row['status'] ) ) { continue; } $results[] = new ValidationResult( (string) $row['code'], (string) $row['status'], (string) ( $row['message'] ?? '' ), (string) ( $row['remediation'] ?? '' ), (string) ( $row['source_rule'] ?? '' ), isset( $row['technical_context'] ) && is_array( $row['technical_context'] ) ? $row['technical_context'] : array() ); } return new self( $results, array_values( array_map( 'strval', (array) $data['pack_ids'] ) ), array_values( array_map( 'strval', (array) $data['reason_codes'] ) ), (string) ( $data['resolution_mode'] ?? 'direct' ), (string) ( $data['ruleset_hash'] ?? '' ), (string) ( $data['generated_at'] ?? '' ) ); } }