|
21 | 21 | use function Safe\preg_match; |
22 | 22 |
|
23 | 23 | /** |
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. |
25 | 31 | */ |
26 | 32 | final class Classifier implements ClassifierInterface |
27 | 33 | { |
| 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 | + */ |
28 | 41 | private const string DIRECTORY = 'directory'; |
29 | 42 |
|
| 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 | + */ |
30 | 49 | private const string FILE = 'file'; |
31 | 50 |
|
32 | 51 | /** |
33 | | - * @param string $entry |
| 52 | + * Classifies a .gitignore entry as either a directory or a file pattern. |
34 | 53 | * |
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. |
36 | 64 | */ |
37 | 65 | public function classify(string $entry): string |
38 | 66 | { |
@@ -66,19 +94,32 @@ public function classify(string $entry): string |
66 | 94 | } |
67 | 95 |
|
68 | 96 | /** |
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. |
70 | 102 | * |
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 |
72 | 107 | */ |
73 | 108 | public function isDirectory(string $entry): bool |
74 | 109 | { |
75 | 110 | return self::DIRECTORY === $this->classify($entry); |
76 | 111 | } |
77 | 112 |
|
78 | 113 | /** |
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. |
80 | 120 | * |
81 | | - * @return bool |
| 121 | + * @return bool true when the entry is classified as a file pattern; |
| 122 | + * otherwise, false |
82 | 123 | */ |
83 | 124 | public function isFile(string $entry): bool |
84 | 125 | { |
|
0 commit comments