Classifier

Class
implements ClassifierInterface
Final: Yes

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

Description

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.

Table of Contents

Interfaces

ClassifierInterface

Defines the contract for classifying .gitignore entries.

Constants

DIRECTORY

Represents a classification result indicating directory semantics.

 = 'directory'
FILE

Represents a classification result indicating file semantics.

 = 'file'

Methods

classify()

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

 : string
isDirectory()

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

 : bool
isFile()

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

 : bool
Constants

Constants

DIRECTORY

Private

Represents a classification result indicating directory semantics.

private mixed DIRECTORY = 'directory'

Description

This constant MUST be returned when an entry clearly targets a directory, such as entries ending with a slash or patterns that imply directory traversal.

FILE

Private

Represents a classification result indicating file semantics.

private mixed FILE = 'file'

Description

This constant MUST be returned when an entry does not clearly express directory semantics, including blank values and comment lines.

Methods

classify()

Public

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

public classify( string  $entry) : string

Description

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
$entry : string

Description

The raw .gitignore entry to classify.

Return values
string

Description

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

isDirectory()

Public

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

public isDirectory( string  $entry) : bool

Description

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

Parameters
$entry : string

Description

The raw .gitignore entry to evaluate.

Return values
bool

Description

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

isFile()

Public

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

public isFile( string  $entry) : bool

Description

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

Parameters
$entry : string

Description

The raw .gitignore entry to evaluate.

Return values
bool

Description

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