Qlty config and code cleanup !2
6 files changed, +109 −49
Layout: unified · split
.qlty/.gitignore added +7
| @@ -0,0 +1,7 @@ | ||
| 1 | * | |
| 2 | !configs | |
| 3 | !configs/** | |
| 4 | !hooks | |
| 5 | !hooks/** | |
| 6 | !qlty.toml | |
| 7 | !.gitignore | |
.qlty/qlty.toml added +49
| @@ -0,0 +1,49 @@ | ||
| 1 | config_version = "0" | |
| 2 | ||
| 3 | exclude_patterns = [ | |
| 4 | "**/vendor/**", | |
| 5 | "**/node_modules/**", | |
| 6 | "**/testdata/**", | |
| 7 | "**/dist/**", | |
| 8 | "**/.build/**", | |
| 9 | "**/build/**", | |
| 10 | "**/*.min.*", | |
| 11 | "**/generated/**", | |
| 12 | ".claude/**", | |
| 13 | "**/Pods/**", | |
| 14 | # Vendored: erusev/parsedown and a PrismJS 1.23.0 build. | |
| 15 | "_classes/Parsedown.php", | |
| 16 | "static/prism.js", | |
| 17 | ] | |
| 18 | ||
| 19 | test_patterns = [ | |
| 20 | "**/test/**", | |
| 21 | "**/tests/**", | |
| 22 | "**/Tests/**", | |
| 23 | "**/*_test.*", | |
| 24 | "**/test_*.*", | |
| 25 | "**/*.test.*", | |
| 26 | "**/*Tests.swift", | |
| 27 | "e2e/**", | |
| 28 | ] | |
| 29 | ||
| 30 | [[source]] | |
| 31 | name = "default" | |
| 32 | default = true | |
| 33 | ||
| 34 | [[plugin]] | |
| 35 | name = "osv-scanner" | |
| 36 | ||
| 37 | [[plugin]] | |
| 38 | name = "trufflehog" | |
| 39 | ||
| 40 | # Early returns are guard clauses, which keep the happy path unindented. | |
| 41 | [smells.return_statements] | |
| 42 | enabled = false | |
| 43 | ||
| 44 | # Function and file complexity are left to review rather than counted. | |
| 45 | [smells.function_complexity] | |
| 46 | enabled = false | |
| 47 | ||
| 48 | [smells.file_complexity] | |
| 49 | enabled = false | |
_classes/Template.php +19 −15
| @@ -3,15 +3,23 @@ | ||
| 3 | 3 | |
| 4 | 4 | class Template |
| 5 | 5 | { |
| 6 | public function __construct(string $canonicalURL, string $pageDescription, string $pageTitle, string $pageExtras, string $contentCol, string $commentSection) | |
| 6 | // Template placeholders, in the order they are filled in. | |
| 7 | private const PLACEHOLDERS = [ | |
| 8 | 'Page_Title', | |
| 9 | 'Page_Description', | |
| 10 | 'Canonical_URL', | |
| 11 | 'Page_Extras', | |
| 12 | 'Content_Column', | |
| 13 | 'User_Comments', | |
| 14 | 'Current_Year', | |
| 15 | ]; | |
| 16 | ||
| 17 | private array $fields; | |
| 18 | ||
| 19 | // $fields maps each {Placeholder} in _templates/template.html to its value. | |
| 20 | public function __construct(array $fields) | |
| 7 | 21 | { |
| 8 | $this->canonicalURL = $canonicalURL; | |
| 9 | $this->description = $pageDescription; | |
| 10 | $this->title = $pageTitle; | |
| 11 | $this->extras = $pageExtras; | |
| 12 | $this->content = $contentCol; | |
| 13 | $this->comments = $commentSection; | |
| 14 | $this->currentYear = date("Y"); | |
| 22 | $this->fields = $fields + ['Current_Year' => date("Y")]; | |
| 15 | 23 | } |
| 16 | 24 | |
| 17 | 25 | public function echoTemplate() |
| @@ -21,13 +29,9 @@ class Template | ||
| 21 | 29 | $page = file_get_contents($templateFile); |
| 22 | 30 | |
| 23 | 31 | // Replace the template variables |
| 24 | $page = str_replace('{Page_Title}', $this->title, $page); | |
| 25 | $page = str_replace('{Page_Description}', $this->description, $page); | |
| 26 | $page = str_replace('{Canonical_URL}', $this->canonicalURL, $page); | |
| 27 | $page = str_replace('{Page_Extras}', $this->extras, $page); | |
| 28 | $page = str_replace('{Content_Column}', $this->content, $page); | |
| 29 | $page = str_replace('{User_Comments}', $this->comments, $page); | |
| 30 | $page = str_replace('{Current_Year}', $this->currentYear, $page); | |
| 32 | foreach (self::PLACEHOLDERS as $name) { | |
| 33 | $page = str_replace('{' . $name . '}', $this->fields[$name], $page); | |
| 34 | } | |
| 31 | 35 | |
| 32 | 36 | // Echo the filled-out template |
| 33 | 37 | echo $page; |
_functions/loadJSON.php +1 −1
| @@ -81,7 +81,7 @@ function loadPostJSON(string $fileName, string $query) | ||
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | function loadCommentJSON(string $fileName, string $query = null): string | |
| 84 | function loadCommentJSON(string $fileName, ?string $query = null): string | |
| 85 | 85 | { |
| 86 | 86 | // Set up an empty comment section |
| 87 | 87 | $commentSection = ''; |
_functions/parseMarkdown.php +1 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | function parseMarkdown(string $fileName = null, string $fileContents = null) | |
| 3 | function parseMarkdown(?string $fileName = null, ?string $fileContents = null) | |
| 4 | 4 | { |
| 5 | 5 | if ($fileName != null) { |
| 6 | 6 | // Get file contents |
index.php +32 −32
| @@ -55,14 +55,14 @@ function showHomepage() | ||
| 55 | 55 | |
| 56 | 56 | // Create a template |
| 57 | 57 | include_once('_classes/Template.php'); |
| 58 | $template = new Template( | |
| 59 | $GLOBALS['fullDomain'], | |
| 60 | 'Explore the thoughts of...', | |
| 61 | 'Blog | YourName', | |
| 62 | '', | |
| 63 | $contentCol, | |
| 64 | '' | |
| 65 | ); | |
| 58 | $template = new Template([ | |
| 59 | 'Canonical_URL' => $GLOBALS['fullDomain'], | |
| 60 | 'Page_Description' => 'Explore the thoughts of...', | |
| 61 | 'Page_Title' => 'Blog | YourName', | |
| 62 | 'Page_Extras' => '', | |
| 63 | 'Content_Column' => $contentCol, | |
| 64 | 'User_Comments' => '', | |
| 65 | ]); | |
| 66 | 66 | |
| 67 | 67 | // Echo the HTML to the user |
| 68 | 68 | $template->echoTemplate(); |
| @@ -102,14 +102,14 @@ function showPost($params) | ||
| 102 | 102 | |
| 103 | 103 | // Create a template |
| 104 | 104 | include_once('_classes/Template.php'); |
| 105 | $template = new Template( | |
| 106 | $GLOBALS['fullDomain'] . '/post/' . $query, | |
| 107 | $headerData->description . ' Read more at ' . $GLOBALS['fullDomain'] . '!', | |
| 108 | $headerData->title . ' | Blog', | |
| 109 | '<link rel="stylesheet" href="/static/prism.css"><script src="/static/prism.js"></script>', | |
| 110 | $contentCol, | |
| 111 | $commentSection | |
| 112 | ); | |
| 105 | $template = new Template([ | |
| 106 | 'Canonical_URL' => $GLOBALS['fullDomain'] . '/post/' . $query, | |
| 107 | 'Page_Description' => $headerData->description . ' Read more at ' . $GLOBALS['fullDomain'] . '!', | |
| 108 | 'Page_Title' => $headerData->title . ' | Blog', | |
| 109 | 'Page_Extras' => '<link rel="stylesheet" href="/static/prism.css"><script src="/static/prism.js"></script>', | |
| 110 | 'Content_Column' => $contentCol, | |
| 111 | 'User_Comments' => $commentSection, | |
| 112 | ]); | |
| 113 | 113 | |
| 114 | 114 | // Echo the HTML to the user |
| 115 | 115 | $template->echoTemplate(); |
| @@ -132,14 +132,14 @@ function showComments() | ||
| 132 | 132 | |
| 133 | 133 | // Create a template |
| 134 | 134 | include_once('_classes/Template.php'); |
| 135 | $template = new Template( | |
| 136 | $GLOBALS['fullDomain'] . '/comments/', | |
| 137 | 'Read through some recent comments for blog posts at ' . $GLOBALS['fullDomain'] . '.', | |
| 138 | 'Recent Comments | Blog', | |
| 139 | '<link rel="stylesheet" href="/static/prism.css"><script src="/static/prism.js"></script><meta name="robots" content="noindex,nofollow">', | |
| 140 | '', | |
| 141 | $commentSection | |
| 142 | ); | |
| 135 | $template = new Template([ | |
| 136 | 'Canonical_URL' => $GLOBALS['fullDomain'] . '/comments/', | |
| 137 | 'Page_Description' => 'Read through some recent comments for blog posts at ' . $GLOBALS['fullDomain'] . '.', | |
| 138 | 'Page_Title' => 'Recent Comments | Blog', | |
| 139 | 'Page_Extras' => '<link rel="stylesheet" href="/static/prism.css"><script src="/static/prism.js"></script><meta name="robots" content="noindex,nofollow">', | |
| 140 | 'Content_Column' => '', | |
| 141 | 'User_Comments' => $commentSection, | |
| 142 | ]); | |
| 143 | 143 | |
| 144 | 144 | // Echo the HTML to the user |
| 145 | 145 | $template->echoTemplate(); |
| @@ -156,14 +156,14 @@ function showCategory() | ||
| 156 | 156 | |
| 157 | 157 | // Create a template |
| 158 | 158 | include_once('_classes/Template.php'); |
| 159 | $template = new Template( | |
| 160 | $GLOBALS['fullDomain'] . '/categories/', | |
| 161 | 'Browse the categories for blog posts at ' . $GLOBALS['fullDomain'] . '.', | |
| 162 | 'Categories | Blog', | |
| 163 | '<meta name="robots" content="noindex,nofollow">', | |
| 164 | $contentCol, | |
| 165 | '' | |
| 166 | ); | |
| 159 | $template = new Template([ | |
| 160 | 'Canonical_URL' => $GLOBALS['fullDomain'] . '/categories/', | |
| 161 | 'Page_Description' => 'Browse the categories for blog posts at ' . $GLOBALS['fullDomain'] . '.', | |
| 162 | 'Page_Title' => 'Categories | Blog', | |
| 163 | 'Page_Extras' => '<meta name="robots" content="noindex,nofollow">', | |
| 164 | 'Content_Column' => $contentCol, | |
| 165 | 'User_Comments' => '', | |
| 166 | ]); | |
| 167 | 167 | |
| 168 | 168 | // Echo the HTML to the user |
| 169 | 169 | $template->echoTemplate(); |