Skip to content

Commit b3f0288

Browse files
committed
Add some missing return type declarations.
1 parent 9510ddc commit b3f0288

File tree

8 files changed

+100
-52
lines changed

8 files changed

+100
-52
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,7 @@ __*Why "v3.0.0" instead of "v1.0.0?"*__ Prior to phpMussel v3, the "phpMussel Co
3939
[2021.02.05; Maikuolan]: The default timeout for external requests is now configurable.
4040

4141
[2021.02.07; Maikuolan]: Added the ability to hide the phpMussel version used.
42+
43+
### v3.2.1
44+
45+
[2021.03.11; Maikuolan]: Added some missing return type declarations.

src/ArchiveHandlerInterface.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: Archive handler (last modified: 2020.06.12).
11+
* This file: Archive handler (last modified: 2021.03.11).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -29,13 +29,17 @@ public function EntryRead(int $Bytes = -1);
2929

3030
/**
3131
* Return the compressed size of the entry at the current entry pointer.
32+
*
33+
* @return int
3234
*/
33-
public function EntryCompressedSize();
35+
public function EntryCompressedSize(): int;
3436

3537
/**
3638
* Return the actual size of the entry at the current entry pointer.
39+
*
40+
* @return int
3741
*/
38-
public function EntryActualSize();
42+
public function EntryActualSize(): int;
3943

4044
/**
4145
* Return whether the entry at the current entry pointer is a directory.
@@ -53,8 +57,10 @@ public function EntryIsEncrypted(): bool;
5357

5458
/**
5559
* Return the reported internal CRC hash for the entry, if it exists.
60+
*
61+
* @return string
5662
*/
57-
public function EntryCRC();
63+
public function EntryCRC(): string;
5864

