Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/wiki
Submodule wiki updated from 2182cc to 077086
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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)
- 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)
- Keep Composer autoload, Rector, and ECS from traversing nested fixture `vendor` directories when the composer-plugin consumer fixture has installed dependencies (#179)
- Skip LICENSE generation cleanly when a consumer composer manifest omits or leaves the `license` field empty (#227)

## [1.20.0] - 2026-04-23

Expand Down
22 changes: 16 additions & 6 deletions src/License/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,18 @@ final class Resolver implements ResolverInterface
/**
* Resolves a license identifier to its template filename.
*
* @param string $license The license identifier to resolve
* @param string|null $license The license identifier to resolve
*
* @return string|null The template filename if supported, or null if not
*/
public function resolve(string $license): ?string
public function resolve(?string $license): ?string
{
$normalized = $this->normalize($license);

if (null === $normalized) {
return null;
}

if (! isset(self::SUPPORTED_LICENSES[$normalized])) {
return null;
}
Expand All @@ -65,12 +69,18 @@ public function resolve(string $license): ?string
/**
* Normalizes the license identifier for comparison.
*
* @param string $license The license identifier to normalize
* @param string|null $license The license identifier to normalize
*
* @return string The normalized license string
* @return string|null The normalized license string, or null when unavailable
*/
private function normalize(string $license): string
private function normalize(?string $license): ?string
{
return trim($license);
if (null === $license) {
return null;
}

$license = trim($license);

return '' === $license ? null : $license;
}
}
4 changes: 2 additions & 2 deletions src/License/ResolverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ interface ResolverInterface
/**
* Resolves a license identifier to its template filename.
*
* @param string $license The license identifier to resolve
* @param string|null $license The license identifier to resolve
*
* @return string|null The template filename if supported, or null if not
*/
public function resolve(string $license): ?string;
public function resolve(?string $license): ?string;
}
18 changes: 18 additions & 0 deletions tests/License/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,24 @@ public function generateWithUnsupportedLicenseWillReturnNull(): void
self::assertNull($result);
}

/**
* @return void
*/
#[Test]
public function generateWithMissingLicenseWillReturnNull(): void
{
$this->composer->getLicense()
->willReturn(null);
$this->resolver->resolve(null)
->willReturn(null);
$this->filesystem->dumpFile(Argument::cetera())
->shouldNotBeCalled();

$result = $this->generator->generate('/tmp/LICENSE');

self::assertNull($result);
}

/**
* @return void
*/
Expand Down
18 changes: 18 additions & 0 deletions tests/License/ResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,22 @@ public function resolveWithUnknownLicenseWillReturnNull(): void
{
self::assertNull($this->resolver->resolve('Unknown-License'));
}

/**
* @return void
*/
#[Test]
public function resolveWithMissingLicenseWillReturnNull(): void
{
self::assertNull($this->resolver->resolve(null));
}

/**
* @return void
*/
#[Test]
public function resolveWithEmptyLicenseWillReturnNull(): void
{
self::assertNull($this->resolver->resolve(' '));
}
}
Loading