Skip to content

Commit

Permalink
Some tidying
Browse files Browse the repository at this point in the history
  • Loading branch information
whikloj committed May 2, 2024
1 parent b9b9880 commit fe216d9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 73 deletions.
4 changes: 1 addition & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
},
"require-dev": {
"phpunit/phpunit": "^9.6",
"sebastian/phpcpd": "^6.0",
"squizlabs/php_codesniffer": "^3.5",
"donatj/mock-webserver": "^2.6",
"phpstan/phpstan": "^1.4"
Expand All @@ -46,8 +45,7 @@
"php -d xdebug.mode=profile -d xdebug.output_dir=mytracedir/ -d xdebug.start_with_request=yes -d xdebug.use_compression=true ./vendor/bin/phpunit"
],
"check": [
"./vendor/bin/phpcs --standard=PSR12 src tests",
"./vendor/bin/phpcpd --suffix='.php' src"
"./vendor/bin/phpcs --standard=PSR12 src tests"
],
"phpunit": [
"phpdbg -qrr ./vendor/bin/phpunit -d memory_limit=-1 --verbose --testsuite BagIt"
Expand Down
64 changes: 1 addition & 63 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions src/Bag.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ public function addFile(string $source, string $dest): void
* The relative path of the file.
* @throws FilesystemException
* Issues deleting the file.
* @throws BagItException If the destination is outside the data directory.
*/
public function removeFile(string $dest): void
{
Expand Down Expand Up @@ -559,7 +560,7 @@ public function makeAbsolute(string $path): string
$components = array_filter(explode("/", $path));
$rootComponents = array_filter(explode("/", $this->bagRoot));
$components = array_merge($rootComponents, $components);
$prefix = (preg_match('/^[a-z]:/i', $rootComponents[0] ?? '', $matches) ? '' : '/');
$prefix = (preg_match('/^[a-z]:/i', $rootComponents[0] ?? '') ? '' : '/');
return $prefix . implode('/', $components);
}

Expand Down Expand Up @@ -1475,6 +1476,7 @@ private function updateFetch(): void
*
* @throws FilesystemException
* Unable to read bag-info.txt
* @throws ProfileException Unable to load or parse the BagIt profile.
*/
private function loadBagInfo(): bool
{
Expand Down Expand Up @@ -1717,10 +1719,10 @@ private function calculateTotalFileSizeAndAmountOfFiles(): ?array
$fullPath = $this->makeAbsolute($file);
if (file_exists($fullPath) && is_file($fullPath)) {
$info = stat($fullPath);
if (!isset($info[7])) {
if (!isset($info["size"])) {
return null;
}
$total_size += (int) $info[7];
$total_size += (int) $info["size"];
$total_files += 1;
}
}
Expand Down Expand Up @@ -2049,7 +2051,7 @@ function (&$item) {
}
if (
!preg_match(
"~^BagIt\-Version: (\d+)\.(\d+)$~",
"~^BagIt-Version: (\d+)\.(\d+)$~",
$lines[0],
$match
)
Expand All @@ -2066,7 +2068,7 @@ function (&$item) {
}
if (
!preg_match(
"~^Tag\-File\-Character\-Encoding: (.*)$~",
"~^Tag-File-Character-Encoding: (.*)$~",
$lines[1],
$match
)
Expand Down Expand Up @@ -2510,11 +2512,11 @@ private function hashIsSupported(string $internal_name): bool
* Case-insensitive version of array_key_exists
*
* @param string $search The key to look for.
* @param string|int $key The associative or numeric key to look in.
* @param int|string $key The associative or numeric key to look in.
* @param array $map The associative array to search.
* @return boolean True if the key exists regardless of case.
*/
private static function arrayKeyExistsNoCase(string $search, $key, array $map): bool
private static function arrayKeyExistsNoCase(string $search, int|string $key, array $map): bool
{
$keys = array_column($map, $key);
array_walk(
Expand Down

0 comments on commit fe216d9

Please sign in to comment.