Skip to content

Commit 797910c

Browse files
committed
More refactoring.
- Public before private methods.
1 parent f74f728 commit 797910c

File tree

2 files changed

+117
-117
lines changed

2 files changed

+117
-117
lines changed

src/CompressionHandler.php

+27-27
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: 2021.07.10).
11+
* This file: Compression handler (last modified: 2023.09.25).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -31,32 +31,6 @@ public function __construct(string $Data)
3131
$this->Data = $Data;
3232
}
3333

34-
/**
35-
* The basis for the other try methods.
36-
*
37-
* @param string $Using What the try methods uses.
38-
* @return int 0 = Success. 1 = Missing prerequisite. 2 = Failure.
39-
*/
40-
private function TryX(string $Using): int
41-
{
42-
/** Guard. */
43-
if (!function_exists($Using)) {
44-
return 1;
45-
}
46-
47-
/** Try to decompress. */
48-
$Try = $Using($this->Data);
49-
50-
/** Success. */
51-
if ($Try !== false && is_string($Try)) {
52-
$this->Data = $Try;
53-
return 0;
54-
}
55-
56-
/** Failure. */
57-
return 2;
58-
}
59-
6034
/**
6135
* Try to decompress using GZ.
6236
*
@@ -143,4 +117,30 @@ public function TryEverything(): bool
143117
*/
144118
return ($Original === $this->Data);
145119
}
120+
121+
/**
122+
* The basis for the other try methods.
123+
*
124+
* @param string $Using What the try methods uses.
125+
* @return int 0 = Success. 1 = Missing prerequisite. 2 = Failure.
126+
*/
127+
private function TryX(string $Using): int
128+
{
129+
/** Guard. */
130+
if (!function_exists($Using)) {
131+
return 1;
132+
}
133+
134+
/** Try to decompress. */
135+
$Try = $Using($this->Data);
136+
137+
/** Success. */
138+
if ($Try !== false && is_string($Try)) {
139+
$this->Data = $Try;
140+
return 0;
141+
}
142+
143+
/** Failure. */
144+
return 2;
145+
}
146146
}

src/Scanner.php

+90-90
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: 2023.09.23).
11+
* This file: The scanner (last modified: 2023.09.25).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -619,6 +619,95 @@ public function destroyScanDebugArray(&$Arr): void
619619
$Arr = null;
620620
}
621621

