Skip to content

📦 IsProject

Checks whether the current working directory is a Composer project (i.e. whether a composer.json file exists); it does not execute any Composer commands.

When to use

Use this before performing operations such as install or dependency analysis to first determine whether the current directory is actually a PHP/Composer project, avoiding mistakes on non-project directories. It reads the filesystem directly and is extremely fast.

Signature

go
func (c *Composer) IsProject() bool

Parameters

This method takes no parameters.

Return value

Return valueTypeDescription
Single return valueboolReturns true when composer.json exists in the current working directory, otherwise false

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)
	}

	if comp.IsProject() {
		fmt.Println("The current directory is a Composer project ✅")
	} else {
		fmt.Println("The current directory is not a Composer project ❌")
	}
}

Advanced

Released under the MIT License