🏥 HealthCheck
Performs a one-off comprehensive project health check, summarizing environment, configuration, outdated packages, security vulnerabilities, and abandoned package status.
When to use
Use this when you need a one-click health report for a project (CI gate, monitoring dashboard, pre-deployment self-check) without manually combining multiple individual commands.
Signature
go
func (c *Composer) HealthCheck() (*HealthStatus, error)Parameters
| Parameter | Type | Description |
|---|---|---|
| None | — | This method takes no parameters |
Return value
*HealthStatus: Health status, including environment/file/dependency check fields andOverallStatuserror: Errors during execution
go
type HealthStatus struct {
ComposerInstalled bool `json:"composer_installed"`
ComposerVersion string `json:"composer_version,omitempty"`
PHPAvailable bool `json:"php_available"`
PHPVersion string `json:"php_version,omitempty"`
HasComposerJson bool `json:"has_composer_json"`
HasComposerLock bool `json:"has_composer_lock"`
HasVendorDir bool `json:"has_vendor_dir"`
Valid bool `json:"valid,omitempty"`
OutdatedCount int `json:"outdated_count,omitempty"`
VulnerabilityCount int `json:"vulnerability_count,omitempty"`
AbandonedCount int `json:"abandoned_count,omitempty"`
OverallStatus string `json:"overall_status"` // "healthy" / "warning" / "critical"
Issues []string `json:"issues,omitempty"`
}Example
go
package main
import (
"fmt"
"log"
"github.com/scagogogo/composer-skills/pkg/composer"
)
func main() {
comp, err := composer.New(composer.DefaultOptions())
if err != nil {
log.Fatal(err)
}
health, err := comp.HealthCheck()
if err != nil {
log.Fatalf("Health check failed: %v", err)
}
fmt.Printf("Overall status: %s\n", health.OverallStatus)
fmt.Printf("Composer %s, PHP %s\n", health.ComposerVersion, health.PHPVersion)
for _, issue := range health.Issues {
fmt.Println("- " + issue)
}
}Advanced
OverallStatusvalues:healthy(all pass),warning(non-critical issues such as outdated/abandoned packages),critical(Composer/PHP missing, security vulnerabilities, or invalid configuration)- The checks internally reuse environment probing in the style of GetPHPVersion,
ValidateStructured,GetOutdatedInfo,GetAuditInfo, andGetAbandonedPackagesFromLock - For JSON-formatted output, use
GetHealthAsJSON(see health_check.go) - For single-item diagnostics, use DiagnoseStructured