Skip to content

Commit

Permalink
PUSH
Browse files Browse the repository at this point in the history
-> Add lint
-> More work!
  • Loading branch information
NaysKutzu committed Jul 24, 2024
1 parent 467a518 commit 40a2887
Show file tree
Hide file tree
Showing 94 changed files with 4,045 additions and 1,503 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Lint

on:
push:
branches:
- "develop"
- "1.0-develop"
pull_request:
branches:
- "develop"
- "1.0-develop"

jobs:
lint:
name: Lint
runs-on: ubuntu-20.04
steps:
- name: Code Checkout
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.3"
extensions: bcmath, curl, gd, mbstring, mysql, openssl, pdo, tokenizer, xml, zip
tools: composer:v2
coverage: none

- name: Install dependencies
run: composer install --no-interaction --no-progress --no-suggest --prefer-dist

- name: PHP CS Fixer (APP)
run: vendor/bin/php-cs-fixer fix app --dry-run

- name: PHP CS Fixer (Tests)
run: vendor/bin/php-cs-fixer fix tests --dry-run
- name: PHP CS Fixer (Routes)
run: vendor/bin/php-cs-fixer fix routes --dry-run
- name: PHP CS Fixer (Lang)
run: vendor/bin/php-cs-fixer fix lang --dry-run
- name: PHP CS Fixer (Cron)
run: vendor/bin/php-cs-fixer fix lang --dry-run
- name: PHP CS Fixer (API)
run: vendor/bin/php-cs-fixer fix api --dry-run
- name: PHP CS Fixer (Addons)
run: vendor/bin/php-cs-fixer fix addons --dry-run
- name: PHP CS Fixer (Commands)
run: vendor/bin/php-cs-fixer fix commands --dry-run
- name: PHP CS Fixer (Install)
run: vendor/bin/php-cs-fixer fix install --dry-run
- name: PHP CS Fixer (Public)
run: vendor/bin/php-cs-fixer fix public --dry-run
- name: PHP CS Fixer (Migrate)
run: vendor/bin/php-cs-fixer fix migrate --dry-run
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ composer.phar
/test.json
/caches/*/
caches/last_settings_migrate_run
.php-cs-fixer.cache
3 changes: 0 additions & 3 deletions addons/Example/Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@

class Example
{

public function Main(array $args = [])
{

}
}

?>
7 changes: 4 additions & 3 deletions api/System/logs.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php

use MythicalSystems\Api\Api as api;
use MythicalSystemsFramework\Kernel\Logger;
use MythicalSystemsFramework\Kernel\LoggerTypes;
Expand All @@ -9,6 +10,6 @@

if ($_SERVER['REQUEST_METHOD'] === 'GET') {
api::OK("Showing you latest logs", [
"logs" => Logger::getAllSortedByDate(LoggerTypes::OTHER, LoggerLevels::OTHER,10)
"logs" => Logger::getAllSortedByDate(LoggerTypes::OTHER, LoggerLevels::OTHER, 10)
]);
}
}
5 changes: 2 additions & 3 deletions api/User/login.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php


use MythicalSystems\Api\Api as api;
use MythicalSystemsFramework\Managers\ConfigManager as cfg;
Expand All @@ -9,5 +10,3 @@
if (isset($_POST['email']) && isset($_POST['password'])) {

}

?>
3 changes: 2 additions & 1 deletion app/Cli/Colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ public static function Underline(): string
return "\033[4m";
}

public static function NewLine() : string {
public static function NewLine(): string
{
return "\n";
}

Expand Down
16 changes: 16 additions & 0 deletions app/Cli/Commands/Colors.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace MythicalSystemsFramework\Cli\Commands;

class Colors extends Command
{
public static string $description = 'A command to display the supported colors!';

public static function execute(bool $isFrameworkCommand = false): void
{
$colors = "Colors: &0Black&r, &1Dark Blue&r, &2Dark Green&r, &3Dark Aqua&r, &4Dark Red&r, &5Dark Purple&r, &6Gold&r, &7Gray&r, &8Dark Gray&r, &9Blue&r, &aGreen&r, &bAqua&r, &cRed&r, &dLight Purple&r, &eYellow&r, &fWhite&r, &rReset&r, &lBold&r, &nUnderline&r, &mStrikethrough&r";
echo self::translateColorsCode($colors);
echo PHP_EOL;
echo str_replace('&r', '', $colors);
}
}
72 changes: 72 additions & 0 deletions app/Cli/Commands/Command.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace MythicalSystemsFramework\Cli\Commands;

use MythicalSystemsFramework\Cli\Kernel;

class Command extends Kernel
{
public static string $description = 'A example command :)';

public static function execute(bool $isFrameworkCommand = false): void
{
/**
* This method should be overridden in the child class.
*/
echo self::translateColorsCode("Command executed &asuccessfully&r!");

}
/**
* Logs a success message to the console.
*
* @requires \MythicalSystemsFramework\Cli\Commands\Colors
*
* @param string $message The message to log.
*
* @return void
*/
public static function log_success(string $message): void
{
echo self::translateColorsCode("&a$message&r&o");
}
/**
* Logs a error message to the console.
*
* @requires \MythicalSystemsFramework\Cli\Commands\Colors
*
* @param string $message The message to log.
*
* @return void
*/
public static function log_error(string $message): void
{
echo self::translateColorsCode("&c$message&r&o");
}
/**
* Logs a warning message to the console.
*
* @requires \MythicalSystemsFramework\Cli\Commands\Colors
*
* @param string $message The message to log.
*
* @return void
*/
public static function log_warning(string $message): void
{
echo self::translateColorsCode("&e$message&r&o");
}
/**
* Logs a info message to the console.
*
* @requires \MythicalSystemsFramework\Cli\Commands\Colors
*
* @param string $message The message to log.
*
* @return void
*/
public static function log_info(string $message): void
{
echo self::translateColorsCode("&7$message&r&o");
}

}
99 changes: 99 additions & 0 deletions app/Cli/Commands/Configure.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

