Skip to content

Commit

Permalink
Code linting
Browse files Browse the repository at this point in the history
  • Loading branch information
ToX82 committed Sep 16, 2023
1 parent 1e3331b commit 2642c8f
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 28 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"autoload": {
"psr-4": {"logics\\": "logics/"}
"psr-4": {"Logics\\": "logics/"}
},
"require-dev": {
"fig-r/psr2r-sniffer": "^0.6.3",
"phpstan/phpstan": "^0.12.99"
"phpstan/phpstan": "*"
},
"require": {
"fightbulc/moment": "^1.33"
Expand Down
8 changes: 8 additions & 0 deletions libs/libs.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ function init()
setting('refresh');
setting('page-length');

define('BASE_URL', baseUrl() . "/");

if (!is_file(ROOT . 'vendor/autoload.php')) {
echo file_get_contents(ROOT . 'webroot/firstrun.html');
die;
}
require_once ROOT . 'vendor/autoload.php';

error_reporting(E_ALL ^ E_DEPRECATED);
}

Expand Down
10 changes: 2 additions & 8 deletions libs/paths.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?php

define('BASE_URL', baseUrl() . "/");

if (!is_file(ROOT . 'vendor/autoload.php')) {
echo file_get_contents(ROOT . 'webroot/firstrun.html');
die;
}
require_once ROOT . 'vendor/autoload.php';

/**
* Check if a GET variable exists
*
Expand Down Expand Up @@ -125,6 +117,8 @@ function checkPage($page, $class)
if (strpos(getPageParams(), $page) !== false) {
return $class;
}

return '';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion libs/utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,4 @@ function normalizeChars($inputString)
$real_chars = array_values($fix_list);

return str_replace($error_chars, $real_chars, $inputString);
}
}
25 changes: 20 additions & 5 deletions logics/Configurations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ class Configurations
/**
* Retrieves configurations from a JSON file.
*
* @param string $filePath The path to the JSON file.
* @return array Returns an array of configurations.
* @return object Returns an array of configurations.
*/
public function getConfigurations()
{
Expand Down Expand Up @@ -51,6 +50,12 @@ public function saveConfig()
}
}

/**
* Duplicates a configuration file with a new name.
*
* @param string $configName The name of the configuration file to be duplicated.
* @return void
*/
public function duplicateConfig($configName)
{
if (preg_match('/_copy_(\d+)/', $configName, $matches)) {
Expand All @@ -75,7 +80,6 @@ public function duplicateConfig($configName)
* Deletes a configuration by name from the config file.
*
* @param string $configName The name of the configuration to delete.
* @throws Some_Exception_Class Description of the exception that can be thrown.
* @return void
*/
public function deleteConfig($configName)
Expand All @@ -95,7 +99,6 @@ public function deleteConfig($configName)
* Replaces all occurrences of '/' with '//' in the contents of a file.
*
* @param string $filename The path to the file.
* @throws Exception If the file cannot be read or written.
* @return string The path to the modified file.
*/
public function replaceSlash($filename)
Expand Down Expand Up @@ -161,6 +164,12 @@ public function checkFileExists($filename)
return file_exists($filename);
}

/**
* Change the visibility of a configuration.
*
* @param string $configName The name of the configuration to change.
* @return void
*/
public function changeVisibility($configName)
{
$configurations = $this->getConfigurations();
Expand All @@ -170,6 +179,13 @@ public function changeVisibility($configName)
file_put_contents(ROOT . '/config.json', $jsonData);
}

/**
* Generates the starter config file for the application.
*
* This function creates a new config file in the ROOT directory and
* populates it with the default configurations. It also sets the
* necessary permissions on the config file.
*/
public function starterConfigFile()
{
if (is_writeable(ROOT)) {
Expand All @@ -187,5 +203,4 @@ public function starterConfigFile()
reload('/display/create-config-writeable');
}
}

}
13 changes: 9 additions & 4 deletions logics/Parsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ class Parsers
public $config = '';

/**
* __construct
* Constructor for the class.
*
* @param string $jsonFile The path to the JSON file.
* @return void
*/
public function __construct($jsonFile)
{
Expand Down Expand Up @@ -99,17 +102,18 @@ public function countAll()
* Counts the number of entries for a given log file
*
* @param string $file Log file
* @return int
* @return int|string
*/
public function count($file)
{
$logs = [];
$data = $this->config[$file];
$file = ROOT . "parsers/" . $data['parser'] . ".php";
if (is_file($file)) {
include $file;
}

if (!isset($logs) || count($logs) === 0) {
if (count($logs) === 0) {
return '';
}

Expand Down Expand Up @@ -145,11 +149,12 @@ public function view($file)
*/
public function entries($file, $offset = 0, $limit = 10, $search = '')
{
$logs = [];
$data = $this->config[$file];
include ROOT . "parsers/" . $data['parser'] . ".php";

// We want the records ordered from the newest to the oldest
if (!empty($logs)) {
if (count($logs) > 0) {
$logs = array_reverse($logs);
}

Expand Down
12 changes: 12 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<ruleset name="App">
<rule ref="PSR12"/>
<exclude-pattern>/vendor/*</exclude-pattern>

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="150"/>
<property name="absoluteLineLimit" value="150"/>
</properties>
</rule>
</ruleset>
12 changes: 6 additions & 6 deletions routers/router.ajax.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?php

$objParsers = new logics\Parsers(ROOT . "config.json");
$objParsers = new Logics\Parsers(ROOT . "config.json");
$return = null;

if (isset($_GET['countall'])) {
$return = $objParsers->countAll();
$return = json_encode($return);
}
if (isset($_GET['viewlog'])) {
$file = filter_var($_GET['file'], FILTER_SANITIZE_STRING);
$file = filter_var($_GET['file'], FILTER_DEFAULT);
$offset = filter_var($_GET['start'], FILTER_SANITIZE_NUMBER_INT);
$limit = filter_var($_GET['length'], FILTER_SANITIZE_NUMBER_INT);
$search = filter_var($_GET['search']['value'], FILTER_SANITIZE_STRING);
$search = filter_var($_GET['search']['value'], FILTER_DEFAULT);
$return = $objParsers->entries($file, $offset, $limit, $search);
$return = include(ROOT . 'views/parsers/getdata.php');
}
if (isset($_GET['check-file-exists'])) {
$objConfig = new logics\Configurations();
$filename = filter_var($_POST['filename'], FILTER_SANITIZE_STRING);
$objConfig = new Logics\Configurations();
$filename = filter_var($_POST['filename'], FILTER_DEFAULT);
$return = $objConfig->checkFileExists($filename);
$return = json_encode($return);
}
if (isset($_GET['change-visibility'])) {
$objConfig = new logics\Configurations();
$objConfig = new Logics\Configurations();
$return = $objConfig->changeVisibility($_POST['configName']);

$return = json_encode($return);
Expand Down
4 changes: 2 additions & 2 deletions routers/router.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

$params = splitQueryParams();
$objParsers = new logics\Parsers(ROOT . "config.json");
$objParsers = new Logics\Parsers(ROOT . "config.json");

// Array con le pagine di template da includere
$views = [];
Expand Down Expand Up @@ -43,7 +43,7 @@
}
}

$file = logics\Pages::display($displayPage);
$file = Logics\Pages::display($displayPage);
$views[] = ROOT . $file;
}

Expand Down

0 comments on commit 2642c8f

Please sign in to comment.