Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Resolver
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 resolve
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
 normalize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
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\License;
21
22/**
23 * Resolves license identifiers to their corresponding template filenames.
24 *
25 * This class maintains a mapping of supported open-source licenses to their
26 * template files and provides methods to check support and resolve licenses.
27 */
28 class Resolver implements ResolverInterface
29{
30    private const array SUPPORTED_LICENSES = [
31        'MIT' => 'mit.txt',
32        'BSD-2-Clause' => 'bsd-2-clause.txt',
33        'BSD-3-Clause' => 'bsd-3-clause.txt',
34        'Apache-2.0' => 'apache-2.0.txt',
35        'Apache-2' => 'apache-2.0.txt',
36        'GPL-3.0-or-later' => 'gpl-3.0-or-later.txt',
37        'GPL-3.0' => 'gpl-3.0-or-later.txt',
38        'GPL-3+' => 'gpl-3.0-or-later.txt',
39        'LGPL-3.0-or-later' => 'lgpl-3.0-or-later.txt',
40        'LGPL-3.0' => 'lgpl-3.0-or-later.txt',
41        'LGPL-3+' => 'lgpl-3.0-or-later.txt',
42        'MPL-2.0' => 'mpl-2.0.txt',
43        'ISC' => 'isc.txt',
44        'Unlicense' => 'unlicense.txt',
45    ];
46
47    /**
48     * Resolves a license identifier to its template filename.
49     *
50     * @param string $license The license identifier to resolve
51     *
52     * @return string|null The template filename if supported, or null if not
53     */
54    public function resolve(string $license): ?string
55    {
56        $normalized = $this->normalize($license);
57
58        if (! isset(self::SUPPORTED_LICENSES[$normalized])) {
59            return null;
60        }
61
62        return self::SUPPORTED_LICENSES[$normalized];
63    }
64
65    /**
66     * Normalizes the license identifier for comparison.
67     *
68     * @param string $license The license identifier to normalize
69     *
70     * @return string The normalized license string
71     */
72    private function normalize(string $license): string
73    {
74        return trim($license);
75    }
76}