Skip to content

Commit b72bb78

Browse files
committed
Some minor code-style cleanup.
1 parent 217dbd5 commit b72bb78

File tree

5 files changed

+57
-29
lines changed

5 files changed

+57
-29
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ __*Why "v3.0.0" instead of "v1.0.0?"*__ Prior to phpMussel v3, the "phpMussel Co
2727
[2020.11.20; Maikuolan]: Added partial support for detecting objects and files embedded within pdf files (due to the nature of how this has been implemented, for the purpose of scanning these embedded objects and files, phpMussel will regard pdf as an archive format; this is intentional).
2828

2929
[2020.11.26; Maikuolan]: Ditched external test frameworks in favour of GitHub Actions. Replaced existing tests. (More work needs to eventually be done towards tests. This will eventually happen at some point).
30+
31+
[2020.11.27; Maikuolan]: Some minor code-style cleanup.

src/CompressionHandler.php

Lines changed: 4 additions & 3 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: Compression handler (last modified: 2020.06.22).
11+
* This file: Compression handler (last modified: 2020.11.27).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -113,7 +113,8 @@ public function TryEverything(): bool
113113
* definitely be useless warnings and notices generated. So, let's
114114
* silence them.
115115
*/
116-
set_error_handler(function ($errno, $errstr, $errfile, $errline){});
116+
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
117+
});
117118

118119
/** Loop until data state doesn't change anymore. */
119120
while (true) {
@@ -137,6 +138,6 @@ public function TryEverything(): bool
137138
* whether they're the same or different. If the same, then data
138139
* probably wasn't compressed to begin with.
139140
*/
140-
return ($Original === $this->Data);
141+
return ($Original === $this->Data);
141142
}
142143
}

src/Loader.php

