13
13
*/
14
14
abstract class AbstractManifest
15
15
{
16
-
17
16
/**
18
17
* The bag this manifest is part of.
19
18
*
@@ -93,7 +92,7 @@ abstract class AbstractManifest
93
92
* @param boolean $load
94
93
* Whether we are loading an existing file
95
94
*/
96
- protected function __construct (Bag $ bag , $ algorithm , $ filename , $ load = false )
95
+ protected function __construct (Bag $ bag , string $ algorithm , string $ filename , bool $ load = false )
97
96
{
98
97
$ this ->bag = $ bag ;
99
98
$ this ->algorithm = $ algorithm ;
@@ -110,7 +109,7 @@ protected function __construct(Bag $bag, $algorithm, $filename, $load = false)
110
109
*
111
110
* @return string
112
111
*/
113
- public function getAlgorithm () : string
112
+ public function getAlgorithm (): string
114
113
{
115
114
return $ this ->algorithm ;
116
115
}
@@ -120,7 +119,7 @@ public function getAlgorithm() : string
120
119
*
121
120
* @return string
122
121
*/
123
- public function getFilename () : string
122
+ public function getFilename (): string
124
123
{
125
124
return $ this ->filename ;
126
125
}
@@ -130,7 +129,7 @@ public function getFilename() : string
130
129
*
131
130
* @return array
132
131
*/
133
- public function getErrors () : array
132
+ public function getErrors (): array
134
133
{
135
134
return $ this ->manifestErrors ;
136
135
}
@@ -140,7 +139,7 @@ public function getErrors() : array
140
139
*
141
140
* @return array
142
141
*/
143
- public function getWarnings () : array
142
+ public function getWarnings (): array
144
143
{
145
144
return $ this ->manifestWarnings ;
146
145
}
@@ -151,7 +150,7 @@ public function getWarnings() : array
151
150
* @throws \whikloj\BagItTools\Exceptions\FilesystemException
152
151
* Error writing the manifest file to disk.
153
152
*/
154
- public function update ()
153
+ public function update (): void
155
154
{
156
155
$ newHashes = [];
157
156
foreach ($ this ->hashes as $ path => $ hash ) {
@@ -164,7 +163,7 @@ public function update()
164
163
/**
165
164
* Compare file hashes against what is on disk.
166
165
*/
167
- public function validate ()
166
+ public function validate (): void
168
167
{
169
168
$ this ->manifestWarnings = [] + $ this ->loadIssues ['warning ' ];
170
169
$ this ->manifestErrors = [] + $ this ->loadIssues ['error ' ];
@@ -192,7 +191,7 @@ public function validate()
192
191
* @return array
193
192
* Array of paths => hashes
194
193
*/
195
- public function getHashes () : array
194
+ public function getHashes (): array
196
195
{
197
196
return $ this ->hashes ;
198
197
}
@@ -209,7 +208,7 @@ public function getHashes() : array
209
208
* @param string $filepath
210
209
* The absolute filepath.
211
210
*/
212
- protected function validatePath ($ path , $ filepath )
211
+ protected function validatePath (string $ path , string $ filepath ): void
213
212
{
214
213
if (!file_exists ($ filepath )) {
215
214
$ this ->addError ("{$ path } does not exist. " );
@@ -224,7 +223,7 @@ protected function validatePath($path, $filepath)
224
223
* @throws \whikloj\BagItTools\Exceptions\FilesystemException
225
224
* Unable to read manifest file.
226
225
*/
227
- protected function loadFile ()
226
+ protected function loadFile (): void
228
227
{
229
228
$ this ->hashes = [];
230
229
$ this ->resetLoadIssues ();
@@ -273,7 +272,7 @@ protected function loadFile()
273
272
* @throws \whikloj\BagItTools\Exceptions\FilesystemException
274
273
* If we can't write the manifest files.
275
274
*/
276
- protected function writeToDisk ()
275
+ protected function writeToDisk (): void
277
276
{
278
277
$ fullPath = $ this ->bag ->makeAbsolute ($ this ->filename );
279
278
if (file_exists ($ fullPath )) {
@@ -322,7 +321,7 @@ private function checkIncomingFilePath(string $filepath, int $lineCount): void
322
321
* @return string
323
322
* The hash.
324
323
*/
325
- protected function calculateHash ($ file ) : string
324
+ protected function calculateHash (string $ file ): string
326
325
{
327
326
return hash_file ($ this ->getPhpHashName (), $ file );
328
327
}
@@ -333,7 +332,7 @@ protected function calculateHash($file) : string
333
332
* @param string $message
334
333
* The error text.
335
334
*/
336
- protected function addError ($ message )
335
+ protected function addError (string $ message ): void
337
336
{
338
337
$ this ->manifestErrors [] = [
339
338
'file ' => $ this ->filename ,
@@ -347,7 +346,7 @@ protected function addError($message)
347
346
* @param string $message
348
347
* The error text.
349
348
*/
350
- protected function addWarning ($ message )
349
+ protected function addWarning (string $ message ): void
351
350
{
352
351
$ this ->manifestWarnings [] = [
353
352
'file ' => $ this ->filename ,
@@ -362,7 +361,7 @@ protected function addWarning($message)
362
361
*
363
362
* @return string the PHP hash name for the internal hash encoding.
364
363
*/
365
- protected function getPhpHashName () : string
364
+ protected function getPhpHashName (): string
366
365
{
367
366
return Bag::getHashName ($ this ->algorithm );
368
367
}
@@ -377,7 +376,7 @@ protected function getPhpHashName() : string
377
376
* @param string $path
378
377
* The normalized path.
379
378
*/
380
- private function addToNormalizedList ($ path )
379
+ private function addToNormalizedList (string $ path ): void
381
380
{
382
381
$ this ->normalizedPaths [] = $ path ;
383
382
}
@@ -390,7 +389,7 @@ private function addToNormalizedList($path)
390
389
* @return bool
391
390
* True if there is a match.
392
391
*/
393
- private function matchNormalizedList ($ path ) : bool
392
+ private function matchNormalizedList (string $ path ): bool
394
393
{
395
394
return (in_array ($ this ->normalizePath ($ path ), $ this ->normalizedPaths ));
396
395
}
@@ -405,7 +404,7 @@ private function matchNormalizedList($path) : bool
405
404
* @return string
406
405
* The normalized path.
407
406
*/
408
- private function normalizePath ($ path , $ toLower = true )
407
+ private function normalizePath (string $ path , bool $ toLower = true ): string
409
408
{
410
409
$ path = urldecode ($ path );
411
410
if ($ toLower ) {
@@ -425,7 +424,7 @@ private function normalizePath($path, $toLower = true)
425
424
* @return string
426
425
* The cleaned up absolute file path, not resolved on disk.
427
426
*/
428
- private function cleanUpAbsPath ($ filepath ) : string
427
+ private function cleanUpAbsPath (string $ filepath ): string
429
428
{
430
429
$ filepath = trim ($ filepath );
431
430
return BagUtils::getAbsolute ($ filepath );
@@ -439,7 +438,7 @@ private function cleanUpAbsPath($filepath) : string
439
438
* @return string
440
439
* The cleaned up relative file path or blank if not in the bag Root.
441
440
*/
442
- private function cleanUpRelPath ($ filepath ) : string
441
+ private function cleanUpRelPath (string $ filepath ): string
443
442
{
444
443
$ filepath = $ this ->bag ->makeAbsolute ($ filepath );
445
444
$ filepath = $ this ->cleanUpAbsPath ($ filepath );
@@ -453,7 +452,7 @@ private function cleanUpRelPath($filepath) : string
453
452
* @param string $message
454
453
* The error text.
455
454
*/
456
- private function addLoadError ($ message )
455
+ private function addLoadError (string $ message ): void
457
456
{
458
457
$ this ->loadIssues ['error ' ][] = [
459
458
'file ' => $ this ->filename ,
@@ -467,7 +466,7 @@ private function addLoadError($message)
467
466
* @param string $message
468
467
* The error text.
469
468
*/
470
- private function addLoadWarning ($ message )
469
+ private function addLoadWarning (string $ message ): void
471
470
{
472
471
$ this ->loadIssues ['warning ' ][] = [
473
472
'file ' => $ this ->filename ,
@@ -478,7 +477,7 @@ private function addLoadWarning($message)
478
477
/**
479
478
* Utility to reset the load issues construct.
480
479
*/
481
- private function resetLoadIssues ()
480
+ private function resetLoadIssues (): void
482
481
{
483
482
$ this ->loadIssues = [
484
483
'error ' => [],
0 commit comments