Skip to content

How to handle default values? #8

@gossi

Description

@gossi

Composer has some values for properties that are not present in the composer.json. Some examples:

/config/vendor-dir -> vendor
/config/bin-dir -> vendor/bin
/repositories/{x}/packagist -> true

The question is, what should the API return, in case they are not set written in the composer.json file, e.g.:

composer.getConfig().getVendorDir()

It returns the value that is set in the composer.json (or through API). However when the value isn't set: can return null to indicate that or the default value.

If null the developer can decide what to do and ComposerConstants.DEFAULT_VENDOR_DIR has the default value. If it returns the default value, even if not set, the developer has no idea if that value is a user-set value or the returned default and must check the with getConfig().has("vendor-dir") if the value is set or not.

Another idea is a parameter that should return the default value, even if not set:

composer.getConfig().getVendorDir(true)

which will return the default value, if value isn't set?

Comments?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions