From f7001060eac9e6c7fddac23de327c989e4a9a77b Mon Sep 17 00:00:00 2001 From: Avior Date: Wed, 17 Apr 2019 01:29:08 +0200 Subject: [PATCH] Updated to respect PHPmd --- src/AdminPanel/AdminPanel.php | 6 +++--- src/AdminPanel/Authentificator.php | 6 +++--- src/AdminPanel/Controller.php | 6 ++++-- src/AdminPanel/Functions.php | 6 +++--- src/index.php | 5 +++-- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/AdminPanel/AdminPanel.php b/src/AdminPanel/AdminPanel.php index 2319ec7..17f3004 100644 --- a/src/AdminPanel/AdminPanel.php +++ b/src/AdminPanel/AdminPanel.php @@ -34,16 +34,16 @@ class AdminPanel */ public static function getInstance() { - if (!isset(AdminPanel::$instance)) { + if (!isset(self::$instance)) { define("ROOT", dirname(dirname(__DIR__))); - $ap = AdminPanel::$instance = new self(); + $ap = self::$instance = new self(); $ap->root = dirname(__DIR__); $ap->settings = jsonc_decode(dirname($ap->root) . "/config.jsonc", false); $ap->loader = new FilesystemLoader(); $ap->addLoaderFolder($ap->root . "/AdminPanel/Twig"); // $ap->setLoader(new FilesystemLoader()); } - return AdminPanel::$instance; + return self::$instance; } /** @var Logger $logger */ diff --git a/src/AdminPanel/Authentificator.php b/src/AdminPanel/Authentificator.php index 1e6c62e..b65fb22 100644 --- a/src/AdminPanel/Authentificator.php +++ b/src/AdminPanel/Authentificator.php @@ -9,10 +9,10 @@ class Authentificator private static $instance = null; public static function getInstance() { - if (!isset(Authentificator::$instance)) { - Authentificator::$instance = new self(); + if (!isset(self::$instance)) { + self::$instance = new self(); } - return Authentificator::$instance; + return self::$instance; } private $isLoggedIn = false; diff --git a/src/AdminPanel/Controller.php b/src/AdminPanel/Controller.php index 361aff4..db02d5a 100644 --- a/src/AdminPanel/Controller.php +++ b/src/AdminPanel/Controller.php @@ -41,12 +41,14 @@ class Controller protected function getHTTPGet(string $element, $default = null, $emptyAllowed = false) { - return isset($_GET[$element]) && (!empty($_GET[$element]) || $emptyAllowed) ? $_GET[$element] : $default; + $input = filter_input(INPUT_GET, $element); + return isset($input) && (!empty($input) || $emptyAllowed) ? $input : $default; } protected function getHTTPPost(string $element, $default = null, $emptyAllowed = false) { - return isset($_POST[$element]) && (!empty($_POST[$element]) || $emptyAllowed) ? $_POST[$element] : $default; + $input = filter_input(INPUT_POST, $element); + return isset($input) && (!empty($input) || $emptyAllowed) ? $input : $default; } protected function render($template, $args) diff --git a/src/AdminPanel/Functions.php b/src/AdminPanel/Functions.php index 2afc4e6..c3cf092 100644 --- a/src/AdminPanel/Functions.php +++ b/src/AdminPanel/Functions.php @@ -58,7 +58,7 @@ function slugEqualToURI($slug, $uri, $options) function getModulesJSON() { - $t = array(); + $temp = array(); $modulesDIR = "./Modules"; $modules = array_diff(scandir($modulesDIR), array('..', '.')); foreach ($modules as $module) { @@ -67,11 +67,11 @@ function getModulesJSON() if (is_dir($moduleDIR) && is_file($file)) { $json = json_decode(file_get_contents($file), true); if ($json) { - $t[$module] = $json; + $temp[$module] = $json; } } } - return $t; + return $temp; } function jsonc_decode($filename, $assoc = false, $depth = 512, $options = 0) diff --git a/src/index.php b/src/index.php index e261ac7..f76091f 100644 --- a/src/index.php +++ b/src/index.php @@ -23,7 +23,8 @@ $caches = $cache->getMultiple(array( )); //if cache don't exist create it! -if (!($ap->isCacheEnabled()) || $caches["routes"] === null || $caches['templates'] === null || $caches['forms'] === null) { +$cachesBool = $caches["routes"] === null || $caches['templates'] === null || $caches['forms'] === null; +if (!($ap->isCacheEnabled()) || $cachesBool ) { $modulesDIR = __DIR__ . "/Modules"; $modules = array_diff(scandir($modulesDIR), array('..', '.')); /** @var string $module */ @@ -73,7 +74,7 @@ foreach ($caches['templates'] as $key => $value) { } foreach ($caches['routes'] as $key => $value) { $args = isset($value->args) ? $value->args : new stdClass(); - $composants = slugEqualToURI($value->path, $_SERVER["REQUEST_URI"], $args); + $composants = slugEqualToURI($value->path, filter_input(INPUT_SERVER, "REQUEST_URI"), $args); // dump($composants !== false); if ($composants !== false) { if (isset($value->file)) {