Lines changed: 14 additions & 5 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: 2020.11.20).
11+
* This file: The loader (last modified: 2020.11.27).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -256,7 +256,7 @@ public function __construct(
256256
* @return bool True to end further processing; False to defer processing.
257257
* @return callable
258258
*/
259-
set_error_handler(function($errno, $errstr, $errfile, $errline) use (&$Errors, &$Events) {
259+
set_error_handler(function ($errno, $errstr, $errfile, $errline) use (&$Errors, &$Events) {
260260
$Errors[] = [$errno, $errstr, $errfile, $errline];
261261
if ($Events->assigned('error')) {
262262
$Events->fireEvent('error', '', $errno, $errstr, $errfile, $errline);
@@ -409,7 +409,8 @@ public function __construct(
409409
/**
410410
* Destruct the loader.
411411
*/
412-
public function __destruct() {
412+
public function __destruct()
413+
{
413414
/** Fire any final shutdown events. */
414415
if ($this->Events->assigned('final')) {
415416
$this->Events->fireEvent('final');
@@ -1012,7 +1013,11 @@ public function request(string $URI, $Params = [], int $Timeout = -1, array $Hea
10121013

10131014
/** Used for debugging. */
10141015
$this->debugMessage(sprintf(
1015-
"\r%s - %s - %s - %s\n", $Post ? 'POST' : 'GET', $URI, $Info['http_code'], (floor($Time * 100) / 100) . 's'
1016+
"\r%s - %s - %s - %s\n",
1017+
$Post ? 'POST' : 'GET',
1018+
$URI,
1019+
$Info['http_code'],
1020+
(floor($Time * 100) / 100) . 's'
10161021
));
10171022

10181023
/** Most recent HTTP code flag. */
@@ -1027,7 +1032,11 @@ public function request(string $URI, $Params = [], int $Timeout = -1, array $Hea
10271032

10281033
/** Used for debugging. */
10291034
$this->debugMessage(sprintf(
1030-
"\r%s - %s - %s - %s\n", $Post ? 'POST' : 'GET', $URI, 200, (floor($Time * 100) / 100) . 's'
1035+
"\r%s - %s - %s - %s\n",
1036+
$Post ? 'POST' : 'GET',
1037+
$URI,
1038+
200,
1039+
(floor($Time * 100) / 100) . 's'
10311040
));
10321041

10331042
/** Most recent HTTP code flag. */

src/PdfHandler.php

Lines changed: 8 additions & 5 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.20).
11+
* This file: Pdf handler (last modified: 2020.11.27).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -129,11 +129,14 @@ public function __construct(string $File)
129129
$BoundaryOpen !== false &&
130130
$BoundaryClose !== false &&
131131
$BoundaryClose > $BoundaryOpen &&
132-
($NextSPos === false || (
133-
$BoundaryOpen < $NextSPos &&
134-
trim(substr($Tree[$Iterator]['Data'], $BoundaryClose + $BoundaryWidth, $NextSPos - $BoundaryClose - $BoundaryWidth)) === ''
132+
(
133+
$NextSPos === false ||
134+
(
135+
$BoundaryOpen < $NextSPos &&
136+
trim(substr($Tree[$Iterator]['Data'], $BoundaryClose + $BoundaryWidth, $NextSPos - $BoundaryClose - $BoundaryWidth)) === ''
137+
)
135138
)
136-
)) {
139+
) {
137140
$Label = trim(substr($Tree[$Iterator]['Data'], $Offset, $BoundaryOpen - $Offset));
138141
$Property = trim(substr($Tree[$Iterator]['Data'], $BoundaryOpen + $BoundaryWidth, $BoundaryClose - $BoundaryOpen - $BoundaryWidth));
139142
if (strlen($Label)) {

src/Scanner.php

Lines changed: 29 additions & 16 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: 2020.11.20).
11+
* This file: The scanner (last modified: 2020.11.27).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -921,7 +921,8 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
921921
'/0a(?:4(?:36f6e74656e742d54797065|4617465|6726f6d|d6573736167652d4944|d4' .
922922
'94d452d56657273696f6e)|5(?:265706c792d546f|2657475726e2d50617468|3656e64' .
923923
'6572|375626a656374|46f|82d4d61696c6572))3a20/i',
924-
$str_hex) || preg_match('/0a2d2d.{32}(?:2d2d)?(?:0d)?0a/i', $str_hex));
924+
$str_hex
925+
) || preg_match('/0a2d2d.{32}(?:2d2d)?(?:0d)?0a/i', $str_hex));
925926

926927
/** Look for potential Mach-O indicators. */
927928
$is_macho = preg_match('/^(?:cafe(?:babe|d00d)|c[ef]faedfe|feedfac[ef])$/', $fourcc);
@@ -975,7 +976,7 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
975976
if (!isset($Fragment[1]) || substr($Fragment[1], 0, 1) !== '$') {
976977
continue 2;
977978
}
978-
$lv_haystack = substr($Fragment[1],1);
979+
$lv_haystack = substr($Fragment[1], 1);
979980
if (!isset($$lv_haystack) || is_array($$lv_haystack)) {
980981
continue 2;
981982
}
@@ -1940,9 +1941,9 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
19401941
$VN = $this->getShorthand($VN[0]);
19411942
$VNLC = strtolower($VN);
19421943
if (($is_not_php && (
1943-
strpos($VNLC, '-php') !== false || strpos($VNLC, '.php') !== false
1944+
strpos($VNLC, '-php') !== false || strpos($VNLC, '.php') !== false
19441945
)) || ($is_not_html && (
1945-
strpos($VNLC, '-htm') !== false || strpos($VNLC, '.htm') !== false
1946+
strpos($VNLC, '-htm') !== false || strpos($VNLC, '.htm') !== false
19461947
))) {
19471948
continue;
19481949
}
@@ -2002,7 +2003,6 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
20022003

20032004
/** Perform API lookups for domains. */
20042005
if (isset($URLScanner) && empty($this->Loader->ScanResultsText[$AtInstanceLookupKey])) {
2005-
20062006
$URLScanner['DomainsCount'] = count($URLScanner['DomainParts']);
20072007

20082008
$URLScanner['URLsCount'] = count($URLScanner['URLParts']);
@@ -2236,7 +2236,9 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
22362236
'https://www.virustotal.com/vtapi/v2/file/report?apikey=' .
22372237
urlencode($this->Loader->Configuration['virustotal']['vt_public_api_key']) .
22382238
'&resource=' . $md5,
2239-
$VTParams, 12);
2239+
$VTParams,
2240+
12
2241+
);
22402242
$VTJSON = json_decode($VTRequest, true);
22412243
$VTCacheTime = $this->Loader->Configuration['virustotal']['vt_quota_time'] * 60;
22422244
$this->Loader->InstanceCache['vt_quota'] .= ($this->Loader->Time + $VTCacheTime) . ';';
@@ -2615,7 +2617,8 @@ private function archiveRecursor(string $Data, string $File = '', int $ScanDepth
26152617
$ThisItemRef = $ItemRef . '' . preg_replace(['~[\x00-\x1f]~', '~^[\\\/]~'], '', $Filename);
26162618

26172619
/** Verify filesize, integrity, etc. Exit early in case of problems. */
2618-
if ($Filesize !== strlen($Content) || ($InternalCRC &&
2620+
if ($Filesize !== strlen($Content) || (
2621+
$InternalCRC &&
26192622
preg_replace('~^0+~', '', $DataCRC32) !== preg_replace('~^0+~', '', $InternalCRC)
26202623
)) {
26212624
$this->Loader->atHit($Hash, $Filesize, $ThisItemRef, sprintf(
@@ -2905,11 +2908,13 @@ private function imageIndicators(string $Ext, string $Head): bool
29052908
return (
29062909
preg_match(
29072910
'/^(?:bm[2p]|c(d5|gm)|d(ib|w[fg]|xf)|ecw|fits|gif|img|j(f?if?|p[2s]|pe?g?2?|xr)|p(bm|cx|dd|gm|ic|n[gms]|' .
2908-
'pm|s[dp])|s(id|v[ag])|tga|w(bmp?|ebp|mp)|x(cf|bmp))$/'
2909-
, $Ext) ||
2911+
'pm|s[dp])|s(id|v[ag])|tga|w(bmp?|ebp|mp)|x(cf|bmp))$/',
2912+
$Ext
2913+
) ||
29102914
preg_match(
2911-
'/^(?:0000000c6a502020|25504446|38425053|424d|474946383[79]61|57454250|67696d7020786366|89504e47|ffd8ff)/'
2912-
, $Head)
2915+
'/^(?:0000000c6a502020|25504446|38425053|424d|474946383[79]61|57454250|67696d7020786366|89504e47|ffd8ff)/',
2916+
$Head
2917+
)
29132918
);
29142919
}
29152920

@@ -3090,7 +3095,9 @@ function_exists('gzinflate') &&
30903095
'/(base64_decode|decode_base64|base64\.b64decode|atob|Base64\.decode64)(\s*' .
30913096
'\(\s*["\'\`])([\da-z+\/]{4})*([\da-z+\/]{4}|[\da-z+\/]{3}=|[\da-z+\/]{2}==)(["\'\`]' .
30923097
'\s*\))/i',
3093-
$str, $matches)) {
3098+
$str,
3099+
$matches
3100+
)) {
30943101
for ($i = 0; $c > $i; $i++) {
30953102
$str = str_ireplace(
30963103
$matches[0][$i],
@@ -3102,7 +3109,9 @@ function_exists('gzinflate') &&
31023109
}
31033110
if ($c = preg_match_all(
31043111
'/(str_rot13\s*\(\s*["\'])([^\'"\(\)]{1,4096})(["\']\s*\))/i',
3105-
$str, $matches)) {
3112+
$str,
3113+
$matches
3114+
)) {
31063115
for ($i = 0; $c > $i; $i++) {
31073116
$str = str_ireplace(
31083117
$matches[0][$i],
@@ -3114,7 +3123,9 @@ function_exists('gzinflate') &&
31143123
}
31153124
if ($c = preg_match_all(
31163125
'/(hex2bin\s*\(\s*["\'])([\da-f]{1,4096})(["\']\s*\))/i',
3117-
$str, $matches)) {
3126+
$str,
3127+
$matches
3128+
)) {
31183129
for ($i = 0; $c > $i; $i++) {
31193130
$str = str_ireplace(
31203131
$matches[0][$i],
@@ -3126,7 +3137,9 @@ function_exists('gzinflate') &&
31263137
}
31273138
if ($c = preg_match_all(
31283139
'/([Uu][Nn][Pp][Aa][Cc][Kk]\s*\(\s*["\']\s*H\*\s*["\']\s*,\s*["\'])([\da-fA-F]{1,4096})(["\']\s*\))/',
3129-
$str, $matches)) {
3140+
$str,
3141+
$matches
3142+
)) {
31303143
for ($i = 0; $c > $i; $i++) {
31313144
$str = str_replace($matches[0][$i], '"' . $this->Loader->hexSafe($this->Loader->substrBeforeLast($this->Loader->substrAfterFirst($matches[0][$i], $matches[1][$i]), $matches[3][$i])) . '"', $str);
31323145
}

0 commit comments

Comments
 (0)