Skip to content

Commit

Permalink
Update functions.php
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
tolgahanacar authored Aug 15, 2024
1 parent 8c7d0bb commit b590b5f
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions controller/functions.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
function HttpStatus($code)
{
$status = array(

function HttpStatus(int $code): string {
$status = [
100 => 'Continue',
101 => 'Switching Protocols',
200 => 'OK',
Expand Down Expand Up @@ -43,19 +43,16 @@ function HttpStatus($code)
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported'
);
return $status[$code] ? $status[$code] : $status[500];
];

return $status[$code] ?? $status[500];
}

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

function Security($value){
$trim = trim($value);
$strip_tags = strip_tags($trim);
$htmlspecialchars = htmlspecialchars($strip_tags, ENT_QUOTES);
$return = $htmlspecialchars;
return $return;
}
function Security(string $value): string {
return htmlspecialchars(strip_tags(trim($value)), ENT_QUOTES);
}

0 comments on commit b590b5f

Please sign in to comment.