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.
This commit is contained in:
Are0h 2022-05-16 19:14:38 -07:00
parent 63eaba08e2
commit a31dff94cb
23 changed files with 106 additions and 27 deletions

View file

@ -2,7 +2,7 @@
return (new PhpCsFixer\Config()) return (new PhpCsFixer\Config())
->setRules([ ->setRules([
'@PSR2' => true, '@PSR12' => true,
'array_indentation' => true, 'array_indentation' => true,
'array_syntax' => [ 'array_syntax' => [
'syntax' => 'short', 'syntax' => 'short',
@ -11,8 +11,10 @@ return (new PhpCsFixer\Config())
'method_chaining_indentation' => true, 'method_chaining_indentation' => true,
'class_attributes_separation' => [ 'class_attributes_separation' => [
'elements' => [ 'elements' => [
'method' => 'none', 'const' => 'none',
'trait_import' => 'none' 'method' => 'one',
'property' => 'none',
'trait_import' => 'none',
], ],
], ],
'multiline_whitespace_before_semicolons' => [ 'multiline_whitespace_before_semicolons' => [
@ -44,7 +46,6 @@ return (new PhpCsFixer\Config())
'lowercase_cast' => true, 'lowercase_cast' => true,
'no_extra_blank_lines' => [ 'no_extra_blank_lines' => [
'tokens' => [ 'tokens' => [
'use',
'curly_brace_block', 'curly_brace_block',
'extra', 'extra',
'parenthesis_brace_block', 'parenthesis_brace_block',

View file

@ -10,6 +10,7 @@ class AuthAPI
public function __construct() public function __construct()
{ {
} }
public static function status() public static function status()
{ {
$result = []; $result = [];
@ -28,6 +29,7 @@ class AuthAPI
} }
return $result; return $result;
} }
public static function login($body) public static function login($body)
{ {
$result = []; $result = [];
@ -54,6 +56,7 @@ class AuthAPI
return $result; return $result;
} }
public static function logout($body) public static function logout($body)
{ {
Auth::logout($body); Auth::logout($body);
@ -63,11 +66,13 @@ class AuthAPI
]; ];
return $result; return $result;
} }
public static function requestSecret($body) public static function requestSecret($body)
{ {
$result = Auth::findSecret($body); $result = Auth::findSecret($body);
return $result; return $result;
} }
public static function resetPassword($body) public static function resetPassword($body)
{ {
$result = Auth::makeNewPassword($body); $result = Auth::makeNewPassword($body);

View file

@ -11,6 +11,7 @@ class ImagesAPI
public function __construct() public function __construct()
{ {
} }
public static function uploadImage($request, $type = null) public static function uploadImage($request, $type = null)
{ {
$file = $request->getUploadedFiles(); $file = $request->getUploadedFiles();

View file

@ -9,6 +9,7 @@ class InitAPI
public function __construct() public function __construct()
{ {
} }
public static function handleInitTasks($task, $request) public static function handleInitTasks($task, $request)
{ {
//check if a site config already exists. if it does, deny set up request //check if a site config already exists. if it does, deny set up request

View file

@ -10,6 +10,7 @@ class MailerAPI
public function __construct() public function __construct()
{ {
} }
public static function handleMail($request, $body, $response) public static function handleMail($request, $body, $response)
{ {
// if testing, verify session is active // if testing, verify session is active

View file

@ -6,6 +6,7 @@ use brain\data\Book;
use brain\data\Settings; use brain\data\Settings;
use brain\data\Session; use brain\data\Session;
use brain\utility\StringTools; use brain\utility\StringTools;
use function _\filter; use function _\filter;
class PagesAPI class PagesAPI
@ -13,6 +14,7 @@ class PagesAPI
public function __construct() public function __construct()
{ {
} }
public static function getPageContent($request, $args) public static function getPageContent($request, $args)
{ {
$task = $args['fourth']; $task = $args['fourth'];
@ -101,6 +103,7 @@ class PagesAPI
} }
return $result; return $result;
} }
public static function handlePageTask($request, $args) public static function handlePageTask($request, $args)
{ {
$task = $args['fourth']; $task = $args['fourth'];

View file

@ -12,6 +12,7 @@ class SettingsAPI
public function __construct() public function __construct()
{ {
} }
public static function handleSettingsTask($request, $args, $body = null) public static function handleSettingsTask($request, $args, $body = null)
{ {
$task = $args['fourth']; $task = $args['fourth'];
@ -26,7 +27,8 @@ class SettingsAPI
true true
); );
//check to see if dynamic rendering is active //check to see if dynamic rendering is active
if (isset($settings['global']['dynamicRender']) && if (
isset($settings['global']['dynamicRender']) &&
$settings['global']['dynamicRender'] === 'true' $settings['global']['dynamicRender'] === 'true'
) { ) {
$result = [ $result = [
@ -97,6 +99,7 @@ class SettingsAPI
return $result; return $result;
} }
public static function getInfo($request, $args) public static function getInfo($request, $args)
{ {
$task = $args['fourth']; $task = $args['fourth'];
@ -140,6 +143,7 @@ class SettingsAPI
} }
return $result; return $result;
} }
public static function createBackup() public static function createBackup()
{ {
$result = Maintenance::makeBackup(); $result = Maintenance::makeBackup();

View file

@ -103,6 +103,7 @@ class APIControl
return $response->withHeader('Content-Type', 'application/json'); return $response->withHeader('Content-Type', 'application/json');
} }
} }
public static function post( public static function post(
ServerRequestInterface $request, ServerRequestInterface $request,
ResponseInterface $response, ResponseInterface $response,

View file

@ -7,6 +7,7 @@ use Psr\Http\Message\ServerRequestInterface;
use Slim\Views\Twig; use Slim\Views\Twig;
use brain\data\Settings; use brain\data\Settings;
use brain\utility\Sorting; use brain\utility\Sorting;
use function _\find; use function _\find;
class IndexControl class IndexControl

View file

@ -24,6 +24,7 @@ class RouteControl
break; break;
} }
} }
public function post( public function post(
ServerRequestInterface $request, ServerRequestInterface $request,
ResponseInterface $response, ResponseInterface $response,

View file

@ -3,6 +3,7 @@
namespace brain\data; namespace brain\data;
use ReallySimpleJWT\Token; use ReallySimpleJWT\Token;
use function _\find; use function _\find;
class Auth class Auth
@ -10,6 +11,7 @@ class Auth
public function __construct() public function __construct()
{ {
} }
public static function sessionStatus() public static function sessionStatus()
{ {
if (isset($_SESSION['member'])) { if (isset($_SESSION['member'])) {
@ -19,6 +21,7 @@ class Auth
} }
//return $this->secret; //return $this->secret;
} }
public static function status() public static function status()
{ {
$result = ''; $result = '';
@ -29,6 +32,7 @@ class Auth
} }
return $result; return $result;
} }
public static function login($who) public static function login($who)
{ {
//grab member list //grab member list
@ -69,14 +73,13 @@ class Auth
} }
return $result; return $result;
} }
public static function findSecret($data) public static function findSecret($data)
{ {
$result = []; $result = [];
$folks = (new Settings())->getFolks(); $folks = (new Settings())->getFolks();
if (!empty($data['email']) && if (!empty($data['email']) && filter_var($data['email'], FILTER_VALIDATE_EMAIL)) {
filter_var($data['email'], FILTER_VALIDATE_EMAIL)
) {
$found = find($folks, ['email' => $data['email']]); $found = find($folks, ['email' => $data['email']]);
if ($found) { if ($found) {
//if email is cool, check mail relay status //if email is cool, check mail relay status
@ -110,6 +113,7 @@ class Auth
return $result; return $result;
} }
public static function makeNewPassword($data) public static function makeNewPassword($data)
{ {
//check if passwordsmatch //check if passwordsmatch
@ -142,6 +146,7 @@ class Auth
return $result; return $result;
} }
public static function logout() public static function logout()
{ {
Session::kill(); Session::kill();

View file

@ -5,6 +5,7 @@ namespace brain\data;
use brain\utility\DocTools; use brain\utility\DocTools;
use brain\utility\StringTools; use brain\utility\StringTools;
use brain\utility\FileUploader; use brain\utility\FileUploader;
use function _\find; use function _\find;
use function _\filter; use function _\filter;
@ -13,6 +14,7 @@ class Book
public function __construct() public function __construct()
{ {
} }
public function findPageById(string $uuid) public function findPageById(string $uuid)
{ {
$content = $this->getContents(); $content = $this->getContents();
@ -20,6 +22,7 @@ class Book
return $page; return $page;
} }
public function findPageBySlug(string $slug = null) public function findPageBySlug(string $slug = null)
{ {
$content = $this->getContents(); $content = $this->getContents();
@ -31,6 +34,7 @@ class Book
return $page; return $page;
} }
public function editPage($task, $request) public function editPage($task, $request)
{ {
$content = $this->getContents(); $content = $this->getContents();
@ -204,6 +208,7 @@ class Book
return $response; return $response;
} }
public function getPages(int $page, int $limit, string $sort = null) public function getPages(int $page, int $limit, string $sort = null)
{ {
$content = $this->getContents(); $content = $this->getContents();
@ -278,6 +283,7 @@ class Book
], ],
]; ];
} }
public function getContents() public function getContents()
{ {
// test new contents data class // test new contents data class

View file

@ -2,28 +2,31 @@
namespace brain\data; namespace brain\data;
use HtmlSanitizer\Extension\Basic\BasicExtension;
use HtmlSanitizer\Extension\Iframe\IframeExtension;
use HtmlSanitizer\Extension\Listing\ListExtension;
use HtmlSanitizer\SanitizerBuilder; 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\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; use function _\orderBy;
class Contents class Contents
{ {
public $files = []; public $files = [];
public $config = []; public $config = [];
public function __construct($folder) public function __construct($folder)
{ {
$this->read($folder); $this->read($folder);
} }
public function read($folder) public function read($folder)
{ {
$folders = glob("$folder/*", GLOB_ONLYDIR); $folders = glob("$folder/*", GLOB_ONLYDIR);
@ -36,6 +39,7 @@ class Contents
$this->files[] = $file; $this->files[] = $file;
} }
} }
public function getAll() public function getAll()
{ {
$environment = new Environment($this->config); $environment = new Environment($this->config);

View file

@ -3,6 +3,7 @@
namespace brain\data; namespace brain\data;
use brain\utility\DocTools; use brain\utility\DocTools;
use function _\find; use function _\find;
class Member class Member
@ -10,6 +11,7 @@ class Member
public function __construct() public function __construct()
{ {
} }
public static function verifyKey(string $key) public static function verifyKey(string $key)
{ {
if (isset($key)) { if (isset($key)) {
@ -24,6 +26,7 @@ class Member
return false; return false;
} }
} }
public static function updateData(string $key, string $data, $secret = null) public static function updateData(string $key, string $data, $secret = null)
{ {
$folks = (new Settings())->getFolks(); $folks = (new Settings())->getFolks();

View file

@ -4,14 +4,19 @@ namespace brain\data;
use brain\utility\Sorting; use brain\utility\Sorting;
use brain\utility\DocTools; use brain\utility\DocTools;
use function _\find; use function _\find;
class Render class Render
{ {
public $loader; public $loader;
public $twig; public $twig;
public $pageInfo; public $pageInfo;
public $menu; public $menu;
public $background; public $background;
public function __construct() public function __construct()
@ -88,6 +93,7 @@ class Render
} }
} }
} }
public function renderPages() public function renderPages()
{ {
$pages = (new Book())->getContents(); $pages = (new Book())->getContents();
@ -122,6 +128,7 @@ class Render
DocTools::writeHTML($location, $html, $dir); DocTools::writeHTML($location, $html, $dir);
} }
} }
public function renderArchive() public function renderArchive()
{ {
$archive = Sorting::archive(); $archive = Sorting::archive();
@ -138,6 +145,7 @@ class Render
$location = '../public/archives.html'; $location = '../public/archives.html';
DocTools::writeHTML($location, $html); DocTools::writeHTML($location, $html);
} }
public function renderTags() public function renderTags()
{ {
$list = Sorting::tags(); $list = Sorting::tags();
@ -170,6 +178,7 @@ class Render
} }
} }
} }
public function renderIndex() public function renderIndex()
{ {
//TODO: Need to fix this to account for new index templating system //TODO: Need to fix this to account for new index templating system

View file

@ -23,6 +23,7 @@ class Session
fclose($new); fclose($new);
} }
} }
public static function active() public static function active()
{ {
if (!is_file(self::$file)) { if (!is_file(self::$file)) {
@ -34,7 +35,8 @@ class Session
if ($secret == null) { if ($secret == null) {
return false; return false;
} else { } else {
if (Token::validate($data['token'], $secret) && if (
Token::validate($data['token'], $secret) &&
Token::validateExpiration($data['token'], $secret) Token::validateExpiration($data['token'], $secret)
) { ) {
return true; return true;
@ -47,12 +49,14 @@ class Session
} }
} }
} }
public static function verifyToken($token) public static function verifyToken($token)
{ {
$data = json_decode(file_get_contents(self::$file), true); $data = json_decode(file_get_contents(self::$file), true);
if ($data['member'] != null) { if ($data['member'] != null) {
$secret = (new Settings())->getFolks('secret'); $secret = (new Settings())->getFolks('secret');
if (Token::validate($token, $secret) && if (
Token::validate($token, $secret) &&
Token::validateExpiration($token, $secret) Token::validateExpiration($token, $secret)
) { ) {
return true; return true;
@ -63,6 +67,7 @@ class Session
return false; return false;
} }
} }
public static function set($key, $value) public static function set($key, $value)
{ {
$data = json_decode(file_get_contents(self::$file), true); $data = json_decode(file_get_contents(self::$file), true);
@ -71,12 +76,14 @@ class Session
fwrite($fresh, json_encode($data)); fwrite($fresh, json_encode($data));
fclose($fresh); fclose($fresh);
} }
public static function get($key) public static function get($key)
{ {
$data = json_decode(file_get_contents(self::$file), true); $data = json_decode(file_get_contents(self::$file), true);
return $data[$key]; return $data[$key];
} }
public static function kill() public static function kill()
{ {
($fresh = fopen(self::$file, 'w')) or die('Unable to open file!'); ($fresh = fopen(self::$file, 'w')) or die('Unable to open file!');

View file

@ -4,6 +4,7 @@ namespace brain\data;
use brain\utility\DocTools; use brain\utility\DocTools;
use brain\utility\Sorting; use brain\utility\Sorting;
use function _\find; use function _\find;
use function _\pull; use function _\pull;
use function _\remove; use function _\remove;
@ -24,6 +25,7 @@ class Settings
true true
); );
} }
public static function sync($data) public static function sync($data)
{ {
$settings = self::$settings; $settings = self::$settings;
@ -46,6 +48,7 @@ class Settings
DocTools::writeSettings('../config/settings.json', $settings); DocTools::writeSettings('../config/settings.json', $settings);
} }
public static function navSync($data) public static function navSync($data)
{ {
$settings = self::$settings; $settings = self::$settings;
@ -94,6 +97,7 @@ class Settings
DocTools::writeSettings('../config/settings.json', $settings); DocTools::writeSettings('../config/settings.json', $settings);
} }
public function getFolks($key = null) public function getFolks($key = null)
{ {
if (isset($key)) { if (isset($key)) {
@ -106,25 +110,30 @@ class Settings
return $this->folks; return $this->folks;
} }
} }
public function getSettings($key = null) public function getSettings($key = null)
{ {
return self::$settings; return self::$settings;
} }
public static function getTags() public static function getTags()
{ {
return self::$tags; return self::$tags;
} }
public static function updateGlobalData($key, $data) public static function updateGlobalData($key, $data)
{ {
$settings = self::$settings; $settings = self::$settings;
$settings['global'][$key] = $data; $settings['global'][$key] = $data;
DocTools::writeSettings('../config/settings.json', $settings); DocTools::writeSettings('../config/settings.json', $settings);
} }
public static function getCurrentIndex() public static function getCurrentIndex()
{ {
$settings = self::$settings; $settings = self::$settings;
return $settings['library_stats']['current_index']; return $settings['library_stats']['current_index'];
} }
public static function updateIndex() public static function updateIndex()
{ {
$settings = self::$settings; $settings = self::$settings;
@ -133,6 +142,7 @@ class Settings
DocTools::writeSettings('../config/settings.json', $settings); DocTools::writeSettings('../config/settings.json', $settings);
} }
public static function updateMenu($body) public static function updateMenu($body)
{ {
$settings = self::$settings; $settings = self::$settings;
@ -155,6 +165,7 @@ class Settings
} }
DocTools::writeSettings('../config/settings.json', $settings); DocTools::writeSettings('../config/settings.json', $settings);
} }
public static function updateTags() public static function updateTags()
{ {
$tags = Sorting::tags(); $tags = Sorting::tags();

View file

@ -16,10 +16,12 @@ class Themes
); );
} }
} }
public function getThemes() public function getThemes()
{ {
return $this->themes; return $this->themes;
} }
public function getCustomIndex() public function getCustomIndex()
{ {
$settings = (new Settings())->getSettings(); $settings = (new Settings())->getSettings();
@ -38,6 +40,7 @@ class Themes
} }
return $views; return $views;
} }
public function getCustomViews() public function getCustomViews()
{ {
$settings = (new Settings())->getSettings(); $settings = (new Settings())->getSettings();

View file

@ -7,6 +7,7 @@ class DocTools
public function __construct() public function __construct()
{ {
} }
public static function writePages($task, $path, $fileLocation, $fileContents) public static function writePages($task, $path, $fileLocation, $fileContents)
{ {
try { try {
@ -27,6 +28,7 @@ class DocTools
return false; return false;
} }
} }
public static function writeSettings($fileLocation, $fileContents) public static function writeSettings($fileLocation, $fileContents)
{ {
if (!is_file($fileLocation)) { if (!is_file($fileLocation)) {
@ -37,6 +39,7 @@ class DocTools
fclose($new); fclose($new);
} }
} }
public static function writeHTML($location, $html, $path = null) public static function writeHTML($location, $html, $path = null)
{ {
if ($path != null) { if ($path != null) {
@ -53,6 +56,7 @@ class DocTools
fclose($new); fclose($new);
} }
} }
public static function deleteFolder($path) public static function deleteFolder($path)
{ {
if (!empty($path) && is_dir($path)) { if (!empty($path) && is_dir($path)) {
@ -79,6 +83,7 @@ class DocTools
rmdir($path); rmdir($path);
} }
} }
public static function objectToMD($object) public static function objectToMD($object)
{ {
$markdown = "---\n" . $markdown = "---\n" .

View file

@ -9,6 +9,7 @@ class Maintenance
public function __construct() public function __construct()
{ {
} }
public static function makeBackup() public static function makeBackup()
{ {
//make sure back directory is there //make sure back directory is there

View file

@ -14,6 +14,7 @@ class SetUp
return false; return false;
} }
} }
public static function init($body) public static function init($body)
{ {
//grab template files //grab template files
@ -93,6 +94,7 @@ class SetUp
return $result; return $result;
} }
public static function restore($request) public static function restore($request)
{ {
$result = [ $result = [

View file

@ -10,8 +10,8 @@ use Mni\FrontYAML\Parser;
class Sorting class Sorting
{ {
private static $_tags = []; private static $p_tags = [];
private static $_archive = []; private static $p_archive = [];
public function __construct() public function __construct()
{ {
@ -24,8 +24,8 @@ class Sorting
$temp = explode(',', $page['tags']); $temp = explode(',', $page['tags']);
foreach ($temp as $tag) { foreach ($temp as $tag) {
$label = trim($tag); $label = trim($tag);
if (!find(self::$_tags, ['tag_name' => $label])) { if (!find(self::$p_tags, ['tag_name' => $label])) {
array_push(self::$_tags, [ array_push(self::$p_tags, [
'tag_name' => $label, 'tag_name' => $label,
'slug' => StringTools::safeString($label), 'slug' => StringTools::safeString($label),
'pages' => self::tagPages($label, $pages), 'pages' => self::tagPages($label, $pages),
@ -34,7 +34,7 @@ class Sorting
} }
} }
return self::$_tags; return self::$p_tags;
} }
private static function tagPages($tag, $pages) 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' => $year['year'],
'year_data' => $sorted, 'year_data' => $sorted,
]); ]);
} }
return self::$_archive; return self::$p_archive;
} }
public static function page($page) public static function page($page)
{ {

View file

@ -26,6 +26,7 @@ class StringTools
mt_rand(0, 65535) mt_rand(0, 65535)
); );
} }
public static function sanitizeContent($entry) public static function sanitizeContent($entry)
{ {
$parser = new Parser(); $parser = new Parser();
@ -62,6 +63,7 @@ class StringTools
return $cleaned; return $cleaned;
} }
public static function safeString($string) public static function safeString($string)
{ {
return strtolower( return strtolower(
@ -83,6 +85,7 @@ class StringTools
) )
); );
} }
public static function randomString(int $length) public static function randomString(int $length)
{ {
$alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; $alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
@ -113,6 +116,7 @@ class StringTools
} }
} }
} }
private static function checkSpecial($string) private static function checkSpecial($string)
{ {
$specials = ['*', '&', '!', '@', '%', '^', '#', '$']; $specials = ['*', '&', '!', '@', '%', '^', '#', '$'];