Skip to content

ComposerJson

github-actions edited this page Apr 19, 2026 · 1 revision

Represents a specialized reader for a Composer JSON file.

This class SHALL provide convenient accessors for commonly used composer.json metadata after reading and caching the file contents. Consumers SHOULD use this class when they need normalized access to package-level metadata. The internal data cache MUST reflect the contents returned by the underlying JSON file reader at construction time.


Methods

__construct

Initializes the Composer JSON reader.

public __construct(string|null $path = null): mixed

When no path is provided, the default Composer file location returned by Composer's factory SHALL be used. The constructor MUST immediately read and cache the JSON document contents so that subsequent accessor methods can operate on the in-memory data.

Parameters:

Parameter Type Description
$path string|null The absolute or relative path to a
Composer JSON file. When omitted, the
default Composer file path SHALL be used.

Throws:

when $path is'nt provided and COMPOSER environment variable is set to a directory


getName

Returns the package name declared in the Composer file.

public getName(): string

This method SHALL return the value of the name key when present. If the package name is not defined, the method MUST return an empty string.

Return Value:

the package name, or an empty string when undefined


getDescription

Returns the package description declared in the Composer file.

public getDescription(): string

This method SHALL return the value of the description key when present. If the description is not defined, the method MUST return an empty string.

Return Value:

the package description, or an empty string when undefined


getVersion

Returns the package version.

public getVersion(): string

This method SHOULD return the installed package version when it can be resolved through Composer's installed versions metadata. When that value cannot be resolved, the method SHALL fall back to the version value declared in the Composer file. If neither source provides a usable value, the method MUST return an empty string.

Return Value:

the package version, or an empty string when undefined


getType

Returns the package type declared in the Composer file.

public getType(): string

This method SHALL return the value of the type key when present. If the package type is not defined, the method MUST return an empty string.

Return Value:

the package type, or an empty string when undefined


getKeywords

Returns the package keywords declared in the Composer file.

public getKeywords(): array<int,string>

This method SHALL return the keywords values in declaration order whenever available. Non-string values MUST be ignored. If the section is absent, the method MUST return an empty array.

Return Value:

the package keywords, or an empty array when undefined


getHomepage

Returns the package homepage URL declared in the Composer file.

public getHomepage(): string

This method SHALL return the value of the homepage key when present. If the homepage is not defined, the method MUST return an empty string.

Return Value:

the homepage URL, or an empty string when undefined


getReadme

Returns the readme path or reference declared in the Composer file.

public getReadme(): string

This method SHALL return the value of the readme key when present. If the readme value is not defined, the method MUST return an empty string.

Return Value:

the readme value, or an empty string when undefined


getTime

Returns the package time metadata as an immutable date-time instance.

public getTime(): \DateTimeImmutable|null

This method SHALL attempt to create a DateTimeImmutable instance from the time field. When the field is not present or is not a valid date-time string, the current immutable date-time SHALL be returned.

Return Value:

the package time metadata as an immutable date-time value


getLicense

Returns the package license when it can be resolved to a single value.

public getLicense(): string|null

This method SHALL return the license value directly when it is a string. When the license is an array containing exactly one item, that single item SHALL be returned. When the license field is not present, is empty, or cannot be resolved to exactly one string value, the method MUST return null.

Return Value:

the resolved license identifier, or null when no single license value can be determined


getAuthors

Returns the package authors declared in the Composer file.

public getAuthors(bool $onlyFirstAuthor = false): \FastForward\DevTools\Composer\Json\Schema\AuthorInterface|iterable<int,\FastForward\DevTools\Composer\Json\Schema\AuthorInterface>

This method SHALL normalize each author entry to an AuthorInterface implementation. When $onlyFirstAuthor is true, the first normalized author MUST be returned. If no author is declared, an UnderflowException SHALL be thrown. When $onlyFirstAuthor is false, all normalized authors MUST be returned as an iterable.

Parameters:

Parameter Type Description
$onlyFirstAuthor bool determines whether only the first declared
author SHALL be returned instead of the full
author list

Return Value:

