occurrences = $occurrences; $this->generated = $generated; $this->truncated = $truncated; $this->scanned = $scanned; } /** * Returns every analysed occurrence. * * @return Occurrence[] */ public function occurrences(): array { return $this->occurrences; } /** * Total number of controlled blocks. * * @return int */ public function total_blocks(): int { return count( $this->occurrences ); } /** * Number of distinct locations (posts, templates, widgets) involved. * * @return int */ public function total_locations(): int { $seen = array(); foreach ( $this->occurrences as $occurrence ) { $seen[ $occurrence->source_kind . ':' . $occurrence->source_id ] = true; } return count( $seen ); } /** * Number of occurrences with at least one warning. * * @return int */ public function total_warnings(): int { $count = 0; foreach ( $this->occurrences as $occurrence ) { if ( $occurrence->has_warnings() ) { ++$count; } } return $count; } /** * Number of occurrences whose visibility is switched on. * * @return int */ public function total_active(): int { $count = 0; foreach ( $this->occurrences as $occurrence ) { if ( $occurrence->is_enabled() ) { ++$count; } } return $count; } /** * Usage count per condition type, highest first. * * @return array Condition type id → number of blocks using it. */ public function counts_by_condition_type(): array { $counts = array(); foreach ( $this->occurrences as $occurrence ) { // array_unique: a block using a type twice still counts once. foreach ( array_unique( $occurrence->condition_types() ) as $type ) { $counts[ $type ] = ( $counts[ $type ] ?? 0 ) + 1; } } arsort( $counts ); return $counts; } /** * Usage count per source kind. * * @return array Source kind → number of blocks. */ public function counts_by_source_kind(): array { $counts = array(); foreach ( $this->occurrences as $occurrence ) { $counts[ $occurrence->source_kind ] = ( $counts[ $occurrence->source_kind ] ?? 0 ) + 1; } arsort( $counts ); return $counts; } }