Skip to content

Commit 144c8bc

Browse files
committed
Type and simplify is_known_*() helpers
1 parent 3707f9a commit 144c8bc

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

include/errors.inc

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ The most commonly searched terms have also been added.
123123
TODO: Determine if we want to continue 301 -OR- make these official URLs.
124124
******************************************************************************/
125125

126-
function is_known_ini ($ini) {
127-
$inis = array(
126+
function is_known_ini (string $ini): ?string {
127+
$inis = [
128128
'engine' => 'apache.configuration.php#ini.engine',
129129
'short-open-tag' => 'ini.core.php#ini.short-open-tag',
130130
'asp-tags' => 'ini.core.php#ini.asp-tags',
@@ -345,13 +345,13 @@ $inis = array(
345345
'soap.wsdl-cache-enabled' => 'soap.configuration.php#ini.soap.wsdl-cache-enabled',
346346
'soap.wsdl-cache-dir' => 'soap.configuration.php#ini.soap.wsdl-cache-dir',
347347
'soap.wsdl-cache-ttl' => 'soap.configuration.php#ini.soap.wsdl-cache-ttl',
348-
);
348+
];
349349

350-
return isset($inis[$ini]) ? $inis[$ini] : false;
350+
return $inis[$ini] ?? null;
351351
}
352352

353-
function is_known_variable($variable) {
354-
$variables = array(
353+
function is_known_variable(string $variable): ?string {
354+
$variables = [
355355
// Variables
356356
'globals' => 'reserved.variables.globals.php',
357357
'-server' => 'reserved.variables.server.php',
@@ -375,18 +375,13 @@ $variables = array(
375375
'http-post-files' => 'reserved.variables.files.php',
376376
'http-cookie-vars' => 'reserved.variables.cookies.php',
377377
'http-env-vars' => 'reserved.variables.env.php',
378-
);
379-
380-
if ($variable[0] === '$') {
381-
$variable = ltrim($variable, '$');
382-
}
383-
384-
return isset($variables[$variable]) ? $variables[$variable] : false;
378+
];
385379

380+
return $variables[ltrim($variable, '$')] ?? null;
386381
}
387382

388-
function is_known_term ($term) {
389-
$terms = array(
383+
function is_known_term (string $term): ?string {
384+
$terms = [
390385
'<>' => 'language.operators.comparison.php',
391386
'==' => 'language.operators.comparison.php',
392387
'===' => 'language.operators.comparison.php',
@@ -458,9 +453,9 @@ $terms = array(
458453
'timestamp' => 'function.time.php',
459454
'try' => 'language.exceptions.php',
460455
'upload' => 'features.file-upload.php',
461-
);
456+
];
462457

463-
return isset($terms[$term]) ? $terms[$term] : false;
458+
return $terms[$term] ?? null;
464459
}
465460

466461
/*
@@ -473,8 +468,8 @@ Search snippet provider: A dirty proof-of-concept:
473468
It should also take into account vague searches, such as 'global' and 'str'. The search works well enough for,
474469
most terms, so something like $_SERVER isn't really needed but it's defined below anyways...
475470
*/
476-
function is_known_snippet($term) {
477-
$snippets = array(
471+
function is_known_snippet(string $term): ?string {
472+
$snippets = [
478473
'global' => '
479474
The <b>global</b> keyword is used to manipulate <a href="/language.variables.scope">variable scope</a>, and
480475
there is also the concept of <a href="/language.variables.superglobals">super globals</a> in PHP,
@@ -497,10 +492,10 @@ $snippets = array(
497492
<a href="/language.functions">function is defined</a>, or
498493
<a href="/about.prototypes">how to read a function prototype</a>.
499494
See also the list of <a href="/extensions">PHP extensions</a>',
500-
);
495+
];
501496

502497
$term = ltrim(strtolower(trim($term)), '$');
503-
return $snippets[$term] ?? false;
498+
return $snippets[$term] ?? null;
504499
}
505500

506501
/**

0 commit comments

Comments
 (0)