This commit is contained in:
Shish 2023-02-03 16:44:16 +00:00
parent 8219cd7686
commit 54e2ca21ec
16 changed files with 108 additions and 22 deletions

View file

@ -15,7 +15,7 @@ jobs:
uses: actions/checkout@v3 uses: actions/checkout@v3
- name: Set Up Cache - name: Set Up Cache
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: | path: |
vendor vendor
@ -35,12 +35,25 @@ jobs:
- name: Format - name: Format
run: ./vendor/bin/php-cs-fixer fix && git diff --exit-code run: ./vendor/bin/php-cs-fixer fix && git diff --exit-code
static:
name: Static Analysis
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: PHPStan
uses: php-actions/phpstan@v3
with:
contfiguration: tests/phpstan.neon
test: test:
name: PHP ${{ matrix.php }} / DB ${{ matrix.database }} name: PHP ${{ matrix.php }} / DB ${{ matrix.database }}
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
php: ['8.1'] php: ['8.1', '8.2']
database: ['pgsql', 'mysql', 'sqlite'] database: ['pgsql', 'mysql', 'sqlite']
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -51,7 +64,7 @@ jobs:
fetch-depth: 2 fetch-depth: 2
- name: Set Up Cache - name: Set Up Cache
uses: actions/cache@v2 uses: actions/cache@v3
with: with:
path: | path: |
vendor vendor

View file

