respect-validation/src-dev/Spdx/Contributor.php
Henrique Moody 7db3bea8a6
Enhance LintSpdxCommand with contributor tracking and header normalization
Improves SPDX header linting to ensure consistent license metadata across
the codebase.

Key changes:

- Enforce deterministic tag ordering (License-Identifier, FileCopyrightText,
  FileContributor) to ensure consistency, prevent merge conflicts, and
  simplify code reviews

- Add contributor alias mapping to consolidate contributors with multiple
  emails or name variations (e.g., "nickl-" → "Nick Lombard")

- Add --contributions-strategy option with "blame" (current code authors)
  and "log" (all historical contributors) to support different attribution
  philosophies

- Add optional path argument to lint specific files or directories

- Add --fix option to automatically correct header issues

Assisted-by: Claude Code (claude-opus-4-5-20251101)
2026-02-03 15:23:20 +01:00

53 lines
2.1 KiB
PHP

<?php
/*
* SPDX-License-Identifier: MIT
* SPDX-FileCopyrightText: (c) Respect Project Contributors
* SPDX-FileContributor: Henrique Moody <henriquemoody@gmail.com>
*/
declare(strict_types=1);
namespace Respect\Dev\Spdx;
use function str_ends_with;
final readonly class Contributor
{
private const array CONTRIBUTOR_ALIASES = [
'alexandre@gaigalas.net' => ['Alexandre Gomes Gaigalas', 'alganet@gmail.com'],
'alganet+github@gmail.com' => ['Alexandre Gomes Gaigalas', 'alganet@gmail.com'],
'alganet@alganet-laptop.(none)' => ['Alexandre Gomes Gaigalas', 'alganet@gmail.com'],
'alganet@alganet-workstation.(none)' => ['Alexandre Gomes Gaigalas', 'alganet@gmail.com'],
'gaigalas@yahoo-inc.com' => ['Alexandre Gomes Gaigalas', 'alganet@gmail.com'],
'augusto@phpsp.org.br' => ['Augusto Pascutti', 'augusto.hp@gmail.com'],
'github@jigsoft.co.za' => ['Nick Lombard', 'github@jigsoft.co.za'],
'nick@jigsoft.co.za' => ['Nick Lombard', 'github@jigsoft.co.za'],
'emmersonsiqueira@gmail.com' => ['Emmerson Siqueira', 'emmersonsiqueira@gmail.com'],
'jayson.reis@sabbre.com.br' => ['Jayson Reis', 'santosdosreis@gmail.com'],
'kolyshkin@.sqlmaze.local' => ['Kir Kolyshkin', 'kolyshkin@gmail.com'],
'pathumhdes@gmail.com' => ['Pathum Harshana De Silva', 'pathumhdes@gmail.com'],
'andre@andre.(none)' => ['Carlos André Ferrari', 'caferrari@gmail.com'],
'mazanax@yandex.ru' => ['Aleksandr Gorshkov', 'mazanax@yandex.ru'],
'paulkarikari1@gmail.com' => ['Paul Karikari', 'paulkarikari1@gmail.com'],
];
private function __construct(
public string $name,
public string|null $email,
) {
}
public static function create(string $name, string|null $email): self
{
if ($email !== null && isset(self::CONTRIBUTOR_ALIASES[$email])) {
[$name, $email] = self::CONTRIBUTOR_ALIASES[$email];
}
if ($email !== null && str_ends_with($email, 'users.noreply.github.com')) {
$email = null;
}
return new self($name, $email);
}
}