622+
/**
623+
* Writes to $HashReference, and performs any other needed hit-related actions.
624+
*
625+
* @param string $Hash The hash of the item which had a positive hit.
626+
* @param int $Size The size of the item which had a positive hit.
627+
* @param string $Name The name of the item which had a positive hit.
628+
* @param string $Text A human-readable explanation of the hit.
629+
* @param int $Code The integer results of the scan.
630+
* @param int $Depth The current depth of the scan process.
631+
* @return void
632+
*/
633+
public function atHit(string $Hash, int $Size = -1, string $Name = '', string $Text = '', int $Code = 2, int $Depth = 0): void
634+
{
635+
/** Fallback for missing item hash. */
636+
if ($Hash === '') {
637+
$Hash = $this->Loader->L10N->getString('response.Data not available');
638+
}
639+
640+
/** Fallback for missing item name. */
641+
if ($Name === '') {
642+
$Name = $this->Loader->L10N->getString('response.Data not available');
643+
}
644+
645+
/** Ensure that $Text doesn't break lines and clean it up. */
646+
$Text = preg_replace('~[\x00-\x1F]~', '', $Text);
647+
648+
/** Generate hash reference and key for various arrays to be populated. */
649+
$HashReference = sprintf('%s:%d:%s', $Hash, $Size, $Name);
650+
if (strpos($this->Loader->HashReference, $HashReference . "\n") === false) {
651+
$this->Loader->HashReference .= $HashReference . "\n";
652+
}
653+
654+
$TextLength = strlen($Text);
655+
656+
/** Scan results as text. */
657+
if ($TextLength && isset($this->Loader->ScanResultsText[$HashReference]) && strlen($this->Loader->ScanResultsText[$HashReference])) {
658+
$this->Loader->ScanResultsText[$HashReference] .= $this->Loader->L10N->getString('grammar_spacer') . $Text;
659+
} else {
660+
$this->Loader->ScanResultsText[$HashReference] = $Text;
661+
}
662+
663+
/** Scan results as integers. */
664+
if (empty($this->Loader->ScanResultsIntegers[$HashReference]) || $this->Loader->ScanResultsIntegers[$HashReference] !== 2) {
665+
$this->Loader->ScanResultsIntegers[$HashReference] = $Code;
666+
}
667+
668+
/** Increment detections count. */
669+
if ($Code !== 0 && $Code !== 1) {
670+
if (isset($this->Loader->InstanceCache['DetectionsCount'])) {
671+
$this->Loader->InstanceCache['DetectionsCount']++;
672+
} else {
673+
$this->Loader->InstanceCache['DetectionsCount'] = 1;
674+
}
675+
}
676+
677+
/** Indenting to apply for the formatted scan results . */
678+
$Indent = str_pad('', ($Depth < 1 ? 4 : ($Depth * 3) + 4), '', STR_PAD_LEFT);
679+
680+
/** Fallback for missing text for formatted text. */
681+
if ($TextLength === 0) {
682+
if ($Code === 0) {
683+
$Text = sprintf(
684+
$this->Loader->L10N->getString('grammar_exclamation_mark'),
685+
sprintf($this->Loader->L10N->getString('response.%s does not exist'), $Name)
686+
);
687+
} elseif ($Code === 1) {
688+
$Text = $this->Loader->L10N->getString('response.No problems found');
689+
} else {
690+
$Text = $this->Loader->L10N->getString('response.Data not available');
691+
}
692+
}
693+
694+
if ($this->CalledFrom === 'CLI') {
695+
if ($Code === 1) {
696+
$Text = "\033[0;92m" . $Text . "\033[0;33m";
697+
} elseif ($Code === 2 || $Code < 0) {
698+
$Text = "\033[0;91m" . $Text . "\033[0;33m";
699+
} else {
700+
$Text = "\033[0;90m" . $Text . "\033[0;33m";
701+
}
702+
}
703+
704+
/** Scan results as formatted text. */
705+
$this->Loader->ScanResultsFormatted .= $Indent . $Text . "\n";
706+
707+
/** Update flags. */
708+
$this->Loader->InstanceCache['CheckWasLast'] = false;
709+
}
710+
622711
/**
623712
* Responsible for recursing through any files given to it to be scanned, which
624713
* may be necessary for the case of archives and directories. It performs the
@@ -3931,93 +4020,4 @@ private function resetHeuristics(): void
39314020
$this->HeuristicCount = 0;
39324021
$this->HeuristicMode = false;
39334022
}
3934-
3935-
/**
3936-
* Writes to $HashReference, and performs any other needed hit-related actions.
3937-
*
3938-
* @param string $Hash The hash of the item which had a positive hit.
3939-
* @param int $Size The size of the item which had a positive hit.
3940-
* @param string $Name The name of the item which had a positive hit.
3941-
* @param string $Text A human-readable explanation of the hit.
3942-
* @param int $Code The integer results of the scan.
3943-
* @param int $Depth The current depth of the scan process.
3944-
* @return void
3945-
*/
3946-
public function atHit(string $Hash, int $Size = -1, string $Name = '', string $Text = '', int $Code = 2, int $Depth = 0): void
3947-
{
3948-
/** Fallback for missing item hash. */
3949-
if ($Hash === '') {
3950-
$Hash = $this->Loader->L10N->getString('response.Data not available');
3951-
}
3952-
3953-
/** Fallback for missing item name. */
3954-
if ($Name === '') {
3955-
$Name = $this->Loader->L10N->getString('response.Data not available');
3956-
}
3957-
3958-
/** Ensure that $Text doesn't break lines and clean it up. */
3959-
$Text = preg_replace('~[\x00-\x1F]~', '', $Text);
3960-
3961-
/** Generate hash reference and key for various arrays to be populated. */
3962-
$HashReference = sprintf('%s:%d:%s', $Hash, $Size, $Name);
3963-
if (strpos($this->Loader->HashReference, $HashReference . "\n") === false) {
3964-
$this->Loader->HashReference .= $HashReference . "\n";
3965-
}
3966-
3967-
$TextLength = strlen($Text);
3968-
3969-
/** Scan results as text. */
3970-
if ($TextLength && isset($this->Loader->ScanResultsText[$HashReference]) && strlen($this->Loader->ScanResultsText[$HashReference])) {
3971-
$this->Loader->ScanResultsText[$HashReference] .= $this->Loader->L10N->getString('grammar_spacer') . $Text;
3972-
} else {
3973-
$this->Loader->ScanResultsText[$HashReference] = $Text;
3974-
}
3975-
3976-
/** Scan results as integers. */
3977-
if (empty($this->Loader->ScanResultsIntegers[$HashReference]) || $this->Loader->ScanResultsIntegers[$HashReference] !== 2) {
3978-
$this->Loader->ScanResultsIntegers[$HashReference] = $Code;
3979-
}
3980-
3981-
/** Increment detections count. */
3982-
if ($Code !== 0 && $Code !== 1) {
3983-
if (isset($this->Loader->InstanceCache['DetectionsCount'])) {
3984-
$this->Loader->InstanceCache['DetectionsCount']++;
3985-
} else {
3986-
$this->Loader->InstanceCache['DetectionsCount'] = 1;
3987-
}
3988-
}
3989-
3990-
/** Indenting to apply for the formatted scan results . */
3991-
$Indent = str_pad('', ($Depth < 1 ? 4 : ($Depth * 3) + 4), '', STR_PAD_LEFT);
3992-
3993-
/** Fallback for missing text for formatted text. */
3994-
if ($TextLength === 0) {
3995-
if ($Code === 0) {
3996-
$Text = sprintf(
3997-
$this->Loader->L10N->getString('grammar_exclamation_mark'),
3998-
sprintf($this->Loader->L10N->getString('response.%s does not exist'), $Name)
3999-
);
4000-
} elseif ($Code === 1) {
4001-
$Text = $this->Loader->L10N->getString('response.No problems found');
4002-
} else {
4003-
$Text = $this->Loader->L10N->getString('response.Data not available');
4004-
}
4005-
}
4006-
4007-
if ($this->CalledFrom === 'CLI') {
4008-
if ($Code === 1) {
4009-
$Text = "\033[0;92m" . $Text . "\033[0;33m";
4010-
} elseif ($Code === 2 || $Code < 0) {
4011-
$Text = "\033[0;91m" . $Text . "\033[0;33m";
4012-
} else {
4013-
$Text = "\033[0;90m" . $Text . "\033[0;33m";
4014-
}
4015-
}
4016-
4017-
/** Scan results as formatted text. */
4018-
$this->Loader->ScanResultsFormatted .= $Indent . $Text . "\n";
4019-
4020-
/** Update flags. */
4021-
$this->Loader->InstanceCache['CheckWasLast'] = false;
4022-
}
40234023
}

0 commit comments

Comments
 (0)