Skip to content

Commit

Permalink
Return file path in archive type exception
Browse files Browse the repository at this point in the history
  • Loading branch information
whikloj committed Apr 12, 2024
1 parent 9f202d5 commit cefe7c9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"./vendor/bin/phpcpd --suffix='.php' src"
],
"phpunit": [
"phpdbg -qrr ./vendor/bin/phpunit -d memory_limit=-1 --testsuite BagIt"
"phpdbg -qrr ./vendor/bin/phpunit -d memory_limit=-1 --verbose --testsuite BagIt"
],
"test": [
"@check",
Expand Down
11 changes: 5 additions & 6 deletions src/Bag.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public function package(string $filepath): void
{
if (!self::hasExtension($filepath, $this->packageExtensions)) {
throw new BagItException(
"Unknown archive type, the file extension must be one of (" .
"Unknown archive type ($filepath), the file extension must be one of (" .
implode(", ", $this->packageExtensions) . ")"
);
}
Expand Down Expand Up @@ -2186,18 +2186,17 @@ private static function getExtension(string $filepath): ?string
{
$filename = strtolower(basename($filepath));
$pathinfo = pathinfo($filename);
$extensions = [$pathinfo['extension']] ?? null;
$extensions = [];
$extensions[] = $pathinfo['extension'] ?? null;
while (strpos($pathinfo['filename'], ".") > -1) {
$pathinfo = pathinfo($pathinfo['filename']);
$extensions[] = $pathinfo['extension'] ?? null;
}
$extensions = array_filter($extensions);
if (count($extensions) > 0) {
$extension = implode(".", array_reverse($extensions));
} else {
$extension = null;
return implode(".", array_reverse($extensions));
}
return $extension;
return null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/BagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,8 +838,8 @@ public function testInvalidPackage(): void
$this->assertFileDoesNotExist($archivefile);

$this->expectException(BagItException::class);
$this->expectExceptionMessage("Unknown archive type, the file extension must be one of (tar, tgz, tar.gz, " .
"tar.bz2, zip)");
$this->expectExceptionMessage("Unknown archive type ($archivefile), the file extension must be one of (tar, " .
"tgz, tar.gz, tar.bz2, zip)");

$bag->package($archivefile);
}
Expand Down

0 comments on commit cefe7c9

Please sign in to comment.