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