@ -58,7 +58,8 @@
"require-dev" : { "require-dev" : {
"phpunit/phpunit" : "^9.0", "phpunit/phpunit" : "^9.0",
"friendsofphp/php-cs-fixer" : "^3.12", "friendsofphp/php-cs-fixer" : "^3.12",
"scrutinizer/ocular": "dev-master" "scrutinizer/ocular": "dev-master",
"phpstan/phpstan": "1.10.x-dev"
}, },
"suggest": { "suggest": {
"ext-memcache": "memcache caching", "ext-memcache": "memcache caching",

65
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "e7d482b23052d4e764a4f2c076865bc5", "content-hash": "d010608b1d82774bd3444615496f254f",
"packages": [ "packages": [
{ {
"name": "bower-asset/jquery", "name": "bower-asset/jquery",
@ -2264,6 +2264,66 @@
}, },
"time": "2023-01-29T14:41:23+00:00" "time": "2023-01-29T14:41:23+00:00"
}, },
{
"name": "phpstan/phpstan",
"version": "1.10.x-dev",
"source": {
"type": "git",
"url": "https://github.com/phpstan/phpstan.git",
"reference": "f9f7d4a0714c8356ebe3a14e328a0a6dc778d454"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/f9f7d4a0714c8356ebe3a14e328a0a6dc778d454",
"reference": "f9f7d4a0714c8356ebe3a14e328a0a6dc778d454",
"shasum": ""
},
"require": {
"php": "^7.2|^8.0"
},
"conflict": {
"phpstan/phpstan-shim": "*"
},
"default-branch": true,
"bin": [
"phpstan",
"phpstan.phar"
],
"type": "library",
"autoload": {
"files": [
"bootstrap.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PHPStan - PHP Static Analysis Tool",
"keywords": [
"dev",
"static analysis"
],
"support": {
"issues": "https://github.com/phpstan/phpstan/issues",
"source": "https://github.com/phpstan/phpstan/tree/1.10.x"
},
"funding": [
{
"url": "https://github.com/ondrejmirtes",
"type": "github"
},
{
"url": "https://github.com/phpstan",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/phpstan/phpstan",
"type": "tidelift"
}
],
"time": "2023-02-02T16:02:59+00:00"
},
{ {
"name": "phpunit/php-code-coverage", "name": "phpunit/php-code-coverage",
"version": "9.2.x-dev", "version": "9.2.x-dev",
@ -5483,7 +5543,8 @@
"stability-flags": { "stability-flags": {
"shish/gqla": 20, "shish/gqla": 20,
"naroga/redis-cache": 20, "naroga/redis-cache": 20,
"scrutinizer/ocular": 20 "scrutinizer/ocular": 20,
"phpstan/phpstan": 20
}, },
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,

View file

@ -70,7 +70,7 @@ class EventTracingCache implements CacheInterface
public function getMultiple($keys, $default = null) public function getMultiple($keys, $default = null)
{ {
$this->tracer->begin("Cache Get Multiple"); $this->tracer->begin("Cache Get Multiple");
$val = $this->engine->getMultiple($values, $default); $val = $this->engine->getMultiple($keys, $default);
$this->tracer->end(); $this->tracer->end();
return $val; return $val;
} }
@ -109,7 +109,7 @@ function loadCache(?string $dsn): CacheInterface
$hp = explode(":", $matches[2]); $hp = explode(":", $matches[2]);
$memcache = new \Memcached(); $memcache = new \Memcached();
$memcache->addServer($hp[0], (int)$hp[1]); $memcache->addServer($hp[0], (int)$hp[1]);
$c = new \Sabre\Cache\Memcached($memcached); $c = new \Sabre\Cache\Memcached($memcache);
} elseif ($matches[1] == "apc") { } elseif ($matches[1] == "apc") {
$c = new \Sabre\Cache\Apcu(); $c = new \Sabre\Cache\Apcu();
} elseif ($matches[1] == "redis") { } elseif ($matches[1] == "redis") {

View file

@ -264,6 +264,7 @@ class DatabaseConfig extends BaseConfig
private string $table_name; private string $table_name;
private ?string $sub_column; private ?string $sub_column;
private ?string $sub_value; private ?string $sub_value;
private string $cache_name;
public function __construct( public function __construct(
Database $database, Database $database,

View file

@ -233,7 +233,7 @@ abstract class ExtensionInfo
return self::$all_info_by_class[$normal]; return self::$all_info_by_class[$normal];
} else { } else {
$infos = print_r(array_keys(self::$all_info_by_class), true); $infos = print_r(array_keys(self::$all_info_by_class), true);
throw new ScoreException("$normal not found in {$infos}"); throw new SCoreException("$normal not found in {$infos}");
} }
} }
@ -242,7 +242,7 @@ abstract class ExtensionInfo
foreach (get_subclasses_of("Shimmie2\ExtensionInfo") as $class) { foreach (get_subclasses_of("Shimmie2\ExtensionInfo") as $class) {
$extension_info = new $class(); $extension_info = new $class();
if (array_key_exists($extension_info->key, self::$all_info_by_key)) { if (array_key_exists($extension_info->key, self::$all_info_by_key)) {
throw new ScoreException("Extension Info $class with key $extension_info->key has already been loaded"); throw new SCoreException("Extension Info $class with key $extension_info->key has already been loaded");
} }
self::$all_info_by_key[$extension_info->key] = $extension_info; self::$all_info_by_key[$extension_info->key] = $extension_info;

View file

@ -174,7 +174,7 @@ class Tag
} // hard-code one bad case... } // hard-code one bad case...
if (mb_strlen($tag, 'UTF-8') > 255) { if (mb_strlen($tag, 'UTF-8') > 255) {
throw new ScoreException("The tag below is longer than 255 characters, please use a shorter tag.\n$tag\n"); throw new SCoreException("The tag below is longer than 255 characters, please use a shorter tag.\n$tag\n");
} }
return $tag; return $tag;
} }

View file

@ -9,9 +9,6 @@ namespace Shimmie2;
* be included right at the very start of index.php and tests/bootstrap.php * be included right at the very start of index.php and tests/bootstrap.php
*/ */
use JetBrains\PhpStorm\NoReturn;
#[NoReturn]
function die_nicely($title, $body, $code=0) function die_nicely($title, $body, $code=0)
{ {
print("<!DOCTYPE html> print("<!DOCTYPE html>

View file

@ -177,7 +177,7 @@ class User
{ {
global $database; global $database;
if (User::by_name($name)) { if (User::by_name($name)) {
throw new ScoreException("Desired username is already in use"); throw new SCoreException("Desired username is already in use");
} }
$old_name = $this->name; $old_name = $this->name;
$this->name = $name; $this->name = $name;

View file

@ -573,6 +573,7 @@ class CommentList extends Extension
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? 'none', 'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? 'none',
]; ];
// @phpstan-ignore-next-line
$akismet = new \Akismet( $akismet = new \Akismet(
$_SERVER['SERVER_NAME'], $_SERVER['SERVER_NAME'],
$config->get_string('comment_wordpress_key'), $config->get_string('comment_wordpress_key'),

View file

@ -128,9 +128,9 @@ and of course start organising your images :-)
} }
$wikiLink = make_link("wiki/$st"); $wikiLink = make_link("wiki/$st");
if (class_exists('Shimmie2\TagCategories')) { if (class_exists('Shimmie2\TagCategories')) {
$this->tagcategories = new TagCategories(); $tagcategories = new TagCategories();
$tag_category_dict = $this->tagcategories->getKeyedDict(); $tag_category_dict = $tagcategories->getKeyedDict();
$st = $this->tagcategories->getTagHtml(html_escape($st), $tag_category_dict); $st = $tagcategories->getTagHtml(html_escape($st), $tag_category_dict);
} }
$short_wiki_description = '<h2>'.$st.'&nbsp;<a href="'.$wikiLink.'"><sup>ⓘ</sup></a></h2>'.$short_wiki_description; $short_wiki_description = '<h2>'.$st.'&nbsp;<a href="'.$wikiLink.'"><sup>ⓘ</sup></a></h2>'.$short_wiki_description;
$page->add_block(new Block(null, $short_wiki_description, "main", 0, "short-wiki-description")); $page->add_block(new Block(null, $short_wiki_description, "main", 0, "short-wiki-description"));

View file

@ -11,6 +11,8 @@ class TagList extends Extension
/** @var TagListTheme */ /** @var TagListTheme */
protected ?Themelet $theme; protected ?Themelet $theme;
private $tagcategories = null;
public function onInitExt(InitExtEvent $event) public function onInitExt(InitExtEvent $event)
{ {
global $config; global $config;

View file

@ -9,6 +9,7 @@ class TagListTheme extends Themelet
public string $heading = ""; public string $heading = "";
public string $list = ""; public string $list = "";
public ?string $navigation; public ?string $navigation;
private $tagcategories = null;
public function set_heading(string $text) public function set_heading(string $text)
{ {

View file

@ -32,9 +32,9 @@ class WikiTheme extends Themelet
// see if title is a category'd tag // see if title is a category'd tag
$title_html = html_escape($wiki_page->title); $title_html = html_escape($wiki_page->title);
if (class_exists('Shimmie2\TagCategories')) { if (class_exists('Shimmie2\TagCategories')) {
$this->tagcategories = new TagCategories(); $tagcategories = new TagCategories();
$tag_category_dict = $this->tagcategories->getKeyedDict(); $tag_category_dict = $tagcategories->getKeyedDict();
$title_html = $this->tagcategories->getTagHtml($title_html, $tag_category_dict); $title_html = $tagcategories->getTagHtml($title_html, $tag_category_dict);
} }
if (!$wiki_page->exists) { if (!$wiki_page->exists) {

9
tests/phpstan.neon Normal file
View file

@ -0,0 +1,9 @@
parameters:
level: 0
paths:
- ../core
- ../ext
- ../tests
- ../themes/default
ignoreErrors:
- '#Attribute class GQLA\\Expose#'

View file

@ -37,7 +37,7 @@ EOD
$message_html = empty($main_text) ? "" : "<div class='space' id='message'>$main_text</div>"; $message_html = empty($main_text) ? "" : "<div class='space' id='message'>$main_text</div>";
$counter_html = empty($counter_text) ? "" : "<div class='mdl-typography--text-center' id='counter'>$counter_text</div>"; $counter_html = empty($counter_text) ? "" : "<div class='mdl-typography--text-center' id='counter'>$counter_text</div>";
$contact_link = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a> -"; $contact_link = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a> -";
$main_links_html = empty($main_links) ? "" : preg_replace('data-clink-sel="" ', '', preg_replace('/shm-clink/', 'mdl-navigation__link', $main_links)); $main_links_html = empty($main_links) ? "" : preg_replace('/data-clink-sel="" /', '', preg_replace('/shm-clink/', 'mdl-navigation__link', $main_links));
$search_html = " $search_html = "
<div class='mdl-grid'> <div class='mdl-grid'>
<div class='mdl-layout-spacer'></div> <div class='mdl-layout-spacer'></div>