Skip to content

Commit da58692

Browse files
[license] Handle missing license metadata (#227) (#228)
* [license] Handle missing license metadata (#227) * Update wiki submodule pointer for PR #228 --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent d989d39 commit da58692

6 files changed

Lines changed: 56 additions & 9 deletions

File tree

.github/wiki

Submodule wiki updated from 2182ccf to 077086a

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- Rewrite drifted Git hooks by removing the previous target first, restore the intended `0o755` executable mode, and report unwritable hook replacements cleanly when `.git/hooks` stays locked (#190)
2323
- Keep Composer plugin command discovery compatible with consumer environments by moving unsupported Symfony Console named parameters out of command metadata/configuration and by decoupling the custom filesystem wrapper from Composer's bundled Symfony Filesystem signatures (#185)
2424
- Keep Composer autoload, Rector, and ECS from traversing nested fixture `vendor` directories when the composer-plugin consumer fixture has installed dependencies (#179)
25+
- Skip LICENSE generation cleanly when a consumer composer manifest omits or leaves the `license` field empty (#227)
2526

2627
## [1.20.0] - 2026-04-23
2728

src/License/Resolver.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,18 @@ final class Resolver implements ResolverInterface
4747
/**
4848
* Resolves a license identifier to its template filename.
4949
*
50-
* @param string $license The license identifier to resolve
50+
* @param string|null $license The license identifier to resolve
5151
*
5252
* @return string|null The template filename if supported, or null if not
5353
*/
54-
public function resolve(string $license): ?string
54+
public function resolve(?string $license): ?string
5555
{
5656
$normalized = $this->normalize($license);
5757

58+
if (null === $normalized) {
59+
return null;
60+
}
61+
5862
if (! isset(self::SUPPORTED_LICENSES[$normalized])) {
5963
return null;
6064
}
@@ -65,12 +69,18 @@ public function resolve(string $license): ?string
6569
/**
6670
* Normalizes the license identifier for comparison.
6771
*
68-
* @param string $license The license identifier to normalize
72+
* @param string|null $license The license identifier to normalize
6973
*
70-
* @return string The normalized license string
74+
* @return string|null The normalized license string, or null when unavailable
7175
*/
72-
private function normalize(string $license): string
76+
private function normalize(?string $license): ?string
7377
{
74-
return trim($license);
78+
if (null === $license) {
79+
return null;
80+
}
81+
82+
$license = trim($license);
83+
84+
return '' === $license ? null : $license;
7585
}
7686
}

src/License/ResolverInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ interface ResolverInterface
3030
/**
3131
* Resolves a license identifier to its template filename.
3232
*
33-
* @param string $license The license identifier to resolve
33+
* @param string|null $license The license identifier to resolve
3434
*
3535
* @return string|null The template filename if supported, or null if not
3636
*/
37-
public function resolve(string $license): ?string;
37+
public function resolve(?string $license): ?string;
3838
}

tests/License/GeneratorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ public function generateWithUnsupportedLicenseWillReturnNull(): void
109109
self::assertNull($result);
110110
}
111111

112+
/**
113+
* @return void
114+
*/
115+
#[Test]
116+
public function generateWithMissingLicenseWillReturnNull(): void
117+
{
118+
$this->composer->getLicense()
119+
->willReturn(null);
120+
$this->resolver->resolve(null)
121+
->willReturn(null);
122+
$this->filesystem->dumpFile(Argument::cetera())
123+
->shouldNotBeCalled();
124+
125+
$result = $this->generator->generate('/tmp/LICENSE');
126+
127+
self::assertNull($result);
128+
}
129+
112130
/**
113131
* @return void
114132
*/

tests/License/ResolverTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,22 @@ public function resolveWithUnknownLicenseWillReturnNull(): void
6565
{
6666
self::assertNull($this->resolver->resolve('Unknown-License'));
6767
}
68+
69+
/**
70+
* @return void
71+
*/
72+
#[Test]
73+
public function resolveWithMissingLicenseWillReturnNull(): void
74+
{
75+
self::assertNull($this->resolver->resolve(null));
76+
}
77+
78+
/**
79+
* @return void
80+
*/
81+
#[Test]
82+
public function resolveWithEmptyLicenseWillReturnNull(): void
83+
{
84+
self::assertNull($this->resolver->resolve(' '));
85+
}
6886
}

0 commit comments

Comments
 (0)