5965
/**
6066
* Return the name of the entry at the current entry pointer.

src/Loader.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The loader (last modified: 2021.03.03).
11+
* This file: The loader (last modified: 2021.03.11).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -484,8 +484,9 @@ public function readBytes(string $In, int $Mode = 0)
484484
*
485485
* @param mixed $Var The variable to fix (passed by reference).
486486
* @param string $Type The type (or pseudo-type) to cast the variable to.
487+
* @return void
487488
*/
488-
public function autoType(&$Var, string $Type = '')
489+
public function autoType(&$Var, string $Type = ''): void
489490
{
490491
if (in_array($Type, ['string', 'timezone', 'checkbox', 'url', 'email'], true)) {
491492
$Var = (string)$Var;
@@ -513,8 +514,9 @@ public function autoType(&$Var, string $Type = '')
513514
* Performs fallbacks and autotyping for missing configuration directives.
514515
*
515516
* @param array $Fallbacks The fallback source.
517+
* @return void
516518
*/
517-
public function fallback(array $Fallbacks)
519+
public function fallback(array $Fallbacks): void
518520
{
519521
foreach ($Fallbacks as $KeyCat => $DCat) {
520522
if (!isset($this->Configuration[$KeyCat])) {
@@ -551,8 +553,9 @@ public function fallback(array $Fallbacks)
551553
* Load L10N data.
552554
*
553555
* @param string $Path Where to find the L10N data to load.
556+
* @return void
554557
*/
555-
public function loadL10N(string $Path = '')
558+
public function loadL10N(string $Path = ''): void
556559
{
557560
if ($this->Configuration['core']['lang'] === 'en') {
558561
$Primary = $this->readFile($Path . 'en.yml');
@@ -905,7 +908,7 @@ public function readFileBlocksGZ(string $File, int $BlocksToRead = 0): string
905908
* @param resource|null $Context Refer to the description for file().
906909
* @return array The file's contents or an empty array on failure.
907910
*/
908-
public function readFileAsArray(string $Filename, int $Flags = 0, $Context = null)
911+
public function readFileAsArray(string $Filename, int $Flags = 0, $Context = null): array
909912
{
910913
/** Guard. */
911914
if (!is_file($Filename) || !is_readable($Filename) || !$Filesize = filesize($Filename)) {
@@ -939,8 +942,9 @@ public function unpackSafe(string $Format, string $Data): array
939942
* If input isn't an array, make it so. Remove empty elements.
940943
*
941944
* @param mixed $Input
945+
* @return void
942946
*/
943-
public function arrayify(&$Input)
947+
public function arrayify(&$Input): void
944948
{
945949
if (!is_array($Input)) {
946950
$Input = [$Input];
@@ -993,8 +997,9 @@ public function isDirEmpty(string $Directory): bool
993997
* Deletes empty directories (used by some front-end methods and log rotation).
994998
*
995999
* @param string $Dir The directory to delete.
1000+
* @return void
9961001
*/
997-
public function deleteDirectory(string $Dir)
1002+
public function deleteDirectory(string $Dir): void
9981003
{
9991004
while (strrpos($Dir, DIRECTORY_SEPARATOR) !== false) {
10001005
$Dir = substr($Dir, 0, strrpos($Dir, DIRECTORY_SEPARATOR));
@@ -1110,8 +1115,9 @@ public function hexSafe(string $Data): string
11101115
*
11111116
* @throws Exception if using flatfiles for caching and if an appropriate
11121117
* cache directory hasn't been specified or can't be written to.
1118+
* @return void
11131119
*/
1114-
private function initialiseCache()
1120+
private function initialiseCache(): void
11151121
{
11161122
/** Exit early if already initialised. */
11171123
if ($this->Cache instanceof \Maikuolan\Common\Cache) {
@@ -1224,8 +1230,9 @@ public function loadShorthandData(): bool
12241230
* @param string $Text A human-readable explanation of the hit.
12251231
* @param int $Code The integer results of the scan.
12261232
* @param int $Depth The current depth of the scan process.
1233+
* @return void
12271234
*/
1228-
public function atHit(string $Hash, int $Size = -1, string $Name = '', string $Text = '', int $Code = 2, int $Depth = 0)
1235+
public function atHit(string $Hash, int $Size = -1, string $Name = '', string $Text = '', int $Code = 2, int $Depth = 0): void
12291236
{
12301237
/** Fallback for missing item hash. */
12311238
if ($Hash === '') {

src/PdfHandler.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: Pdf handler (last modified: 2020.11.27).
11+
* This file: Pdf handler (last modified: 2021.03.11).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -348,7 +348,7 @@ public function EntryRead(int $Bytes = -1): string
348348
*/
349349
public function EntryCompressedSize(): int
350350
{
351-
return $this->Objects[$this->Index]['EntryCompressedSize'] ?? 0;
351+
return (int)($this->Objects[$this->Index]['EntryCompressedSize'] ?? 0);
352352
}
353353

354354
/**
@@ -358,7 +358,7 @@ public function EntryCompressedSize(): int
358358
*/
359359
public function EntryActualSize(): int
360360
{
361-
return $this->Objects[$this->Index]['EntryActualSize'] ?? 0;
361+
return (int)($this->Objects[$this->Index]['EntryActualSize'] ?? 0);
362362
}
363363

364364
/**
@@ -384,11 +384,11 @@ public function EntryIsEncrypted(): bool
384384
/**
385385
* Return the reported internal CRC hash for the entry, if it exists.
386386
*
387-
* @return false Pdf doesn't provide internal CRCs.
387+
* @return string Empty because PDF doesn't provide internal CRCs.
388388
*/
389-
public function EntryCRC(): bool
389+
public function EntryCRC(): string
390390
{
391-
return false;
391+
return '';
392392
}
393393

394394
/**

src/RarHandler.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: Rar handler (last modified: 2020.07.11).
11+
* This file: Rar handler (last modified: 2021.03.11).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -89,18 +89,22 @@ public function EntryRead(int $Bytes = -1)
8989

9090
/**
9191
* Return the compressed size of the entry at the current entry pointer.
92+
*
93+
* @return int
9294
*/
93-
public function EntryCompressedSize()
95+
public function EntryCompressedSize(): int
9496
{
95-
return is_object($this->RarEntry) ? $this->RarEntry->getPackedSize() : false;
97+
return is_object($this->RarEntry) ? (int)$this->RarEntry->getPackedSize() : 0;
9698
}
9799

98100
/**
99101
* Return the actual size of the entry at the current entry pointer.
102+
*
103+
* @return int
100104
*/
101-
public function EntryActualSize()
105+
public function EntryActualSize(): int
102106
{
103-
return is_object($this->RarEntry) ? $this->RarEntry->getUnpackedSize() : false;
107+
return is_object($this->RarEntry) ? (int)$this->RarEntry->getUnpackedSize() : 0;
104108
}
105109

106110
/**
@@ -125,10 +129,12 @@ public function EntryIsEncrypted(): bool
125129

126130
/**
127131
* Return the reported internal CRC hash for the entry, if it exists.
132+
*
133+
* @return string
128134
*/
129-
public function EntryCRC()
135+
public function EntryCRC(): string
130136
{
131-
return is_object($this->RarEntry) ? $this->RarEntry->getCrc() : false;
137+
return is_object($this->RarEntry) ? (string)$this->RarEntry->getCrc() : '';
132138
}
133139

134140
/**

src/Scanner.php

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The scanner (last modified: 2021.01.10).
11+
* This file: The scanner (last modified: 2021.03.11).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -314,8 +314,9 @@ public function scan($Files, int $Format = 0)
314314
* @param string|array $Files Supplied by the scan method.
315315
* @param int $Depth Represents the current depth of recursion from which the
316316
* method has been called.
317+
* @return void
317318
*/
318-
private function recursor($Files = '', int $Depth = -1)
319+
private function recursor($Files = '', int $Depth = -1): void
319320
{
320321
/** Fire event: "atStartOf_recursor". */
321322
$this->Loader->Events->fireEvent('atStartOf_recursor');
@@ -716,8 +717,9 @@ private function recursor($Files = '', int $Depth = -1)
716717
* scanned (in this context, referring to the name supplied by the upload
717718
* client or CLI operator, as opposed to the temporary filename assigned
718719
* by the server or anything else).
720+
* @return void
719721
*/
720-
private function dataHandler(string $str = '', int $Depth = 0, string $OriginalFilename = '')
722+
private function dataHandler(string $str = '', int $Depth = 0, string $OriginalFilename = ''): void
721723
{
722724
/** Fire event: "atStartOf_dataHandler". */
723725
$this->Loader->Events->fireEvent('atStartOf_dataHandler');
@@ -2339,9 +2341,10 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
23392341
* needed (because the zip and rar classes require a file pointer).
23402342
* @param int $ScanDepth The current scan depth (supplied during recursion).
23412343
* @param string $ItemRef A reference to the parent container (for logging).
2344+
* @return void
23422345
* @throws Exception if the metadata scanner throws an exception (forwarded on).
23432346
*/
2344-
private function archiveRecursor(string $Data, string $File = '', int $ScanDepth = 0, string $ItemRef = '')
2347+
private function archiveRecursor(string $Data, string $File = '', int $ScanDepth = 0, string $ItemRef = ''): void
23452348
{
23462349
/** Fire event: "atStartOf_archiveRecursor". */
23472350
$this->Loader->Events->fireEvent('atStartOf_archiveRecursor');
@@ -2687,8 +2690,10 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
26872690

26882691
/**
26892692
* Initialise statistics if they've been enabled.
2693+
*
2694+
* @return void
26902695
*/
2691-
public function statsInitialise()
2696+
public function statsInitialise(): void
26922697
{
26932698
/** Guard. */
26942699
if (!$this->Loader->Configuration['core']['statistics']) {
@@ -2724,8 +2729,9 @@ public function statsInitialise()
27242729
*
27252730
* @param string $Statistic The statistic to increment.
27262731
* @param int $Amount The amount to increment it by.
2732+
* @return void
27272733
*/
2728-
public function statsIncrement(string $Statistic, int $Amount)
2734+
public function statsIncrement(string $Statistic, int $Amount): void
27292735
{
27302736
/** Guard. */
27312737
if (!$this->Loader->Configuration['core']['statistics'] || !isset($this->Loader->InstanceCache['Statistics'][$Statistic])) {
@@ -2738,8 +2744,10 @@ public function statsIncrement(string $Statistic, int $Amount)
27382744

27392745
/**
27402746
* Fetch information about signature files for the scan process.
2747+
*
2748+
* @return void
27412749
*/
2742-
private function organiseSigFiles()
2750+
private function organiseSigFiles(): void
27432751
{
27442752
/** Guard. */
27452753
if (empty($this->Loader->Configuration['signatures']['active']) || !$this->Loader->SignaturesPath) {
@@ -3597,8 +3605,9 @@ private function confineLength(int $Length): bool
35973605
* @param string $Checksum
35983606
* @param int $StringLength
35993607
* @param int $Depth
3608+
* @return void
36003609
*/
3601-
private function detected(string $VN, string $OriginalFilename, string $Checksum, int $StringLength, int $Depth)
3610+
private function detected(string $VN, string $OriginalFilename, string $Checksum, int $StringLength, int $Depth): void
36023611
{
36033612
/** Prepare detection text. */
36043613
$Text = sprintf($this->Loader->L10N->getString('grammar_exclamation_mark'), sprintf(
@@ -3631,8 +3640,9 @@ private function detected(string $VN, string $OriginalFilename, string $Checksum
36313640
* @param string|int $Initial The start of the boundary or string initial offset value.
36323641
* @param string|int $Terminal The end of the boundary or string terminal offset value.
36333642
* @param array $SectionOffsets Section offset values.
3643+
* @return void
36343644
*/
3635-
private function dataConfineByOffsets(string &$Data, &$Initial, &$Terminal, array &$SectionOffsets)
3645+
private function dataConfineByOffsets(string &$Data, &$Initial, &$Terminal, array &$SectionOffsets): void
36363646
{
36373647
/** Guard. */
36383648
if ($Initial === '*' && $Terminal === '*') {
@@ -3738,8 +3748,9 @@ private function splitSigParts(string $Sig, int $Max = -1): array
37383748
* @param int $Depth The depth of the item being scanned in relation to its
37393749
* container and/or its hierarchy within the scan process.
37403750
* @param string $Checksum A hash for the content, inherited from the parent.
3751+
* @return void
37413752
*/
3742-
private function metaDataScan(string $ItemRef, string $Filename, string &$Data, int $Depth, string $Checksum)
3753+
private function metaDataScan(string $ItemRef, string $Filename, string &$Data, int $Depth, string $Checksum): void
37433754
{
37443755
$Depth++;
37453756

@@ -3903,8 +3914,9 @@ private function convertCrx(string &$Data): bool
39033914
* Assigns an array to use for dumping scan debug information (optional).
39043915
*
39053916
* @param array $Arr
3917+
* @return void
39063918
*/
3907-
public function setScanDebugArray(&$Arr)
3919+
public function setScanDebugArray(&$Arr): void
39083920
{
39093921
unset($this->debugArr);
39103922
if (!is_array($Arr)) {
@@ -3917,17 +3929,20 @@ public function setScanDebugArray(&$Arr)
39173929
* Destroys the scan debug array (optional).
39183930
*
39193931
* @param array $Arr
3932+
* @return void
39203933
*/
3921-
public function destroyScanDebugArray(&$Arr)
3934+
public function destroyScanDebugArray(&$Arr): void
39223935
{
39233936
unset($this->Loader->InstanceCache['DebugArrKey'], $this->debugArr);
39243937
$Arr = null;
39253938
}
39263939

39273940
/**
39283941
* Reset heuristics.
3942+
*
3943+
* @return void
39293944
*/
3930-
private function resetHeuristics()
3945+
private function resetHeuristics(): void
39313946
{
39323947
$this->HeuristicText = [];
39333948
$this->HeuristicCount = 0;

0 commit comments

Comments
 (0)