check_id = $check_id; $this->factory = $factory; $this->observations = $observations; } public function id(): string { return $this->check_id; } /** * @return array */ public function execute( string $timestamp ): array { $section = $this->observations->section( $this->check_id ); $state = (string) $section['state']; $status = $this->status( $section ); $total = (int) $section['total']; $seen = (int) $section['observed']; if ( 0 === $seen || in_array( $state, array( 'permission_denied', 'not_applicable', 'not_tested' ), true ) ) { $coverage = 'none'; } elseif ( 'error' === $state ) { $coverage = 'error'; } elseif ( $seen < $total || 'partial' === $state ) { $coverage = 'partial'; } else { $coverage = 'complete'; } $evidence = array( 'capability' => $section['capability'], 'state' => $state, ); foreach ( array( 'values', 'masked_paths', 'permission', 'limitations' ) as $key ) { if ( array() !== $section[ $key ] && '' !== $section[ $key ] ) { $evidence[ $key ] = $section[ $key ]; } } return $this->factory->build( $this->check_id, $status, $evidence, $seen, $total, $coverage, $timestamp ); } /** * @param array $section Observation section. */ private function status( array $section ): string { $state = (string) $section['state']; $values = $section['values']; if ( 'error' === $state ) { return 'error'; } if ( in_array( $state, array( 'permission_denied', 'not_applicable', 'not_tested' ), true ) ) { return 'not_tested'; } if ( 'server.filesystem_resources' === $this->check_id && isset( $values['disk_free_band'] ) ) { if ( 'low' === $values['disk_free_band'] ) { return 'fail'; } if ( 'watch' === $values['disk_free_band'] ) { return 'warning'; } } if ( 'server.scheduled_work' === $this->check_id && 'disabled' === ( $values['wp_cron_state'] ?? null ) && 'not_tested' === ( $values['system_timer_state'] ?? null ) ) { return 'warning'; } if ( 'server.tls_http' === $this->check_id && 'http' === ( $values['home_scheme'] ?? null ) ) { return 'warning'; } if ( 'server.integrity' === $this->check_id && 'partial' === $state ) { return 'not_tested'; } return 'available' === $state ? 'pass' : 'info'; } }