diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 7b453d9e..91cd6501 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ jobs: uses: actions/checkout@v3 - name: Set Up Cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | vendor @@ -35,12 +35,25 @@ jobs: - name: Format 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: name: PHP ${{ matrix.php }} / DB ${{ matrix.database }} strategy: fail-fast: false matrix: - php: ['8.1'] + php: ['8.1', '8.2'] database: ['pgsql', 'mysql', 'sqlite'] runs-on: ubuntu-latest @@ -51,7 +64,7 @@ jobs: fetch-depth: 2 - name: Set Up Cache - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | vendor diff --git a/composer.json b/composer.json index 710b9cc2..5caa462b 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,8 @@ "require-dev" : { "phpunit/phpunit" : "^9.0", "friendsofphp/php-cs-fixer" : "^3.12", - "scrutinizer/ocular": "dev-master" + "scrutinizer/ocular": "dev-master", + "phpstan/phpstan": "1.10.x-dev" }, "suggest": { "ext-memcache": "memcache caching", diff --git a/composer.lock b/composer.lock index cb4a0aed..945585c1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e7d482b23052d4e764a4f2c076865bc5", + "content-hash": "d010608b1d82774bd3444615496f254f", "packages": [ { "name": "bower-asset/jquery", @@ -2264,6 +2264,66 @@ }, "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", "version": "9.2.x-dev", @@ -5483,7 +5543,8 @@ "stability-flags": { "shish/gqla": 20, "naroga/redis-cache": 20, - "scrutinizer/ocular": 20 + "scrutinizer/ocular": 20, + "phpstan/phpstan": 20 }, "prefer-stable": false, "prefer-lowest": false, diff --git a/core/cacheengine.php b/core/cacheengine.php index 60f4cac4..d8c02d75 100644 --- a/core/cacheengine.php +++ b/core/cacheengine.php @@ -70,7 +70,7 @@ class EventTracingCache implements CacheInterface public function getMultiple($keys, $default = null) { $this->tracer->begin("Cache Get Multiple"); - $val = $this->engine->getMultiple($values, $default); + $val = $this->engine->getMultiple($keys, $default); $this->tracer->end(); return $val; } @@ -109,7 +109,7 @@ function loadCache(?string $dsn): CacheInterface $hp = explode(":", $matches[2]); $memcache = new \Memcached(); $memcache->addServer($hp[0], (int)$hp[1]); - $c = new \Sabre\Cache\Memcached($memcached); + $c = new \Sabre\Cache\Memcached($memcache); } elseif ($matches[1] == "apc") { $c = new \Sabre\Cache\Apcu(); } elseif ($matches[1] == "redis") { diff --git a/core/config.php b/core/config.php index 12857435..3372bf17 100644 --- a/core/config.php +++ b/core/config.php @@ -264,6 +264,7 @@ class DatabaseConfig extends BaseConfig private string $table_name; private ?string $sub_column; private ?string $sub_value; + private string $cache_name; public function __construct( Database $database, diff --git a/core/extension.php b/core/extension.php index cf41957b..88667049 100644 --- a/core/extension.php +++ b/core/extension.php @@ -233,7 +233,7 @@ abstract class ExtensionInfo return self::$all_info_by_class[$normal]; } else { $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) { $extension_info = new $class(); 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; diff --git a/core/imageboard/tag.php b/core/imageboard/tag.php index 0ce5464e..1a00c20d 100644 --- a/core/imageboard/tag.php +++ b/core/imageboard/tag.php @@ -174,7 +174,7 @@ class Tag } // hard-code one bad case... 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; } diff --git a/core/sanitize_php.php b/core/sanitize_php.php index 598d412b..a47cc394 100644 --- a/core/sanitize_php.php +++ b/core/sanitize_php.php @@ -9,9 +9,6 @@ namespace Shimmie2; * 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) { print(" diff --git a/core/user.php b/core/user.php index 11546a8e..afb80bbb 100644 --- a/core/user.php +++ b/core/user.php @@ -177,7 +177,7 @@ class User { global $database; 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; $this->name = $name; diff --git a/ext/comment/main.php b/ext/comment/main.php index 61e86b22..8e254877 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -573,6 +573,7 @@ class CommentList extends Extension 'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? 'none', ]; + // @phpstan-ignore-next-line $akismet = new \Akismet( $_SERVER['SERVER_NAME'], $config->get_string('comment_wordpress_key'), diff --git a/ext/index/theme.php b/ext/index/theme.php index a0dd4d05..b9984bf8 100644 --- a/ext/index/theme.php +++ b/ext/index/theme.php @@ -128,9 +128,9 @@ and of course start organising your images :-) } $wikiLink = make_link("wiki/$st"); if (class_exists('Shimmie2\TagCategories')) { - $this->tagcategories = new TagCategories(); - $tag_category_dict = $this->tagcategories->getKeyedDict(); - $st = $this->tagcategories->getTagHtml(html_escape($st), $tag_category_dict); + $tagcategories = new TagCategories(); + $tag_category_dict = $tagcategories->getKeyedDict(); + $st = $tagcategories->getTagHtml(html_escape($st), $tag_category_dict); } $short_wiki_description = '

'.$st.' 

'.$short_wiki_description; $page->add_block(new Block(null, $short_wiki_description, "main", 0, "short-wiki-description")); diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index 345cf9c4..021fe730 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -11,6 +11,8 @@ class TagList extends Extension /** @var TagListTheme */ protected ?Themelet $theme; + private $tagcategories = null; + public function onInitExt(InitExtEvent $event) { global $config; diff --git a/ext/tag_list/theme.php b/ext/tag_list/theme.php index f829465a..c274a743 100644 --- a/ext/tag_list/theme.php +++ b/ext/tag_list/theme.php @@ -9,6 +9,7 @@ class TagListTheme extends Themelet public string $heading = ""; public string $list = ""; public ?string $navigation; + private $tagcategories = null; public function set_heading(string $text) { diff --git a/ext/wiki/theme.php b/ext/wiki/theme.php index db29f0b8..c1d4ccce 100644 --- a/ext/wiki/theme.php +++ b/ext/wiki/theme.php @@ -32,9 +32,9 @@ class WikiTheme extends Themelet // see if title is a category'd tag $title_html = html_escape($wiki_page->title); if (class_exists('Shimmie2\TagCategories')) { - $this->tagcategories = new TagCategories(); - $tag_category_dict = $this->tagcategories->getKeyedDict(); - $title_html = $this->tagcategories->getTagHtml($title_html, $tag_category_dict); + $tagcategories = new TagCategories(); + $tag_category_dict = $tagcategories->getKeyedDict(); + $title_html = $tagcategories->getTagHtml($title_html, $tag_category_dict); } if (!$wiki_page->exists) { diff --git a/tests/phpstan.neon b/tests/phpstan.neon new file mode 100644 index 00000000..3c43eedb --- /dev/null +++ b/tests/phpstan.neon @@ -0,0 +1,9 @@ +parameters: + level: 0 + paths: + - ../core + - ../ext + - ../tests + - ../themes/default + ignoreErrors: + - '#Attribute class GQLA\\Expose#' \ No newline at end of file diff --git a/themes/material/home.theme.php b/themes/material/home.theme.php index fb909563..55522fca 100644 --- a/themes/material/home.theme.php +++ b/themes/material/home.theme.php @@ -37,7 +37,7 @@ EOD $message_html = empty($main_text) ? "" : "
$main_text
"; $counter_html = empty($counter_text) ? "" : "
$counter_text
"; $contact_link = empty($contact_link) ? "" : "
Contact -"; - $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 = "