the first declared author when $onlyFirstAuthor is true, or the full authors list when $onlyFirstAuthor is false


getSupport

Returns the support metadata declared in the Composer file.

public getSupport(): \FastForward\DevTools\Composer\Json\Schema\SupportInterface

This method SHALL return a SupportInterface implementation built from the support section. When the section is absent, an empty support object MUST be returned.

Return Value:

the support metadata object


getFunding

Returns the funding entries declared in the Composer file.

public getFunding(): array<int,\FastForward\DevTools\Composer\Json\Schema\Funding>

This method SHALL normalize each funding entry into a Funding value object. Invalid or non-array entries MUST be ignored. If the section is absent, the method MUST return an empty array.

Return Value:

the funding entries, or an empty array when undefined


getAutoload

Returns the autoload configuration for the requested autoload type.

public getAutoload(string|null $type = null): array<string,mixed>

This method SHALL inspect the autoload section and return the nested configuration for the requested type, such as psr-4. When the autoload section or the requested type is not defined, the method MUST return an empty array.

Parameters:

Parameter Type Description
$type string|null The autoload mapping type to retrieve. This
defaults to the complete section when null.

Return Value:

the autoload configuration for the requested type, or an empty array when unavailable


getAutoloadDev

Returns the development autoload configuration for the requested type.

public getAutoloadDev(string|null $type = null): array<string,mixed>

This method SHALL inspect the autoload-dev section and return the nested configuration for the requested type. When the section or the requested type is not defined, the method MUST return an empty array.

Parameters:

Parameter Type Description
$type string|null The development autoload mapping type to
retrieve. This defaults to the complete section
when null.

Return Value:

the autoload-dev configuration for the requested type, or an empty array when unavailable


getMinimumStability

Returns the minimum stability declared in the Composer file.

public getMinimumStability(): string

This method SHALL return the value of the minimum-stability key when present. If the key is absent, the method MUST return an empty string.

Return Value:

the minimum stability value


getConfig

Returns configuration data from the Composer config section.

public getConfig(string|null $config): array<string,mixed>|string

This method SHALL return the complete config section when $config is null. When a specific key is requested, the method SHALL return the matching value if it is an array or a string. Any non-array scalar value MUST be cast to string. If the section or key is absent, an empty array SHALL be returned when $config is null, otherwise an empty string SHALL be returned.

Parameters:

Parameter Type Description
$config string|null the configuration key to retrieve, or null
to retrieve the complete config section

Return Value:

the requested config value or the full config structure, depending on the requested key


getScripts

Returns the scripts declared in the Composer file.

public getScripts(): array<string,mixed>

This method SHALL return the scripts section when present. If the section is absent or invalid, the method MUST return an empty array.

Return Value:

the Composer scripts configuration


getExtra

Returns the extra configuration section declared in the Composer file.

public getExtra(string|null $extra = null): array<string,mixed>

This method SHALL return the complete extra section when $extra is null. When a specific extra key is requested, the method SHALL return the matching value only when that value is an array. If the section or requested key is absent, the method MUST return an empty array.

Parameters:

Parameter Type Description
$extra string|null the extra configuration key to retrieve, or
null to retrieve the complete extra section

Return Value:

the extra configuration data, or an empty array when undefined


getBin

Returns the executable binary declarations from the Composer file.

public getBin(): string|array<int,string>

This method SHALL return the bin value as declared when it is a string or an array. If the section is absent or invalid, the method MUST return an empty array.

Return Value:

the declared binary path or paths


getSuggest

Returns the package suggestions declared in the Composer file.

public getSuggest(): array<string,string>

This method SHALL return the suggest section as a string map. Non-string keys or values MUST be ignored. If the section is absent, the method MUST return an empty array.

Return Value:

the package suggestion map


getComments

Returns comment metadata associated with the Composer file.

public getComments(): array<int|string,mixed>

Since standard Composer JSON does not define a comments section, this method SHALL return the _comment key when present and valid. When comment metadata is unavailable, the method MUST return an empty array.

Return Value:

the comment metadata, or an empty array when unavailable


Clone this wiki locally