Skip to content

Commit

Permalink
More PHP 8 and phpstan fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
whikloj committed Jan 17, 2024
1 parent 8aed900 commit d735be3
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 253 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
},
"scripts": {
"phpstan": [
"php -d memory_limit=-1 ./vendor/bin/phpstan analyze -l 3 src tests"
"php -d memory_limit=-1 ./vendor/bin/phpstan analyze -l 5 src tests"
],
"profile": [
"php -d xdebug.mode=profile -d xdebug.output_dir=mytracedir/ -d xdebug.start_with_request=yes -d xdebug.use_compression=true ./vendor/bin/phpunit"
Expand Down
32 changes: 16 additions & 16 deletions src/AbstractManifest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,51 +19,51 @@ abstract class AbstractManifest
/**
* The bag this manifest is part of.
*
* @var \whikloj\BagItTools\Bag
* @var Bag
*/
protected $bag;
protected Bag $bag;

/**
* The hash algorithm for this manifest.
*
* @var string
*/
protected $algorithm;
protected string $algorithm;

/**
* Associative array where paths are keys and hashes are values.
*
* @var array
*/
protected $hashes = [];
protected array $hashes = [];

/**
* Array of the same paths as in $hashes but normalized for case and characters to check for duplication.
*
* @var array
*/
protected $normalizedPaths = [];
protected array $normalizedPaths = [];

/**
* The filename for this manifest.
*
* @var string
*/
protected $filename;
protected string $filename;

/**
* Errors while validating this manifest.
*
* @var array
*/
protected $manifestErrors = [];
protected array $manifestErrors = [];

/**
* Warnings generated while validating this manifest.
*
* @var array
*/
protected $manifestWarnings = [];
protected array $manifestWarnings = [];

/**
* Errors/Warnings generated while loading.
Expand All @@ -72,22 +72,22 @@ abstract class AbstractManifest
*
* @var array
* Array of arrays with keys 'error' and 'warning'
* @see \whikloj\BagItTools\AbstractManifest::resetLoadIssues()
* @see AbstractManifest::resetLoadIssues
*/
protected $loadIssues;
protected array $loadIssues;

/**
* Manifest constructor.
*
* @param \whikloj\BagItTools\Bag $bag
* @param Bag $bag
* The bag this manifest is part of.
* @param string $algorithm
* The BagIt name of the hash algorithm.
* @param string $filename
* The manifest filename.
* @param boolean $load
* Whether we are loading an existing file
* @throws \whikloj\BagItTools\Exceptions\FilesystemException
* @throws FilesystemException
* Unable to read manifest file.
*/
protected function __construct(Bag $bag, string $algorithm, string $filename, bool $load = false)
Expand Down Expand Up @@ -145,7 +145,7 @@ public function getWarnings(): array
/**
* Update the hashes for each path.
*
* @throws \whikloj\BagItTools\Exceptions\FilesystemException
* @throws FilesystemException
* Error writing the manifest file to disk.
*/
public function update(): void
Expand Down Expand Up @@ -201,7 +201,7 @@ public function getHashes(): array
/**
* Load the paths and hashes from the file on disk, does not validate.
*
* @throws \whikloj\BagItTools\Exceptions\FilesystemException
* @throws FilesystemException
* Unable to read manifest file.
*/
protected function loadFile(): void
Expand Down Expand Up @@ -254,7 +254,7 @@ protected function loadFile(): void
/**
* Utility to recreate the manifest file using the currently stored hashes.
*
* @throws \whikloj\BagItTools\Exceptions\FilesystemException
* @throws FilesystemException
* If we can't write the manifest files.
*/
protected function writeToDisk(): void
Expand Down Expand Up @@ -286,7 +286,7 @@ protected function writeToDisk(): void
*/
private function checkIncomingFilePath(string $filepath, int $lineCount): void
{
if (substr($filepath, 0, 2) == "./") {
if (str_starts_with($filepath, "./")) {
$this->addLoadWarning("Line $lineCount : Paths SHOULD not be relative");
}
if (BagUtils::checkUnencodedFilepath($filepath)) {
Expand Down
Loading

0 comments on commit d735be3

Please sign in to comment.