Skip to content

🔒 ValidateComposerLock

Verifies that the composer.lock file exists and is in sync with composer.json. Equivalent to running composer validate --check-lock.

When to use

Use this when you need to ensure the lock file is not missing and has not fallen out of sync due to composer.json changes. Commonly used in CI to prevent cases where a developer committed composer.json changes but forgot to update the lock.

Signature

go
func (c *Composer) ValidateComposerLock() (string, error)

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return valuestringRaw output of the validation command
Second return valueerrorReturned when the lock is missing or out of sync

Example

go
package main

import (
	"fmt"
	"log"
	"strings"

	"github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
	comp, err := composer.New(composer.DefaultOptions())
	if err != nil {
		log.Fatalf("init failed: %v", err)
	}

	output, err := comp.ValidateComposerLock()
	if err != nil {
		switch {
		case strings.Contains(output, "not found"):
			fmt.Println("missing composer.lock file")
		case strings.Contains(output, "not up to date"):
			fmt.Println("composer.lock is out of date, please run composer update")
		default:
			log.Fatalf("validation failed: %v", err)
		}
		return
	}
	fmt.Println("composer.lock is valid")
}

Advanced

Released under the MIT License