Skip to content

📊 GetProjectDependencies

Reads composer.json and composer.lock together and returns a summary of the project's dependencies, including direct dependencies, development dependencies, and all installed packages.

When to use

Use this when you need to get the full picture of dependencies (counts, package name lists) in one shot instead of querying them one by one. It does not execute Composer commands; it is pure file reading, so it is fast and does not depend on the network.

Signature

go
func (c *Composer) GetProjectDependencies() (*ProjectDependencies, error)

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
First return value*ProjectDependenciesDependency summary struct, containing counts and package name lists of each kind
Second return valueerrorAlways nil (fault-tolerant internally; missing files do not raise an error)

ProjectDependencies fields: DirectCount, DevCount, TotalInstalled, DirectPackages, DevPackages, InstalledPackages.

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.Fatalf("Initialization failed: %v", err)
	}

	deps, err := comp.GetProjectDependencies()
	if err != nil {
		log.Fatalf("Failed to get dependency summary: %v", err)
	}
	fmt.Printf("Direct dependencies: %d, Dev dependencies: %d, Total installed: %d\n",
		deps.DirectCount, deps.DevCount, deps.TotalInstalled)
}

Advanced

  • To get a complete project summary including outdated package counts, vulnerability counts, and version numbers, use GetProjectSummary.
  • To get only the direct dependency package name list, use GetDirectDependencyNames.
  • Platform requirements (php, ext-*, lib-*) are automatically excluded from the package name lists.

Released under the MIT License