• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eliashaeussler / gitattributes / 11745881131

08 Nov 2024 04:31PM UTC coverage: 86.061% (+49.6%) from 36.424%
11745881131

push

github

eliashaeussler
Initial commit

142 of 165 new or added lines in 10 files covered. (86.06%)

142 of 165 relevant lines covered (86.06%)

4.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.91
/src/GitattributesDumper.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/gitattributes".
7
 *
8
 * Copyright (C) 2024 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\Gitattributes;
25

26
use function file_exists;
27
use function file_put_contents;
28

29
/**
30
 * GitattributesDumper.
31
 *
32
 * @author Elias Häußler <elias@haeussler.dev>
33
 * @license GPL-3.0-or-later
34
 */
35
final class GitattributesDumper
36
{
37
    public function __construct(
2✔
38
        private readonly string $rootPath,
39
    ) {}
2✔
40

41
    /**
42
     * @param list<Rule\Rule> $rules
43
     *
44
     * @throws Exception\FileAlreadyExists
45
     */
46
    public function dump(string $filename, array $rules): bool
2✔
47
    {
48
        $file = Helper\FilesystemHelper::createFileObject($filename, $this->rootPath);
2✔
49

50
        if (file_exists($file->getPathname())) {
2✔
51
            throw new Exception\FileAlreadyExists($file->getPathname());
1✔
52
        }
53

54
        $ruleset = new Rule\Ruleset($file, $rules);
1✔
55
        $lines = $ruleset->toString().PHP_EOL;
1✔
56

57
        if (false !== file_put_contents($file->getPathname(), $lines)) {
1✔
58
            return true;
1✔
59
        }
60

NEW
61
        return false;
×
62
    }
63
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc