From 4c5377c2c9d03acac04ccdfc9ec57ed0f926033f Mon Sep 17 00:00:00 2001
From: Stein Magne Bjorklund <steinmb@smbjorklund.com>
Date: Thu, 16 Sep 2021 09:59:23 +0200
Subject: [PATCH] Improve inline comments and do strict checks

We should not trust language " auto magic". Let us
be sure we do a strict type check.
---
 index.php | 32 +++++++++++++-------------------
 1 file changed, 13 insertions(+), 19 deletions(-)

diff --git a/index.php b/index.php
index 896e27a4..d4eb0337 100644
--- a/index.php
+++ b/index.php
@@ -1,4 +1,4 @@
-<?php
+<?php declare(strict_types=1);
 
 use uib\ub\loadspeakr\Endpoint;
 use uib\ub\loadspeakr\Exporter;
@@ -9,27 +9,23 @@ use uib\ub\loadspeakr\Utils;
 
 require_once __DIR__ . '/vendor/autoload.php';
 
-//Import
-if (isset($_GET['q']) && $_GET['q'] == 'import') {
-    include_once('classes/Importer.php');
+if (isset($_GET['q']) && $_GET['q'] === 'import') {
     $imp = new Importer();
     $imp->run();
     exit(0);
 }
 
-//Test if LODSPeaKr is configured
+// Check that application is installed.
 if (!file_exists('settings.inc.php')) {
     echo 'Need to configure lodspeakr first. Please run "install.sh". Alternatively, you can <a href="import">import an existing application</a>';
     exit(0);
 }
 
 include_once('common.inc.php');
-//Debug output
 
 $conf['logfile'] = null;
 if ($conf['debug']) {
-    include_once('classes/Logging.php');
-    if (isset($_GET['q']) && $_GET['q'] == 'logs') {
+    if (isset($_GET['q']) && $_GET['q'] === 'logs') {
         Logging::init();
         exit(0);
     } else {
@@ -54,13 +50,12 @@ $acceptContentType = Utils::getBestContentType($_SERVER['HTTP_ACCEPT'], $conf['h
 $extension = Utils::getExtension($acceptContentType, $conf['http_accept']);
 
 
-//Check content type is supported by LODSPeaKr
-if ($acceptContentType == null) {
+// Check that content type is supported by LODSPeaKr.
+if ($acceptContentType === null) {
     HTTPStatus::send406($uri);
 }
 
-//Export
-if ($conf['export'] && $_GET['q'] == 'export') {
+if ($conf['export'] && $_GET['q'] === 'export') {
     include_once('settings.inc.php');
     include_once('classes/Exporter.php');
     $exp = new Exporter();
@@ -69,22 +64,21 @@ if ($conf['export'] && $_GET['q'] == 'export') {
     exit(0);
 }
 
-//Redirect to root URL if necessary
+// Redirect to root URL if necessary.
 $uri = $conf['basedir'] . $_GET['q'];
 $localUri = $uri;
-if ($uri == $conf['basedir']) {
+if ($uri === $conf['basedir']) {
     header('Location: ' . $conf['root']);
     exit(0);
 }
 
 
-//Configure external URIs if necessary
+// Configure external URIs if necessary.
 $localUri = $conf['basedir'] . $_GET['q'];
 
 $uri = Utils::getMirroredUri($localUri);
 
-
-//Load Loadspeakr modules.
+// Load Loadspeakr modules.
 foreach ($conf['modules']['available'] as $i) {
     $className = $i . 'Module';
     $currentModule = $conf['modules']['directory'] . $className . '.php';
@@ -99,10 +93,10 @@ foreach ($conf['modules']['available'] as $i) {
     $module = new $namespacedClassName();
     $matching = $module->match($uri);
 
-    if ($matching != false) {
+    if ($matching !== false) {
         $module->execute($matching);
 
-        if ($conf['logfile'] != null) {
+        if ($conf['logfile'] !== null) {
             fwrite($conf['logfile'], "]}");
             fclose($conf['logfile']);
         }
-- 
GitLab