From a31dff94cb1b46530f65fe414aa90de5a9ee9515 Mon Sep 17 00:00:00 2001 From: Are0h Date: Mon, 16 May 2022 19:14:38 -0700 Subject: [PATCH] Updated PHP lint to @PSR12 b/c @PSR2 is deprecated So, @PSR12 is the recommended coding standard, so I updated the config and reformatted the appropriate files. Again. Whew. --- .php-cs-fixer.php | 9 +++++---- brain/api/v1/AuthAPI.php | 5 +++++ brain/api/v1/ImagesAPI.php | 1 + brain/api/v1/InitAPI.php | 1 + brain/api/v1/MailerAPI.php | 1 + brain/api/v1/PagesAPI.php | 3 +++ brain/api/v1/SettingsAPI.php | 6 +++++- brain/controller/APIControl.php | 1 + brain/controller/IndexControl.php | 1 + brain/controller/RouteControl.php | 1 + brain/data/Auth.php | 11 ++++++++--- brain/data/Book.php | 6 ++++++ brain/data/Contents.php | 24 ++++++++++++++---------- brain/data/Member.php | 3 +++ brain/data/Render.php | 9 +++++++++ brain/data/Session.php | 11 +++++++++-- brain/data/Settings.php | 11 +++++++++++ brain/data/Themes.php | 3 +++ brain/utility/DocTools.php | 5 +++++ brain/utility/Maintenance.php | 1 + brain/utility/Setup.php | 2 ++ brain/utility/Sorting.php | 14 +++++++------- brain/utility/StringTools.php | 4 ++++ 23 files changed, 106 insertions(+), 27 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 7f73a4c..adf5ae8 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -2,7 +2,7 @@ return (new PhpCsFixer\Config()) ->setRules([ - '@PSR2' => true, + '@PSR12' => true, 'array_indentation' => true, 'array_syntax' => [ 'syntax' => 'short', @@ -11,8 +11,10 @@ return (new PhpCsFixer\Config()) 'method_chaining_indentation' => true, 'class_attributes_separation' => [ 'elements' => [ - 'method' => 'none', - 'trait_import' => 'none' + 'const' => 'none', + 'method' => 'one', + 'property' => 'none', + 'trait_import' => 'none', ], ], 'multiline_whitespace_before_semicolons' => [ @@ -44,7 +46,6 @@ return (new PhpCsFixer\Config()) 'lowercase_cast' => true, 'no_extra_blank_lines' => [ 'tokens' => [ - 'use', 'curly_brace_block', 'extra', 'parenthesis_brace_block', diff --git a/brain/api/v1/AuthAPI.php b/brain/api/v1/AuthAPI.php index 0114d48..8c0c119 100644 --- a/brain/api/v1/AuthAPI.php +++ b/brain/api/v1/AuthAPI.php @@ -10,6 +10,7 @@ class AuthAPI public function __construct() { } + public static function status() { $result = []; @@ -28,6 +29,7 @@ class AuthAPI } return $result; } + public static function login($body) { $result = []; @@ -54,6 +56,7 @@ class AuthAPI return $result; } + public static function logout($body) { Auth::logout($body); @@ -63,11 +66,13 @@ class AuthAPI ]; return $result; } + public static function requestSecret($body) { $result = Auth::findSecret($body); return $result; } + public static function resetPassword($body) { $result = Auth::makeNewPassword($body); diff --git a/brain/api/v1/ImagesAPI.php b/brain/api/v1/ImagesAPI.php index 944d0d3..6d303ea 100644 --- a/brain/api/v1/ImagesAPI.php +++ b/brain/api/v1/ImagesAPI.php @@ -11,6 +11,7 @@ class ImagesAPI public function __construct() { } + public static function uploadImage($request, $type = null) { $file = $request->getUploadedFiles(); diff --git a/brain/api/v1/InitAPI.php b/brain/api/v1/InitAPI.php index 33597d8..a363fc9 100644 --- a/brain/api/v1/InitAPI.php +++ b/brain/api/v1/InitAPI.php @@ -9,6 +9,7 @@ class InitAPI public function __construct() { } + public static function handleInitTasks($task, $request) { //check if a site config already exists. if it does, deny set up request diff --git a/brain/api/v1/MailerAPI.php b/brain/api/v1/MailerAPI.php index f9ad009..ac6261f 100644 --- a/brain/api/v1/MailerAPI.php +++ b/brain/api/v1/MailerAPI.php @@ -10,6 +10,7 @@ class MailerAPI public function __construct() { } + public static function handleMail($request, $body, $response) { // if testing, verify session is active diff --git a/brain/api/v1/PagesAPI.php b/brain/api/v1/PagesAPI.php index aa74d65..d979cf9 100644 --- a/brain/api/v1/PagesAPI.php +++ b/brain/api/v1/PagesAPI.php @@ -6,6 +6,7 @@ use brain\data\Book; use brain\data\Settings; use brain\data\Session; use brain\utility\StringTools; + use function _\filter; class PagesAPI @@ -13,6 +14,7 @@ class PagesAPI public function __construct() { } + public static function getPageContent($request, $args) { $task = $args['fourth']; @@ -101,6 +103,7 @@ class PagesAPI } return $result; } + public static function handlePageTask($request, $args) { $task = $args['fourth']; diff --git a/brain/api/v1/SettingsAPI.php b/brain/api/v1/SettingsAPI.php index 822ecdd..974d30a 100644 --- a/brain/api/v1/SettingsAPI.php +++ b/brain/api/v1/SettingsAPI.php @@ -12,6 +12,7 @@ class SettingsAPI public function __construct() { } + public static function handleSettingsTask($request, $args, $body = null) { $task = $args['fourth']; @@ -26,7 +27,8 @@ class SettingsAPI true ); //check to see if dynamic rendering is active - if (isset($settings['global']['dynamicRender']) && + if ( + isset($settings['global']['dynamicRender']) && $settings['global']['dynamicRender'] === 'true' ) { $result = [ @@ -97,6 +99,7 @@ class SettingsAPI return $result; } + public static function getInfo($request, $args) { $task = $args['fourth']; @@ -140,6 +143,7 @@ class SettingsAPI } return $result; } + public static function createBackup() { $result = Maintenance::makeBackup(); diff --git a/brain/controller/APIControl.php b/brain/controller/APIControl.php index 132d59a..dd60058 100644 --- a/brain/controller/APIControl.php +++ b/brain/controller/APIControl.php @@ -103,6 +103,7 @@ class APIControl return $response->withHeader('Content-Type', 'application/json'); } } + public static function post( ServerRequestInterface $request, ResponseInterface $response, diff --git a/brain/controller/IndexControl.php b/brain/controller/IndexControl.php index fd74731..19c0e08 100644 --- a/brain/controller/IndexControl.php +++ b/brain/controller/IndexControl.php @@ -7,6 +7,7 @@ use Psr\Http\Message\ServerRequestInterface; use Slim\Views\Twig; use brain\data\Settings; use brain\utility\Sorting; + use function _\find; class IndexControl diff --git a/brain/controller/RouteControl.php b/brain/controller/RouteControl.php index 7749362..2fbc068 100644 --- a/brain/controller/RouteControl.php +++ b/brain/controller/RouteControl.php @@ -24,6 +24,7 @@ class RouteControl break; } } + public function post( ServerRequestInterface $request, ResponseInterface $response, diff --git a/brain/data/Auth.php b/brain/data/Auth.php index 5f9c59d..3956bfd 100644 --- a/brain/data/Auth.php +++ b/brain/data/Auth.php @@ -3,6 +3,7 @@ namespace brain\data; use ReallySimpleJWT\Token; + use function _\find; class Auth @@ -10,6 +11,7 @@ class Auth public function __construct() { } + public static function sessionStatus() { if (isset($_SESSION['member'])) { @@ -19,6 +21,7 @@ class Auth } //return $this->secret; } + public static function status() { $result = ''; @@ -29,6 +32,7 @@ class Auth } return $result; } + public static function login($who) { //grab member list @@ -69,14 +73,13 @@ class Auth } return $result; } + public static function findSecret($data) { $result = []; $folks = (new Settings())->getFolks(); - if (!empty($data['email']) && - filter_var($data['email'], FILTER_VALIDATE_EMAIL) - ) { + if (!empty($data['email']) && filter_var($data['email'], FILTER_VALIDATE_EMAIL)) { $found = find($folks, ['email' => $data['email']]); if ($found) { //if email is cool, check mail relay status @@ -110,6 +113,7 @@ class Auth return $result; } + public static function makeNewPassword($data) { //check if passwordsmatch @@ -142,6 +146,7 @@ class Auth return $result; } + public static function logout() { Session::kill(); diff --git a/brain/data/Book.php b/brain/data/Book.php index 642df40..4695548 100644 --- a/brain/data/Book.php +++ b/brain/data/Book.php @@ -5,6 +5,7 @@ namespace brain\data; use brain\utility\DocTools; use brain\utility\StringTools; use brain\utility\FileUploader; + use function _\find; use function _\filter; @@ -13,6 +14,7 @@ class Book public function __construct() { } + public function findPageById(string $uuid) { $content = $this->getContents(); @@ -20,6 +22,7 @@ class Book return $page; } + public function findPageBySlug(string $slug = null) { $content = $this->getContents(); @@ -31,6 +34,7 @@ class Book return $page; } + public function editPage($task, $request) { $content = $this->getContents(); @@ -204,6 +208,7 @@ class Book return $response; } + public function getPages(int $page, int $limit, string $sort = null) { $content = $this->getContents(); @@ -278,6 +283,7 @@ class Book ], ]; } + public function getContents() { // test new contents data class diff --git a/brain/data/Contents.php b/brain/data/Contents.php index 74cf95c..e37d949 100644 --- a/brain/data/Contents.php +++ b/brain/data/Contents.php @@ -2,28 +2,31 @@ namespace brain\data; -use HtmlSanitizer\Extension\Basic\BasicExtension; -use HtmlSanitizer\Extension\Iframe\IframeExtension; -use HtmlSanitizer\Extension\Listing\ListExtension; use HtmlSanitizer\SanitizerBuilder; -use League\CommonMark\Environment\Environment; -use League\CommonMark\Extension\Attributes\AttributesExtension; -use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; -use League\CommonMark\Extension\FrontMatter\FrontMatterExtension; -use League\CommonMark\Extension\FrontMatter\Output\RenderedContentWithFrontMatter; -use League\CommonMark\Extension\Strikethrough\StrikethroughExtension; use League\CommonMark\MarkdownConverter; +use League\CommonMark\Environment\Environment; +use HtmlSanitizer\Extension\Basic\BasicExtension; +use HtmlSanitizer\Extension\Listing\ListExtension; +use HtmlSanitizer\Extension\Iframe\IframeExtension; +use League\CommonMark\Extension\Attributes\AttributesExtension; +use League\CommonMark\Extension\FrontMatter\FrontMatterExtension; +use League\CommonMark\Extension\CommonMark\CommonMarkCoreExtension; +use League\CommonMark\Extension\Strikethrough\StrikethroughExtension; +use League\CommonMark\Extension\FrontMatter\Output\RenderedContentWithFrontMatter; + use function _\orderBy; class Contents { - public $files = []; + public $files = []; + public $config = []; public function __construct($folder) { $this->read($folder); } + public function read($folder) { $folders = glob("$folder/*", GLOB_ONLYDIR); @@ -36,6 +39,7 @@ class Contents $this->files[] = $file; } } + public function getAll() { $environment = new Environment($this->config); diff --git a/brain/data/Member.php b/brain/data/Member.php index fa1e7f4..66ebc64 100644 --- a/brain/data/Member.php +++ b/brain/data/Member.php @@ -3,6 +3,7 @@ namespace brain\data; use brain\utility\DocTools; + use function _\find; class Member @@ -10,6 +11,7 @@ class Member public function __construct() { } + public static function verifyKey(string $key) { if (isset($key)) { @@ -24,6 +26,7 @@ class Member return false; } } + public static function updateData(string $key, string $data, $secret = null) { $folks = (new Settings())->getFolks(); diff --git a/brain/data/Render.php b/brain/data/Render.php index 83916af..77bc2fd 100644 --- a/brain/data/Render.php +++ b/brain/data/Render.php @@ -4,14 +4,19 @@ namespace brain\data; use brain\utility\Sorting; use brain\utility\DocTools; + use function _\find; class Render { public $loader; + public $twig; + public $pageInfo; + public $menu; + public $background; public function __construct() @@ -88,6 +93,7 @@ class Render } } } + public function renderPages() { $pages = (new Book())->getContents(); @@ -122,6 +128,7 @@ class Render DocTools::writeHTML($location, $html, $dir); } } + public function renderArchive() { $archive = Sorting::archive(); @@ -138,6 +145,7 @@ class Render $location = '../public/archives.html'; DocTools::writeHTML($location, $html); } + public function renderTags() { $list = Sorting::tags(); @@ -170,6 +178,7 @@ class Render } } } + public function renderIndex() { //TODO: Need to fix this to account for new index templating system diff --git a/brain/data/Session.php b/brain/data/Session.php index dc8d7b8..a4dbb02 100644 --- a/brain/data/Session.php +++ b/brain/data/Session.php @@ -23,6 +23,7 @@ class Session fclose($new); } } + public static function active() { if (!is_file(self::$file)) { @@ -34,7 +35,8 @@ class Session if ($secret == null) { return false; } else { - if (Token::validate($data['token'], $secret) && + if ( + Token::validate($data['token'], $secret) && Token::validateExpiration($data['token'], $secret) ) { return true; @@ -47,12 +49,14 @@ class Session } } } + public static function verifyToken($token) { $data = json_decode(file_get_contents(self::$file), true); if ($data['member'] != null) { $secret = (new Settings())->getFolks('secret'); - if (Token::validate($token, $secret) && + if ( + Token::validate($token, $secret) && Token::validateExpiration($token, $secret) ) { return true; @@ -63,6 +67,7 @@ class Session return false; } } + public static function set($key, $value) { $data = json_decode(file_get_contents(self::$file), true); @@ -71,12 +76,14 @@ class Session fwrite($fresh, json_encode($data)); fclose($fresh); } + public static function get($key) { $data = json_decode(file_get_contents(self::$file), true); return $data[$key]; } + public static function kill() { ($fresh = fopen(self::$file, 'w')) or die('Unable to open file!'); diff --git a/brain/data/Settings.php b/brain/data/Settings.php index 8ad9102..7f050de 100644 --- a/brain/data/Settings.php +++ b/brain/data/Settings.php @@ -4,6 +4,7 @@ namespace brain\data; use brain\utility\DocTools; use brain\utility\Sorting; + use function _\find; use function _\pull; use function _\remove; @@ -24,6 +25,7 @@ class Settings true ); } + public static function sync($data) { $settings = self::$settings; @@ -46,6 +48,7 @@ class Settings DocTools::writeSettings('../config/settings.json', $settings); } + public static function navSync($data) { $settings = self::$settings; @@ -94,6 +97,7 @@ class Settings DocTools::writeSettings('../config/settings.json', $settings); } + public function getFolks($key = null) { if (isset($key)) { @@ -106,25 +110,30 @@ class Settings return $this->folks; } } + public function getSettings($key = null) { return self::$settings; } + public static function getTags() { return self::$tags; } + public static function updateGlobalData($key, $data) { $settings = self::$settings; $settings['global'][$key] = $data; DocTools::writeSettings('../config/settings.json', $settings); } + public static function getCurrentIndex() { $settings = self::$settings; return $settings['library_stats']['current_index']; } + public static function updateIndex() { $settings = self::$settings; @@ -133,6 +142,7 @@ class Settings DocTools::writeSettings('../config/settings.json', $settings); } + public static function updateMenu($body) { $settings = self::$settings; @@ -155,6 +165,7 @@ class Settings } DocTools::writeSettings('../config/settings.json', $settings); } + public static function updateTags() { $tags = Sorting::tags(); diff --git a/brain/data/Themes.php b/brain/data/Themes.php index f8897b8..b82c336 100644 --- a/brain/data/Themes.php +++ b/brain/data/Themes.php @@ -16,10 +16,12 @@ class Themes ); } } + public function getThemes() { return $this->themes; } + public function getCustomIndex() { $settings = (new Settings())->getSettings(); @@ -38,6 +40,7 @@ class Themes } return $views; } + public function getCustomViews() { $settings = (new Settings())->getSettings(); diff --git a/brain/utility/DocTools.php b/brain/utility/DocTools.php index 55ddd92..4c71f45 100644 --- a/brain/utility/DocTools.php +++ b/brain/utility/DocTools.php @@ -7,6 +7,7 @@ class DocTools public function __construct() { } + public static function writePages($task, $path, $fileLocation, $fileContents) { try { @@ -27,6 +28,7 @@ class DocTools return false; } } + public static function writeSettings($fileLocation, $fileContents) { if (!is_file($fileLocation)) { @@ -37,6 +39,7 @@ class DocTools fclose($new); } } + public static function writeHTML($location, $html, $path = null) { if ($path != null) { @@ -53,6 +56,7 @@ class DocTools fclose($new); } } + public static function deleteFolder($path) { if (!empty($path) && is_dir($path)) { @@ -79,6 +83,7 @@ class DocTools rmdir($path); } } + public static function objectToMD($object) { $markdown = "---\n" . diff --git a/brain/utility/Maintenance.php b/brain/utility/Maintenance.php index c6f17e3..eece1a2 100644 --- a/brain/utility/Maintenance.php +++ b/brain/utility/Maintenance.php @@ -9,6 +9,7 @@ class Maintenance public function __construct() { } + public static function makeBackup() { //make sure back directory is there diff --git a/brain/utility/Setup.php b/brain/utility/Setup.php index 9bd1311..80cd566 100644 --- a/brain/utility/Setup.php +++ b/brain/utility/Setup.php @@ -14,6 +14,7 @@ class SetUp return false; } } + public static function init($body) { //grab template files @@ -93,6 +94,7 @@ class SetUp return $result; } + public static function restore($request) { $result = [ diff --git a/brain/utility/Sorting.php b/brain/utility/Sorting.php index 0ca4a2e..8ca60a4 100644 --- a/brain/utility/Sorting.php +++ b/brain/utility/Sorting.php @@ -10,8 +10,8 @@ use Mni\FrontYAML\Parser; class Sorting { - private static $_tags = []; - private static $_archive = []; + private static $p_tags = []; + private static $p_archive = []; public function __construct() { @@ -24,8 +24,8 @@ class Sorting $temp = explode(',', $page['tags']); foreach ($temp as $tag) { $label = trim($tag); - if (!find(self::$_tags, ['tag_name' => $label])) { - array_push(self::$_tags, [ + if (!find(self::$p_tags, ['tag_name' => $label])) { + array_push(self::$p_tags, [ 'tag_name' => $label, 'slug' => StringTools::safeString($label), 'pages' => self::tagPages($label, $pages), @@ -34,7 +34,7 @@ class Sorting } } - return self::$_tags; + return self::$p_tags; } private static function tagPages($tag, $pages) { @@ -91,13 +91,13 @@ class Sorting ]); } } - array_push(self::$_archive, [ + array_push(self::$p_archive, [ 'year' => $year['year'], 'year_data' => $sorted, ]); } - return self::$_archive; + return self::$p_archive; } public static function page($page) { diff --git a/brain/utility/StringTools.php b/brain/utility/StringTools.php index 7b49f2e..76ae2ac 100644 --- a/brain/utility/StringTools.php +++ b/brain/utility/StringTools.php @@ -26,6 +26,7 @@ class StringTools mt_rand(0, 65535) ); } + public static function sanitizeContent($entry) { $parser = new Parser(); @@ -62,6 +63,7 @@ class StringTools return $cleaned; } + public static function safeString($string) { return strtolower( @@ -83,6 +85,7 @@ class StringTools ) ); } + public static function randomString(int $length) { $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; @@ -113,6 +116,7 @@ class StringTools } } } + private static function checkSpecial($string) { $specials = ['*', '&', '!', '@', '%', '^', '#', '$'];