Skip to content

Commit a4cdff2

Browse files
committed
Update for PSR-12
1 parent 57eb89e commit a4cdff2

17 files changed

+412
-397
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
},
4040
"scripts": {
4141
"check": [
42-
"./vendor/bin/phpcs --standard=PSR2 src tests",
42+
"./vendor/bin/phpcs --standard=PSR12 src tests",
4343
"./vendor/bin/phpcpd --suffix='.php' src"
4444
],
4545
"test": [

src/AbstractManifest.php

+23-24
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414
abstract class AbstractManifest
1515
{
16-
1716
/**
1817
* The bag this manifest is part of.
1918
*
@@ -93,7 +92,7 @@ abstract class AbstractManifest
9392
* @param boolean $load
9493
* Whether we are loading an existing file
9594
*/
96-
protected function __construct(Bag $bag, $algorithm, $filename, $load = false)
95+
protected function __construct(Bag $bag, string $algorithm, string $filename, bool $load = false)
9796
{
9897
$this->bag = $bag;
9998
$this->algorithm = $algorithm;
@@ -110,7 +109,7 @@ protected function __construct(Bag $bag, $algorithm, $filename, $load = false)
110109
*
111110
* @return string
112111
*/
113-
public function getAlgorithm() : string
112+
public function getAlgorithm(): string
114113
{
115114
return $this->algorithm;
116115
}
@@ -120,7 +119,7 @@ public function getAlgorithm() : string
120119
*
121120
* @return string
122121
*/
123-
public function getFilename() : string
122+
public function getFilename(): string
124123
{
125124
return $this->filename;
126125
}
@@ -130,7 +129,7 @@ public function getFilename() : string
130129
*
131130
* @return array
132131
*/
133-
public function getErrors() : array
132+
public function getErrors(): array
134133
{
135134
return $this->manifestErrors;
136135
}
@@ -140,7 +139,7 @@ public function getErrors() : array
140139
*
141140
* @return array
142141
*/
143-
public function getWarnings() : array
142+
public function getWarnings(): array
144143
{
145144
return $this->manifestWarnings;
146145
}
@@ -151,7 +150,7 @@ public function getWarnings() : array
151150
* @throws \whikloj\BagItTools\Exceptions\FilesystemException
152151
* Error writing the manifest file to disk.
153152
*/
154-
public function update()
153+
public function update(): void
155154
{
156155
$newHashes = [];
157156
foreach ($this->hashes as $path => $hash) {
@@ -164,7 +163,7 @@ public function update()
164163
/**
165164
* Compare file hashes against what is on disk.
166165
*/
167-
public function validate()
166+
public function validate(): void
168167
{
169168
$this->manifestWarnings = [] + $this->loadIssues['warning'];
170169
$this->manifestErrors = [] + $this->loadIssues['error'];
@@ -192,7 +191,7 @@ public function validate()
192191
* @return array
193192
* Array of paths => hashes
194193
*/
195-
public function getHashes() : array
194+
public function getHashes(): array
196195
{
197196
return $this->hashes;
198197
}
@@ -209,7 +208,7 @@ public function getHashes() : array
209208
* @param string $filepath
210209
* The absolute filepath.
211210
*/
212-
protected function validatePath($path, $filepath)
211+
protected function validatePath(string $path, string $filepath): void
213212
{
214213
if (!file_exists($filepath)) {
215214
$this->addError("{$path} does not exist.");
@@ -224,7 +223,7 @@ protected function validatePath($path, $filepath)
224223
* @throws \whikloj\BagItTools\Exceptions\FilesystemException
225224
* Unable to read manifest file.
226225
*/
227-
protected function loadFile()
226+
protected function loadFile(): void
228227
{
229228
$this->hashes = [];
230229
$this->resetLoadIssues();
@@ -273,7 +272,7 @@ protected function loadFile()
273272
* @throws \whikloj\BagItTools\Exceptions\FilesystemException
274273
* If we can't write the manifest files.
275274
*/
276-
protected function writeToDisk()
275+
protected function writeToDisk(): void
277276
{
278277
$fullPath = $this->bag->makeAbsolute($this->filename);
279278
if (file_exists($fullPath)) {
@@ -322,7 +321,7 @@ private function checkIncomingFilePath(string $filepath, int $lineCount): void
322321
* @return string
323322
* The hash.
324323
*/
325-
protected function calculateHash($file) : string
324+
protected function calculateHash(string $file): string
326325
{
327326
return hash_file($this->getPhpHashName(), $file);
328327
}
@@ -333,7 +332,7 @@ protected function calculateHash($file) : string
333332
* @param string $message
334333
* The error text.
335334
*/
336-
protected function addError($message)
335+
protected function addError(string $message): void
337336
{
338337
$this->manifestErrors[] = [
339338
'file' => $this->filename,
@@ -347,7 +346,7 @@ protected function addError($message)
347346
* @param string $message
348347
* The error text.
349348
*/
350-
protected function addWarning($message)
349+
protected function addWarning(string $message): void
351350
{
352351
$this->manifestWarnings[] = [
353352
'file' => $this->filename,
@@ -362,7 +361,7 @@ protected function addWarning($message)
362361
*
363362
* @return string the PHP hash name for the internal hash encoding.
364363
*/
365-
protected function getPhpHashName() : string
364+
protected function getPhpHashName(): string
366365
{
367366
return Bag::getHashName($this->algorithm);
368367
}
@@ -377,7 +376,7 @@ protected function getPhpHashName() : string
377376
* @param string $path
378377
* The normalized path.
379378
*/
380-
private function addToNormalizedList($path)
379+
private function addToNormalizedList(string $path): void
381380
{
382381
$this->normalizedPaths[] = $path;
383382
}
@@ -390,7 +389,7 @@ private function addToNormalizedList($path)
390389
* @return bool
391390
* True if there is a match.
392391
*/
393-
private function matchNormalizedList($path) : bool
392+
private function matchNormalizedList(string $path): bool
394393
{
395394
return (in_array($this->normalizePath($path), $this->normalizedPaths));
396395
}
@@ -405,7 +404,7 @@ private function matchNormalizedList($path) : bool
405404
* @return string
406405
* The normalized path.
407406
*/
408-
private function normalizePath($path, $toLower = true)
407+
private function normalizePath(string $path, bool $toLower = true): string
409408
{
410409
$path = urldecode($path);
411410
if ($toLower) {
@@ -425,7 +424,7 @@ private function normalizePath($path, $toLower = true)
425424
* @return string
426425
* The cleaned up absolute file path, not resolved on disk.
427426
*/
428-
private function cleanUpAbsPath($filepath) : string
427+
private function cleanUpAbsPath(string $filepath): string
429428
{
430429
$filepath = trim($filepath);
431430
return BagUtils::getAbsolute($filepath);
@@ -439,7 +438,7 @@ private function cleanUpAbsPath($filepath) : string
439438
* @return string
440439
* The cleaned up relative file path or blank if not in the bag Root.
441440
*/
442-
private function cleanUpRelPath($filepath) : string
441+
private function cleanUpRelPath(string $filepath): string
443442
{
444443
$filepath = $this->bag->makeAbsolute($filepath);
445444
$filepath = $this->cleanUpAbsPath($filepath);
@@ -453,7 +452,7 @@ private function cleanUpRelPath($filepath) : string
453452
* @param string $message
454453
* The error text.
455454
*/
456-
private function addLoadError($message)
455+
private function addLoadError(string $message): void
457456
{
458457
$this->loadIssues['error'][] = [
459458
'file' => $this->filename,
@@ -467,7 +466,7 @@ private function addLoadError($message)
467466
* @param string $message
468467
* The error text.
469468
*/
470-
private function addLoadWarning($message)
469+
private function addLoadWarning(string $message): void
471470
{
472471
$this->loadIssues['warning'][] = [
473472
'file' => $this->filename,
@@ -478,7 +477,7 @@ private function addLoadWarning($message)
478477
/**
479478
* Utility to reset the load issues construct.
480479
*/
481-
private function resetLoadIssues()
480+
private function resetLoadIssues(): void
482481
{
483482
$this->loadIssues = [
484483
'error' => [],

0 commit comments

Comments
 (0)