findings = $findings; $this->extension_state = $extension_state ?? static function ( string $extension ): bool { return extension_loaded( $extension ); }; } public function id(): string { return 'environment.php_extensions'; } /** * @return array */ public function execute( string $timestamp ): array { $extensions = array_merge( self::REQUIRED, self::RECOMMENDED ); $objects = array(); $observed = 0; $missing_required = 0; $missing_recommended = 0; try { foreach ( $extensions as $extension ) { $state = call_user_func( $this->extension_state, $extension ); if ( ! is_bool( $state ) ) { continue; } $importance = in_array( $extension, self::REQUIRED, true ) ? 'required' : 'recommended'; $objects[] = array( 'id' => $extension, 'importance' => $importance, 'loaded' => $state, ); ++$observed; if ( ! $state && 'required' === $importance ) { ++$missing_required; } elseif ( ! $state ) { ++$missing_recommended; } } } catch ( Throwable $exception ) { return $this->error_finding( $timestamp, count( $extensions ) ); } $total = count( $extensions ); if ( 0 === $observed ) { $status = 'not_tested'; $coverage = 'none'; } elseif ( $missing_required > 0 ) { $status = 'fail'; $coverage = $observed === $total ? 'complete' : 'partial'; } elseif ( $missing_recommended > 0 ) { $status = 'warning'; $coverage = $observed === $total ? 'complete' : 'partial'; } elseif ( $observed < $total ) { $status = 'not_tested'; $coverage = 'partial'; } else { $status = 'pass'; $coverage = 'complete'; } return $this->findings->build( $this->id(), $status, array( 'objects' => $objects, 'observed_count' => $observed, 'total_count' => $total, 'truncated' => false, 'limitations' => array( 'Loaded-state metadata was checked; extension configuration and feature-level behaviour were not exercised.' ), ), $observed, $total, $coverage, $timestamp ); } /** * @return array */ private function error_finding( string $timestamp, int $total ): array { return $this->findings->build( $this->id(), 'error', array( 'objects' => array(), 'observed_count' => 0, 'total_count' => $total, 'truncated' => false, 'limitations' => array( 'The extension observer failed; no exception message or environment value was stored.' ), ), 0, $total, 'error', $timestamp ); } }