phar-io/manifest · error · InvalidApplicationNameException

InvalidApplicationNameException::InvalidFormat

InvalidApplicationNameException::InvalidFormat

Error message

Format of name "%s" is not valid - expected: vendor/packagename

What it means

ApplicationName::ensureValidFormat() requires the name to match the regex #\w/\w# (at least one word character, a slash, one word character) and throws InvalidApplicationNameException with code InvalidFormat otherwise. Application names must be written vendor/packagename.

Solutions

  1. Rewrite the name as vendor/packagename, e.g. 'phpunit/phpunit'
  2. Ensure a literal slash separates non-empty segments
  3. Trim whitespace from names read from XML attributes

Example fix

// before
new ApplicationName('phpunit');
// after
new ApplicationName('phpunit/phpunit');
Defensive patterns

Strategy: validation

Validate before calling

if (!preg_match('#\w/\w#', $name)) {
    throw new InvalidArgumentException("Application name '$name' must be vendor/packagename");
}

Type guard

function isValidApplicationName(string $name): bool {
    return (bool) preg_match('#\w/\w#', $name);
}

Try / catch

try {
    $name = new ApplicationName($raw);
} catch (InvalidApplicationNameException $e) {
    // re-prompt or fix the <for> attribute to vendor/packagename
}

Prevention

When it happens

Trigger: Constructing new ApplicationName('phpunit'), an empty string, 'vendor/', '/packagename', or a name with spaces — typically via <extension for="..."> or <contains name="..."> during mapping.

Common situations: Single-word extension targets like for="phpunit" in manifests; missing vendor prefixes; copy-pasted names with whitespace.

Understand the failure class

Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.

Related errors


AI-assisted analysis of phar-io/manifest@c581d4941e (2026-09-14). Data as JSON: /api/errors/5b2cce3a5d995da0. Report an issue: GitHub.

Appendix: source

Thrown at src/values/ApplicationName.php:35

    /** @var string */
    private $name;

    public function __construct(string $name) {
        $this->ensureValidFormat($name);
        $this->name = $name;
    }

    public function asString(): string {
        return $this->name;
    }

    public function isEqual(ApplicationName $name): bool {
        return $this->name === $name->name;
    }

    private function ensureValidFormat(string $name): void {
        if (!preg_match('#\w/\w#', $name)) {
            throw new InvalidApplicationNameException(
                sprintf('Format of name "%s" is not valid - expected: vendor/packagename', $name),
                InvalidApplicationNameException::InvalidFormat
            );
        }
    }
}

View on GitHub (pinned to c581d4941e)