Merger

Class
implements MergerInterface
Read only: Yes Final: Yes

Merges, deduplicates, and sorts .gitignore entries.

Description

This service SHALL combine canonical and project-specific .gitignore definitions into a single normalized result. The resulting entry list MUST exclude blank lines and comment lines from the merged output, MUST remove duplicate entries, and MUST group directory entries before file entries. Directory and file groups SHALL be sorted independently in ascending string order to provide deterministic output.

Table of Contents

Interfaces

MergerInterface

Defines the contract for merging .gitignore entries.

Properties

Methods

__construct()

Initializes the merger with a classifier implementation.

 : mixed
merge()

Merges canonical and project .gitignore entries into a normalized result.

 : GitIgnoreInterface
Properties
Methods

__construct()

Public

Initializes the merger with a classifier implementation.

public __construct([ClassifierInterface  $classifier = new Classifier()]) : mixed

Description

The classifier MUST be capable of determining whether a normalized .gitignore entry represents a directory or a file pattern. When no classifier is provided, a default Classifier instance SHALL be used.

Parameters
$classifier : ClassifierInterface = new Classifier()

Description

the classifier responsible for distinguishing directory entries from file entries during merging

merge()

Public

Merges canonical and project .gitignore entries into a normalized result.

public merge(GitIgnoreInterface  $canonical, GitIgnoreInterface  $project) : GitIgnoreInterface

Description

The implementation MUST combine entries from both sources, MUST remove duplicates, and MUST ignore blank or commented entries after trimming. Entries identified as directories SHALL be collected separately from file entries. Each group MUST be sorted using string comparison, and directory entries MUST appear before file entries in the final result.

The returned GitIgnore instance SHALL preserve the project path provided by the $project argument.

Parameters
$canonical : GitIgnoreInterface

Description

The canonical .gitignore source whose entries provide the shared baseline.

$project : GitIgnoreInterface

Description

The project-specific .gitignore source whose path MUST be preserved in the merged result.

Return values

Description

A new merged .gitignore representation containing normalized, deduplicated, and ordered entries.