Skip to content

Classifier

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

Classifies .gitignore entries as directory-oriented or file-oriented patterns.

This classifier SHALL inspect a raw .gitignore entry and determine whether the entry expresses directory semantics or file semantics. Implementations MUST preserve deterministic classification for identical inputs. Blank entries and comment entries MUST be treated as file-oriented values to avoid incorrectly inferring directory intent where no effective pattern exists.


Methods

classify

Classifies a .gitignore entry as either a directory or a file pattern.

public classify(string $entry): string

The provided entry SHALL be normalized with trim() before any rule is evaluated. Empty entries and comment entries MUST be classified as files. Entries ending with "/" MUST be classified as directories. Patterns that indicate directory traversal or wildcard directory matching SHOULD also be classified as directories.

Parameters:

Parameter Type Description
$entry string The raw .gitignore entry to classify.

Return Value:

The classification result. The value MUST be either self::DIRECTORY or self::FILE.


isDirectory

Determines whether the given .gitignore entry represents a directory pattern.

public isDirectory(string $entry): bool

This method MUST delegate the effective classification to classify() and SHALL return true only when the resulting classification is self::DIRECTORY.

Parameters:

Parameter Type Description
$entry string The raw .gitignore entry to evaluate.

Return Value:

true when the entry is classified as a directory pattern; otherwise, false


isFile

Determines whether the given .gitignore entry represents a file pattern.

public isFile(string $entry): bool

This method MUST delegate the effective classification to classify() and SHALL return true only when the resulting classification is self::FILE.

Parameters:

Parameter Type Description
$entry string The raw .gitignore entry to evaluate.

Return Value:

true when the entry is classified as a file pattern; otherwise, false


Clone this wiki locally