From fe216d9862d6ede3512cd4bca812c5d28d9c77e6 Mon Sep 17 00:00:00 2001 From: Jared Whiklo Date: Wed, 1 May 2024 20:36:05 -0500 Subject: [PATCH] Some tidying --- composer.json | 4 +--- composer.lock | 64 +-------------------------------------------------- src/Bag.php | 16 +++++++------ 3 files changed, 11 insertions(+), 73 deletions(-) diff --git a/composer.json b/composer.json index f928f5a..b8806c8 100644 --- a/composer.json +++ b/composer.json @@ -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" @@ -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" diff --git a/composer.lock b/composer.lock index edabb9d..0145a8c 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "91066452d862fde4d8e86cb1e5719c03", + "content-hash": "fce1174f3dd45f07a3ae898d0702db6a", "packages": [ { "name": "pear/archive_tar", @@ -2764,68 +2764,6 @@ ], "time": "2020-10-26T13:14:26+00:00" }, - { - "name": "sebastian/phpcpd", - "version": "6.0.3", - "source": { - "type": "git", - "url": "https://github.com/sebastianbergmann/phpcpd.git", - "reference": "f3683aa0db2e8e09287c2bb33a595b2873ea9176" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpcpd/zipball/f3683aa0db2e8e09287c2bb33a595b2873ea9176", - "reference": "f3683aa0db2e8e09287c2bb33a595b2873ea9176", - "shasum": "" - }, - "require": { - "ext-dom": "*", - "php": ">=7.3", - "phpunit/php-file-iterator": "^3.0", - "phpunit/php-timer": "^5.0", - "sebastian/cli-parser": "^1.0", - "sebastian/version": "^3.0" - }, - "bin": [ - "phpcpd" - ], - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "6.0-dev" - } - }, - "autoload": { - "classmap": [ - "src/" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Sebastian Bergmann", - "email": "sebastian@phpunit.de", - "role": "lead" - } - ], - "description": "Copy/Paste Detector (CPD) for PHP code.", - "homepage": "https://github.com/sebastianbergmann/phpcpd", - "support": { - "issues": "https://github.com/sebastianbergmann/phpcpd/issues", - "source": "https://github.com/sebastianbergmann/phpcpd/tree/6.0.3" - }, - "funding": [ - { - "url": "https://github.com/sebastianbergmann", - "type": "github" - } - ], - "abandoned": true, - "time": "2020-12-07T05:39:23+00:00" - }, { "name": "sebastian/recursion-context", "version": "4.0.5", diff --git a/src/Bag.php b/src/Bag.php index e089c2d..bd35f9d 100644 --- a/src/Bag.php +++ b/src/Bag.php @@ -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 { @@ -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); } @@ -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 { @@ -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; } } @@ -2049,7 +2051,7 @@ function (&$item) { } if ( !preg_match( - "~^BagIt\-Version: (\d+)\.(\d+)$~", + "~^BagIt-Version: (\d+)\.(\d+)$~", $lines[0], $match ) @@ -2066,7 +2068,7 @@ function (&$item) { } if ( !preg_match( - "~^Tag\-File\-Character\-Encoding: (.*)$~", + "~^Tag-File-Character-Encoding: (.*)$~", $lines[1], $match ) @@ -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(