Skip to content

Commit 89c5ab2

Browse files
authored
Fix: incorrect type in lib/html_utility.php and display_help format (#6887)
1 parent 76b2b69 commit 89c5ab2

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@ repos:
55
name: PHP Lint Checking
66
entry: composer run-script lint
77
language: system
8-
files: ^app/
98
always_run: true
109

1110
- id: phpcsfixer
1211
name: PHP CS Fixer Validation
1312
entry: composer run-script phpcsfixer
1413
language: system
15-
files: ^app/
1614
always_run: true
1715

1816
- id: phpstan
1917
name: PHPStan Validation
2018
entry: composer run-script phpstan
2119
language: system
22-
files: ^app/
2320
always_run: true

cli/add_site.php

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,19 @@
179179
case '--version':
180180
case '-V':
181181
case '-v':
182-
displayVersion();
182+
display_version();
183183

184184
exit;
185185
case '--help':
186186
case '-H':
187187
case '-h':
188-
displayHelp();
188+
display_help();
189189

190190
exit;
191191

192192
default:
193193
echoQuiet("ERROR: Invalid Argument: ($arg)\n\n" . PHP_EOL . PHP_EOL);
194-
displayHelp();
194+
display_help();
195195

196196
exit(1);
197197
}
@@ -215,7 +215,7 @@
215215
}
216216
}
217217
} else {
218-
displayHelp();
218+
display_help();
219219

220220
exit(0);
221221
}
@@ -437,7 +437,11 @@ function geocodeAddress(string $siteAddr1, string $siteAddr2, string $siteCity,
437437

438438
if (!$geocodeApiKey) {
439439
// Dont even try without the key
440-
displayHelp('Error: --geocode-api-key must be given with --geocode-address');
440+
print 'Error: --geocode-api-key must be given with --geocode-address' . PHP_EOL;
441+
442+
display_help();
443+
444+
exit(1);
441445
}
442446

443447
$requestUrl = sprintf('%s?address=%s,%s,%s,%s&key=%s', $googleApiUrl, urlencode($siteAddr1), urlencode($siteAddr2), urlencode($siteCity), urlencode($siteCountry), $geocodeApiKey);
@@ -511,12 +515,16 @@ function fetchCurl(string $url) : string|false {
511515
global $verbose, $debug, $httpsProxy;
512516

513517
if (!function_exists('curl_init')) {
514-
displayHelp('Error: cURL must be enabled in PHP if --geocode is specified.' . PHP_EOL . 'See http://php.net/manual/en/curl.setup.php for help.' . PHP_EOL);
518+
print 'Error: cURL must be enabled in PHP if --geocode is specified.' . PHP_EOL . 'See http://php.net/manual/en/curl.setup.php for help.' . PHP_EOL;
519+
520+
display_help();
521+
522+
exit(1);
515523
}
516524

517-
$curl = curl_init();
518-
$header[0] = 'Accept: text/xml,application/xml,application/json,application/xhtml+xml,';
519-
$header[0] .= 'text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
525+
$curl = curl_init();
526+
527+
$header[] = 'Accept: text/xml,application/xml,application/json,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5';
520528
$header[] = 'Cache-Control: max-age=0';
521529
$header[] = 'Connection: keep-alive';
522530
$header[] = 'Keep-Alive: 300';
@@ -535,13 +543,15 @@ function fetchCurl(string $url) : string|false {
535543
if ($verbose || $debug) {
536544
echoQuiet("Using HTTPS proxy: $httpsProxy" . PHP_EOL);
537545
}
546+
538547
curl_setopt($curl, CURLOPT_PROXY, $httpsProxy);
539548
}
540549

541550
$buffer = curl_exec($curl);
542551

543552
if ($buffer === false) {
544553
$error = curl_error($curl);
554+
545555
echoQuiet('Error: cURL request failed: ' . $error . PHP_EOL);
546556

547557
return false;
@@ -551,11 +561,11 @@ function fetchCurl(string $url) : string|false {
551561
}
552562

553563
/**
554-
* displayVersion - displays version information
564+
* display_version - displays version information
555565
*
556566
* @return void
557567
*/
558-
function displayVersion() : void {
568+
function display_version() : void {
559569
$version = get_cacti_cli_version();
560570
echoQuiet("Cacti Add Site Utility, Version $version, " . COPYRIGHT_YEARS . PHP_EOL);
561571
}
@@ -565,14 +575,10 @@ function displayVersion() : void {
565575
*
566576
* @return void
567577
*/
568-
function displayHelp(mixed $errorMessage = null) : void {
578+
function display_help() : void {
569579
global $log;
570580
$log = false;
571-
displayVersion();
572-
573-
if ($errorMessage) {
574-
echoQuiet("$errorMessage" . PHP_EOL . PHP_EOL);
575-
}
581+
display_version();
576582

577583
echoQuiet(PHP_EOL);
578584
echoQuiet('Usage: add_site.php [site-options] [--quiet]' . PHP_EOL . PHP_EOL);

lib/html_utility.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,9 +1423,9 @@ function get_order_string_page() : string {
14231423
*
14241424
* @param string $regex The regular expression to validate.
14251425
*
1426-
* @return true|string Returns true if the regular expression is valid, otherwise returns an error message string.
1426+
* @return bool|string Returns true if the regular expression is valid, otherwise returns an error message string.
14271427
*/
1428-
function validate_is_regex(string $regex) : true|string {
1428+
function validate_is_regex(string $regex) : bool|string {
14291429
if ($regex == '') {
14301430
return true;
14311431
}

0 commit comments

Comments
 (0)