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

eliashaeussler / php-cs-fixer-config / 16303565736

15 Jul 2025 08:25PM UTC coverage: 100.0%. Remained the same
16303565736

push

github

web-flow
[TASK] Update friendsofphp/php-cs-fixer to v3.84.0

| datasource | package                   | from   | to     |
| ---------- | ------------------------- | ------ | ------ |
| packagist  | friendsofphp/php-cs-fixer | 3.83.0 | 3.84.0 |

137 of 137 relevant lines covered (100.0%)

4.75 hits per line

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

100.0
/src/Rules/Header.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer package "eliashaeussler/php-cs-fixer-config".
7
 *
8
 * Copyright (C) 2023-2025 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\PhpCsFixerConfig\Rules;
25

26
use EliasHaeussler\PhpCsFixerConfig\Package;
27

28
use function count;
29
use function implode;
30
use function is_array;
31
use function sprintf;
32
use function str_repeat;
33
use function strlen;
34
use function trim;
35

36
/**
37
 * Header.
38
 *
39
 * @author Elias Häußler <elias@haeussler.dev>
40
 * @license GPL-3.0-or-later
41
 */
42
final class Header implements Rule
43
{
44
    /**
45
     * @param list<Package\Author> $packageAuthors
46
     */
47
    private function __construct(
4✔
48
        public readonly string $packageName,
49
        public readonly Package\Type $packageType,
50
        public readonly array $packageAuthors,
51
        public readonly Package\CopyrightRange $copyrightRange,
52
        public readonly Package\License $license,
53
    ) {}
4✔
54

55
    /**
56
     * @param Package\Author|list<Package\Author> $packageAuthors
57
     */
58
    public static function create(
4✔
59
        string $packageName,
60
        Package\Type $packageType,
61
        Package\Author|array $packageAuthors = [],
62
        ?Package\CopyrightRange $copyrightRange = null,
63
        Package\License $license = Package\License::Proprietary,
64
    ): self {
65
        if (!is_array($packageAuthors)) {
4✔
66
            $packageAuthors = [$packageAuthors];
4✔
67
        }
68

69
        return new self(
4✔
70
            $packageName,
4✔
71
            $packageType,
4✔
72
            $packageAuthors,
4✔
73
            $copyrightRange ?? Package\CopyrightRange::create(),
4✔
74
            $license,
4✔
75
        );
4✔
76
    }
77

78
    /**
79
     * @return array{
80
     *     header_comment: array{
81
     *         header: string,
82
     *         comment_type: string,
83
     *         location: string,
84
     *         separate: string
85
     *     }
86
     * }
87
     */
88
    public function get(): array
2✔
89
    {
90
        return [
2✔
91
            'header_comment' => [
2✔
92
                'header' => $this->toString(),
2✔
93
                'comment_type' => 'comment',
2✔
94
                'location' => 'after_declare_strict',
2✔
95
                'separate' => 'both',
2✔
96
            ],
2✔
97
        ];
2✔
98
    }
99

100
    public function toString(): string
5✔
101
    {
102
        return trim(<<<HEADER
5✔
103
This file is part of the {$this->packageType->value} "{$this->packageName}".
5✔
104

105
{$this->generateCopyrightLines()}{$this->license->licenseText()}
5✔
106
HEADER);
5✔
107
    }
108

109
    private function generateCopyrightLines(): string
5✔
110
    {
111
        if ([] === $this->packageAuthors) {
5✔
112
            return '';
1✔
113
        }
114

115
        $numberOfPackageAuthors = count($this->packageAuthors);
4✔
116
        $copyright = sprintf('Copyright (C) %s', $this->copyrightRange);
4✔
117
        $lines = [];
4✔
118

119
        for ($i = 0; $i < $numberOfPackageAuthors; ++$i) {
4✔
120
            $author = $this->packageAuthors[$i];
4✔
121
            $authorLine = sprintf('%s <%s>', $author->name, $author->emailAddress);
4✔
122

123
            if (0 === $i) {
4✔
124
                $author = sprintf('%s %s', $copyright, $authorLine);
4✔
125
            } else {
126
                $author = sprintf('%s %s', str_repeat(' ', strlen($copyright)), $authorLine);
1✔
127
            }
128

129
            if ($i < ($numberOfPackageAuthors - 1)) {
4✔
130
                $author .= ',';
1✔
131
            }
132

133
            $lines[] = $author;
4✔
134
        }
135

136
        // Add empty lines to separate copyright and license text
137
        $lines[] = '';
4✔
138
        $lines[] = '';
4✔
139

140
        return implode(PHP_EOL, $lines);
4✔
141
    }
142
}
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

© 2026 Coveralls, Inc