Skip to content

Commit 8508d92

Browse files
committed
fix: PHPDocs
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
1 parent 2997326 commit 8508d92

12 files changed

Lines changed: 179 additions & 32 deletions

src/Command/GitIgnoreCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
*/
4141
final class GitIgnoreCommand extends AbstractCommand
4242
{
43+
/**
44+
* @param WriterInterface $writer the writer component for handling .gitignore file writing
45+
*/
4346
private readonly WriterInterface $writer;
4447

4548
/**

src/GitIgnore/Classifier.php

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,46 @@
2121
use function Safe\preg_match;
2222

2323
/**
24-
* Classifies .gitignore entries as directories or files.
24+
* Classifies .gitignore entries as directory-oriented or file-oriented patterns.
25+
*
26+
* This classifier SHALL inspect a raw .gitignore entry and determine whether the
27+
* entry expresses directory semantics or file semantics. Implementations MUST
28+
* preserve deterministic classification for identical inputs. Blank entries and
29+
* comment entries MUST be treated as file-oriented values to avoid incorrectly
30+
* inferring directory intent where no effective pattern exists.
2531
*/
2632
final class Classifier implements ClassifierInterface
2733
{
34+
/**
35+
* Represents a classification result indicating directory semantics.
36+
*
37+
* This constant MUST be returned when an entry clearly targets a directory,
38+
* such as entries ending with a slash or patterns that imply directory
39+
* traversal.
40+
*/
2841
private const string DIRECTORY = 'directory';
2942

43+
/**
44+
* Represents a classification result indicating file semantics.
45+
*
46+
* This constant MUST be returned when an entry does not clearly express
47+
* directory semantics, including blank values and comment lines.
48+
*/
3049
private const string FILE = 'file';
3150

3251
/**
33-
* @param string $entry
52+
* Classifies a .gitignore entry as either a directory or a file pattern.
3453
*
35-
* @return string
54+
* The provided entry SHALL be normalized with trim() before any rule is
55+
* evaluated. Empty entries and comment entries MUST be classified as files.
56+
* Entries ending with "/" MUST be classified as directories. Patterns that
57+
* indicate directory traversal or wildcard directory matching SHOULD also be
58+
* classified as directories.
59+
*
60+
* @param string $entry The raw .gitignore entry to classify.
61+
*
62+
* @return string The classification result. The value MUST be either
63+
* self::DIRECTORY or self::FILE.
3664
*/
3765
public function classify(string $entry): string
3866
{
@@ -66,19 +94,32 @@ public function classify(string $entry): string
6694
}
6795

6896
/**
69-
* @param string $entry
97+
* Determines whether the given .gitignore entry represents a directory pattern.
98+
*
99+
* This method MUST delegate the effective classification to classify() and
100+
* SHALL return true only when the resulting classification is
101+
* self::DIRECTORY.
70102
*
71-
* @return bool
103+
* @param string $entry The raw .gitignore entry to evaluate.
104+
*
105+
* @return bool true when the entry is classified as a directory pattern;
106+
* otherwise, false
72107
*/
73108
public function isDirectory(string $entry): bool
74109
{
75110
return self::DIRECTORY === $this->classify($entry);
76111
}
77112

78113
/**
79-
* @param string $entry
114+
* Determines whether the given .gitignore entry represents a file pattern.
115+
*
116+
* This method MUST delegate the effective classification to classify() and
117+
* SHALL return true only when the resulting classification is self::FILE.
118+
*
119+
* @param string $entry The raw .gitignore entry to evaluate.
80120
*
81-
* @return bool
121+
* @return bool true when the entry is classified as a file pattern;
122+
* otherwise, false
82123
*/
83124
public function isFile(string $entry): bool
84125
{

src/GitIgnore/ClassifierInterface.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020

2121
/**
2222
* Defines the contract for classifying .gitignore entries.
23+
*
24+
* This classifier SHALL inspect a raw .gitignore entry and determine whether the
25+
* entry expresses directory semantics or file semantics. Implementations MUST
26+
* preserve deterministic classification for identical inputs. Blank entries and
27+
* comment entries MUST be treated as file-oriented values to avoid incorrectly
28+
* inferring directory intent where no effective pattern exists.
2329
*/
2430
interface ClassifierInterface
2531
{

src/GitIgnore/GitIgnore.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@
3232
final readonly class GitIgnore implements GitIgnoreInterface
3333
{
3434
/**
35-
* @param list<string> $entries the .gitignore entries
35+
* Initializes a GitIgnore instance with the given path and entries.
36+
*
3637
* @param string $path the file system path to the .gitignore file
38+
* @param list<string> $entries the .gitignore entries
3739
*/
3840
public function __construct(
3941
public string $path,

src/GitIgnore/Merger.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,51 @@
2020

2121
/**
2222
* Merges, deduplicates, and sorts .gitignore entries.
23+
*
24+
* This service SHALL combine canonical and project-specific .gitignore
25+
* definitions into a single normalized result. The resulting entry list MUST
26+
* exclude blank lines and comment lines from the merged output, MUST remove
27+
* duplicate entries, and MUST group directory entries before file entries.
28+
* Directory and file groups SHALL be sorted independently in ascending string
29+
* order to provide deterministic output.
2330
*/
2431
final readonly class Merger implements MergerInterface
2532
{
2633
/**
27-
* @param ClassifierInterface $classifier
34+
* Initializes the merger with a classifier implementation.
35+
*
36+
* The classifier MUST be capable of determining whether a normalized
37+
* .gitignore entry represents a directory or a file pattern. When no
38+
* classifier is provided, a default Classifier instance SHALL be used.
39+
*
40+
* @param ClassifierInterface $classifier the classifier responsible for
41+
* distinguishing directory entries
42+
* from file entries during merging
2843
*/
2944
public function __construct(
3045
private ClassifierInterface $classifier = new Classifier()
3146
) {}
3247

3348
/**
34-
* @param GitIgnoreInterface $canonical
35-
* @param GitIgnoreInterface $project
49+
* Merges canonical and project .gitignore entries into a normalized result.
50+
*
51+
* The implementation MUST combine entries from both sources, MUST remove
52+
* duplicates, and MUST ignore blank or commented entries after trimming.
53+
* Entries identified as directories SHALL be collected separately from file
54+
* entries. Each group MUST be sorted using string comparison, and directory
55+
* entries MUST appear before file entries in the final result.
56+
*
57+
* The returned GitIgnore instance SHALL preserve the project path provided by
58+
* the $project argument.
59+
*
60+
* @param GitIgnoreInterface $canonical The canonical .gitignore source whose
61+
* entries provide the shared baseline.
62+
* @param GitIgnoreInterface $project The project-specific .gitignore source
63+
* whose path MUST be preserved in the
64+
* merged result.
3665
*
37-
* @return GitIgnoreInterface
66+
* @return GitIgnoreInterface A new merged .gitignore representation containing
67+
* normalized, deduplicated, and ordered entries.
3868
*/
3969
public function merge(GitIgnoreInterface $canonical, GitIgnoreInterface $project): GitIgnoreInterface
4070
{

src/GitIgnore/MergerInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020

2121
/**
2222
* Defines the contract for merging .gitignore entries.
23+
*
24+
* This service SHALL combine canonical and project-specific .gitignore
25+
* definitions into a single normalized result. The resulting entry list MUST
26+
* exclude blank lines and comment lines from the merged output, MUST remove
27+
* duplicate entries, and MUST group directory entries before file entries.
28+
* Directory and file groups SHALL be sorted independently in ascending string
29+
* order to provide deterministic output.
2330
*/
2431
interface MergerInterface
2532
{

src/GitIgnore/Reader.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,25 @@
1818

1919
namespace FastForward\DevTools\GitIgnore;
2020

21+
/**
22+
* Reads .gitignore files and returns domain representations for them.
23+
*
24+
* This reader SHALL provide a minimal abstraction for loading a .gitignore file
25+
* from a filesystem path. The implementation MUST delegate file parsing to the
26+
* GitIgnore value object and MUST return a GitIgnoreInterface-compatible result.
27+
*/
2128
final class Reader implements ReaderInterface
2229
{
2330
/**
24-
* Reads a .gitignore file from the specified path.
31+
* Reads a .gitignore file from the specified filesystem path.
32+
*
33+
* The provided path MUST reference a readable .gitignore file. This method
34+
* SHALL delegate object creation to GitIgnore::fromFile() and MUST return
35+
* the resulting GitIgnoreInterface implementation.
2536
*
26-
* @param string $gitignorePath the path to the .gitignore file
37+
* @param string $gitignorePath The filesystem path to the .gitignore file.
2738
*
28-
* @return GitIgnoreInterface the GitIgnore instance
39+
* @return GitIgnoreInterface The loaded .gitignore representation.
2940
*/
3041
public function read(string $gitignorePath): GitIgnoreInterface
3142
{

src/GitIgnore/ReaderInterface.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,26 @@
1818

1919
namespace FastForward\DevTools\GitIgnore;
2020

21+
/**
22+
* Defines the contract for reading .gitignore files from a storage location.
23+
*
24+
* Implementations MUST load a .gitignore resource from the provided filesystem
25+
* path and SHALL return a GitIgnoreInterface representation of its contents.
26+
* Implementations SHOULD delegate parsing and normalization responsibilities to
27+
* a dedicated domain object or parser when appropriate.
28+
*/
2129
interface ReaderInterface
2230
{
2331
/**
24-
* Reads a .gitignore file from the specified path.
32+
* Reads a .gitignore file from the specified filesystem path.
33+
*
34+
* The provided path MUST identify a readable .gitignore file. Implementations
35+
* SHALL return a GitIgnoreInterface instance representing the contents read
36+
* from that path.
2537
*
26-
* @param string $gitignorePath the path to the .gitignore file
38+
* @param string $gitignorePath The filesystem path to the .gitignore file.
2739
*
28-
* @return GitIgnoreInterface the GitIgnore instance
40+
* @return GitIgnoreInterface The loaded .gitignore representation.
2941
*/
3042
public function read(string $gitignorePath): GitIgnoreInterface;
3143
}

src/GitIgnore/Writer.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,37 @@
2121
use Symfony\Component\Filesystem\Filesystem;
2222

2323
/**
24-
* Renders and writes the normalized .gitignore file.
24+
* Renders and persists normalized .gitignore content.
25+
*
26+
* This writer SHALL transform a GitIgnoreInterface representation into the
27+
* textual format expected by a .gitignore file and MUST persist that content to
28+
* the target path exposed by the provided object. Implementations MUST write a
29+
* trailing line feed to ensure consistent file formatting.
2530
*/
2631
final readonly class Writer implements WriterInterface
2732
{
2833
/**
29-
* @param Filesystem $filesystem
34+
* Creates a writer with the filesystem dependency used for persistence.
35+
*
36+
* The provided filesystem implementation MUST support writing file contents
37+
* to the target path returned by a GitIgnoreInterface instance.
38+
*
39+
* @param Filesystem $filesystem The filesystem service responsible for
40+
* writing the rendered .gitignore content.
3041
*/
3142
public function __construct(
3243
private Filesystem $filesystem
3344
) {}
3445

3546
/**
36-
* @param GitIgnoreInterface $gitignore
47+
* Writes the normalized .gitignore entries to the target file path.
48+
*
49+
* The implementation SHALL join all entries using a Unix line feed and MUST
50+
* append a final trailing line feed to the generated content. The resulting
51+
* content MUST be written to the path returned by $gitignore->path().
52+
*
53+
* @param GitIgnoreInterface $gitignore The .gitignore representation whose
54+
* path and entries SHALL be written.
3755
*
3856
* @return void
3957
*/

src/GitIgnore/WriterInterface.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,24 @@
1919
namespace FastForward\DevTools\GitIgnore;
2020

2121
/**
22-
* Defines the contract for writing .gitignore files.
22+
* Defines the contract for writing .gitignore representations to persistent storage.
23+
*
24+
* Implementations MUST persist the entries exposed by a GitIgnoreInterface
25+
* instance to its associated path. Implementations SHALL preserve the semantic
26+
* ordering of entries provided by the input object and SHOULD write content in a
27+
* format compatible with standard .gitignore files.
2328
*/
2429
interface WriterInterface
2530
{
2631
/**
27-
* Writes the GitIgnore content to its associated file path.
32+
* Writes the GitIgnore content to its associated filesystem path.
33+
*
34+
* The provided GitIgnoreInterface instance MUST contain the target path and
35+
* the entries to be written. Implementations SHALL persist that content to
36+
* the associated location represented by the given object.
2837
*
29-
* @param GitIgnoreInterface $gitignore the GitIgnore instance to write
38+
* @param GitIgnoreInterface $gitignore The .gitignore representation to
39+
* write to persistent storage.
3040
*
3141
* @return void
3242
*/

0 commit comments

Comments
 (0)