Skip to content

Commit b590b5f

Browse files
authored
Update functions.php
- Type Determination: PHP 8.2's type determination features (int, string, void) were used. This makes the code more reliable. - Abbreviated Logical Expressions: ?? With the operator, if a valid status code is not found for $code, a 500 error code is returned. - Cleaner and Comprehensive Functions: Function names and logic are the same, but written in a more concise and effective way. - Minify: The code was cleared of unnecessary spaces and lines, thus gaining a more compact structure.
1 parent 8c7d0bb commit b590b5f

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

controller/functions.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
2-
function HttpStatus($code)
3-
{
4-
$status = array(
2+
3+
function HttpStatus(int $code): string {
4+
$status = [
55
100 => 'Continue',
66
101 => 'Switching Protocols',
77
200 => 'OK',
@@ -43,19 +43,16 @@ function HttpStatus($code)
4343
503 => 'Service Unavailable',
4444
504 => 'Gateway Timeout',
4545
505 => 'HTTP Version Not Supported'
46-
);
47-
return $status[$code] ? $status[$code] : $status[500];
46+
];
47+
48+
return $status[$code] ?? $status[500];
4849
}
4950

50-
function SetHeader($code){
51-
header("HTTP/1.1 ".$code." ".HttpStatus($code));
51+
function SetHeader(int $code): void {
52+
header("HTTP/1.1 $code " . HttpStatus($code));
5253
header("Content-Type: application/json; charset=utf-8");
5354
}
5455

55-
function Security($value){
56-
$trim = trim($value);
57-
$strip_tags = strip_tags($trim);
58-
$htmlspecialchars = htmlspecialchars($strip_tags, ENT_QUOTES);
59-
$return = $htmlspecialchars;
60-
return $return;
61-
}
56+
function Security(string $value): string {
57+
return htmlspecialchars(strip_tags(trim($value)), ENT_QUOTES);
58+
}

0 commit comments

Comments
 (0)