namespace MythicalSystemsFramework\Cli\Commands;

use Exception;
use MythicalSystemsFramework\Database\MySQL;
use MythicalSystemsFramework\Managers\ConfigManager as cfg;
use MythicalSystemsFramework\Managers\Settings;

class Configure extends Command
{
public static string $description = 'A command that can help if you want to configure the app!';
public static function execute(bool $isFrameworkCommand = false): void
{
echo self::log_info("");
echo self::log_info("&c1.&7 Configure the database");
echo self::log_info("&c2.&7 Configure the app");
echo self::log_info("&c3.&7 Exit");
echo self::log_info("");

$option = readline("Select an option: ");

switch ($option) {
case '1':
self::dbconfigure();
break;
case '2':
self::configure();
break;
case '3':
self::exit();
break;
default:
echo "Invalid option selected.";
break;
}
}

public static function dbconfigure(): void
{
if (cfg::get("database", "password") !== null) {
echo self::translateColorsCode("&fDatabase configuration already exists. &oWould you like to overwrite it? &8[&aY&8/&cN&8]&f: ");
$overwrite = readline();
if (strtolower($overwrite) !== "y") {
return;
}
}
$defaultHost = "127.0.0.1";
$defaultPort = "3306";
$db = new MySQL();
echo self::translateColorsCode("&fEnter the host of the database &8[&e$defaultHost&8]&f: ");
$host = readline() ?: $defaultHost;
echo self::translateColorsCode("&fEnter the port of the database &8[&e$defaultPort&8]&f: ");
$port = readline() ?: $defaultPort;
echo self::translateColorsCode("&fEnter the username: ");
$username = readline();
echo self::translateColorsCode("&fEnter the password: ");
$password = readline();
echo self::translateColorsCode("&fEnter the database name: ");
$database = readline();
// Perform validation
if (empty($username) || empty($password) || empty($database)) {
echo self::translateColorsCode("&cPlease provide all the required information.&o");
return;
}

// Hide the password
$hiddenPassword = str_repeat('*', strlen($password));

// Use the provided information
echo self::NewLine();
echo self::translateColorsCode("&fHost: &e$host&o");
echo self::translateColorsCode("&fPort: &e$port&o");
echo self::translateColorsCode("&fUsername: &e$username&o");
echo self::translateColorsCode("&fPassword: &e$hiddenPassword&o");
echo self::translateColorsCode("&fDatabase: &e$database&o");

if ($db->tryConnection($host, $port, $username, $password, $database) == true) {
echo self::NewLine();
echo self::translateColorsCode("&fConnection to the database was &asuccessful!&o");
echo self::NewLine();
echo self::translateColorsCode("&fSaving the configuration...&o");
cfg::set("database", "host", $host);
cfg::set("database", "port", $port);
cfg::set("database", "username", $username);
cfg::set("database", "password", $password);
cfg::set("database", "name", $database);
echo self::translateColorsCode("&fConfiguration saved &asuccessfully!&o");
} else {
echo self::translateColorsCode("&7Failed to connect to the database. &o&fPlease check the provided information.");
}

}

public static function configure(): void
{

}
}
21 changes: 21 additions & 0 deletions app/Cli/Commands/Down.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace MythicalSystemsFramework\Cli\Commands;

use MythicalSystemsFramework\Managers\ConfigManager as cfg;

class Down extends Command
{
public static string $description = 'Mark the application as down.';

public static function execute(bool $isFrameworkCommand = false): void
{
echo self::log_info("Marking the application as down...");
if (cfg::get('app', 'maintenance') == "true" && cfg::get('app', 'maintenance') != "false") {
echo self::translateColorsCode("&aApplication &ris already in maintenance mode!");
return;
}
cfg::set('app', 'maintenance', "true");
echo self::log_success("Application is now down!");
}
}
35 changes: 35 additions & 0 deletions app/Cli/Commands/Help.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace MythicalSystemsFramework\Cli\Commands;

class Help extends Command
{
public static string $description = 'The help command to get info about other commands!';

public static function execute(bool $isFrameworkCommand = false): void
{
echo self::log_info("");
echo self::log_info("-----------------------");
echo self::log_info("| Available commands: |");
echo self::log_info("-----------------------");
echo self::log_info("");

$commands = scandir(__DIR__);
foreach ($commands as $command) {
if ($command === '.' || $command === '..' || $command === 'Command.php') {
continue;
}

$command = str_replace('.php', '', $command);
$commandClass = "MythicalSystemsFramework\\Cli\\Commands\\$command";
$reflectionClass = new \ReflectionClass($commandClass);

if (!$reflectionClass->hasProperty('description')) {
continue;
}

echo self::log_info("{$command} > {$reflectionClass->getProperty('description')->getValue()}");
}
echo self::log_info("");
}
}
Loading

0 comments on commit 40a2887

Please sign in to comment.