Skip to content

Commit

Permalink
refactor: enhances code
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudLigny committed Aug 28, 2024
1 parent 66dd0ec commit 622b92f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
16 changes: 8 additions & 8 deletions resources/server/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
}
mb_internal_encoding('UTF-8');

define('SERVER_TMP_DIR', '.cecil');
define('DIRECTORY_INDEX', '/index.html');
define('ERROR_404', '/404.html');
\define('SERVER_TMP_DIR', '.cecil');
\define('DIRECTORY_INDEX', '/index.html');
\define('ERROR_404', '/404.html');
$isIndex = null;
$mediaSubtypeText = ['javascript', 'xml', 'json', 'ld+json', 'csv'];

Expand Down Expand Up @@ -68,7 +68,7 @@
}
// is 404.html exists in a (language) sub dir?
$pathAsArray = explode('/', $path);
if (count($pathAsArray) > 2) {
if (\count($pathAsArray) > 2) {
$subDir = '/' . $pathAsArray[1];
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $subDir . ERROR_404)) {
$path404 = $subDir . ERROR_404;
Expand Down Expand Up @@ -109,7 +109,7 @@
$content = file_get_contents($filename);
$pathInfo = getPathInfo($path);
// text content
if ($pathInfo['media_maintype'] == 'text' || in_array($pathInfo['media_subtype'], $mediaSubtypeText)) {
if ($pathInfo['media_maintype'] == 'text' || \in_array($pathInfo['media_subtype'], $mediaSubtypeText)) {
// replaces the "live" baseurl by the "local" baseurl
$baseurl = explode(';', trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/../' . SERVER_TMP_DIR . '/baseurl')));
if (strstr($baseurl[0], 'http') !== false || $baseurl[0] != '/') {
Expand Down Expand Up @@ -147,8 +147,8 @@
// logger + return
function logger(bool $return): bool
{
\error_log(
\sprintf("%s:%d [%d]: %s\n", $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], \http_response_code(), $_SERVER['REQUEST_URI']),
error_log(
\sprintf("%s:%d [%d]: %s\n", $_SERVER['REMOTE_ADDR'], $_SERVER['REMOTE_PORT'], http_response_code(), $_SERVER['REQUEST_URI']),
3,
$_SERVER['DOCUMENT_ROOT'] . '/../' . SERVER_TMP_DIR . '/server.log'
);
Expand All @@ -160,7 +160,7 @@ function logger(bool $return): bool
function getPathInfo(string $path): array
{
$filename = $_SERVER['DOCUMENT_ROOT'] . $path;
$mediaType = \mime_content_type($filename); // e.g.: "text/html"
$mediaType = mime_content_type($filename); // e.g.: "text/html"
$info = [
'media_maintype' => explode('/', $mediaType)[0], // e.g.: "text"
'media_subtype' => explode('/', $mediaType)[1], // e.g.: "html"
Expand Down
7 changes: 5 additions & 2 deletions tests/IntegrationTests.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

/*
* Copyright (c) Arnaud Ligny <arnaud@ligny.org>
* This file is part of Cecil.
*
* Copyright (c) Arnaud Ligny <arnaud@ligny.fr>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -18,7 +21,7 @@ class IntegrationTests extends \PHPUnit\Framework\TestCase
protected $wsSourceDir;
protected $config;
protected $wsDestinationDir;
const DEBUG = false;
public const DEBUG = false;

public function setUp(): void
{
Expand Down

0 comments on commit 622b92f

Please sign in to comment.