Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Reader | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |
100.00% |
1 / 1 |
| read | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** |
| 6 | * This file is part of fast-forward/dev-tools. |
| 7 | * |
| 8 | * This source file is subject to the license bundled |
| 9 | * with this source code in the file LICENSE. |
| 10 | * |
| 11 | * @copyright Copyright (c) 2026 Felipe Sayão Lobato Abreu <github@mentordosnerds.com> |
| 12 | * @license https://opensource.org/licenses/MIT MIT License |
| 13 | * |
| 14 | * @see https://github.com/php-fast-forward/dev-tools |
| 15 | * @see https://github.com/php-fast-forward |
| 16 | * @see https://datatracker.ietf.org/doc/html/rfc2119 |
| 17 | */ |
| 18 | |
| 19 | namespace FastForward\DevTools\GitAttributes; |
| 20 | |
| 21 | use function Safe\file_get_contents; |
| 22 | |
| 23 | /** |
| 24 | * Reads raw .gitattributes content from the filesystem. |
| 25 | * |
| 26 | * This reader SHALL return the complete textual contents of a .gitattributes |
| 27 | * file, and MUST yield an empty string when the file does not exist. |
| 28 | */ |
| 29 | class Reader implements ReaderInterface |
| 30 | { |
| 31 | /** |
| 32 | * Reads a .gitattributes file from the specified filesystem path. |
| 33 | * |
| 34 | * @param string $gitattributesPath The filesystem path to the .gitattributes file. |
| 35 | * |
| 36 | * @return string The raw .gitattributes content, or an empty string when absent. |
| 37 | */ |
| 38 | public function read(string $gitattributesPath): string |
| 39 | { |
| 40 | if (! file_exists($gitattributesPath)) { |
| 41 | return ''; |
| 42 | } |
| 43 | |
| 44 | return file_get_contents($gitattributesPath); |
| 45 | } |
| 46 | } |