Skip to content

Commit

Permalink
chore: enable phpstan, apply fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
imorland committed Nov 14, 2023
1 parent ea8ea9c commit b5baaa6
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 22 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/backend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Syndication PHP

on: [workflow_dispatch, push, pull_request]

jobs:
run:
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
with:
enable_backend_testing: false
enable_phpstan: true

backend_directory: .
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Javascript
name: Syndication JS

on: [workflow_dispatch, push, pull_request]

Expand All @@ -8,11 +8,12 @@ jobs:
with:
enable_bundlewatch: false
enable_prettier: true
enable_typescript: false
enable_typescript: true

frontend_directory: ./js
backend_directory: .
js_package_manager: npm
main_git_branch: master

secrets:
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
20 changes: 18 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}
],
"require": {
"flarum/core": "^1.3.1"
"flarum/core": "^1.8.3"
},
"extra": {
"flarum-extension": {
Expand All @@ -39,15 +39,31 @@
},
"optional-dependencies": [
"flarum/tags"
]
]
},
"flagrow": {
"discuss": "https://discuss.flarum.org/d/27687"
},
"flarum-cli": {
"modules": {
"githubActions": true
}
}
},
"autoload": {
"psr-4": {
"IanM\\FlarumFeeds\\": "src/"
}
},
"require-dev": {
"flarum/phpstan": "*",
"flarum/tags": "*"
},
"scripts": {
"analyse:phpstan": "phpstan analyse",
"clear-cache:phpstan": "phpstan clear-result-cache"
},
"scripts-descriptions": {
"analyse:phpstan": "Run static analysis"
}
}
18 changes: 12 additions & 6 deletions extend.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@
->get('/rss/d/{id:\d+(?:-[^/]*)?}', 'feeds.rss.discussion', Controller\DiscussionFeedController::class)
->get('/atom/d/{id:\d+(?:-[^/]*)?}', 'feeds.atom.discussion', Controller\DiscussionFeedController::class)

->get('/rss/t/{tag}', 'feeds.rss.tag', Controller\TagsFeedController::class)
->get('/atom/t/{tag}', 'feeds.atom.tag', Controller\TagsFeedController::class)

->get('/rss/t/{tag}/discussions', 'feeds.rss.tag_discussions', Controller\LastDiscussionsByTagFeedController::class)
->get('/atom/t/{tag}/discussions', 'feeds.atom.tag_discussions', Controller\LastDiscussionsByTagFeedController::class)

->get('/rss/u/{username}/posts', 'feeds.rss.user_posts', Controller\UserPostsFeedController::class)
->get('/atom/u/{username}/posts', 'feeds.atom.user_posts', Controller\UserPostsFeedController::class),

Expand All @@ -82,4 +76,16 @@
->default('ianm-syndication.plugin.forum-icons', false)
->serializeToForum('ianm-syndication.plugin.forum-format', 'ianm-syndication.plugin.forum-format')
->serializeToForum('ianm-syndication.plugin.forum-icons', 'ianm-syndication.plugin.forum-icons', 'boolVal'),

(new Extend\Conditional())
->whenExtensionEnabled('flarum-tags', function () {
return [
(new Extend\Routes('forum'))
->get('/rss/t/{tag}', 'feeds.rss.tag', Controller\TagsFeedController::class)
->get('/atom/t/{tag}', 'feeds.atom.tag', Controller\TagsFeedController::class)

->get('/rss/t/{tag}/discussions', 'feeds.rss.tag_discussions', Controller\LastDiscussionsByTagFeedController::class)
->get('/atom/t/{tag}/discussions', 'feeds.atom.tag_discussions', Controller\LastDiscussionsByTagFeedController::class)
];
})
];
13 changes: 13 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
includes:
- vendor/flarum/phpstan/extension.neon

parameters:
# The level will be increased in Flarum 2.0
level: 5
paths:
- extend.php
- src
excludePaths:
- *.blade.php
checkMissingIterableValueType: false
databaseMigrationsPath: ['migrations']
6 changes: 3 additions & 3 deletions src/Controller/AbstractFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\User;
use Illuminate\Support\Str;
use Illuminate\View\Factory;
use Illuminate\Contracts\View\Factory;
use Laminas\Diactoros\Response;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down Expand Up @@ -213,7 +213,7 @@ protected function getForumDocument(Request $request, User $actor)
* @param \stdClass $document A document.
* @param \stdClass $relationship A relationship object in the document.
*
* @return \stdClass The related object from the document.
* @return \stdClass|null The related object from the document.
*/
protected function getRelationship(\stdClass $document, \stdClass $relationship)
{
Expand Down Expand Up @@ -358,7 +358,7 @@ public function truncate($text, $length = 100, $options = [])
}
if (!$exact) {
$spacepos = mb_strrpos($truncate, ' ');
if (isset($spacepos)) {
if ($spacepos) {
if ($html) {
$bits = mb_substr($truncate, $spacepos);
preg_match_all('/<\/([a-z]+)>/', $bits, $droppedTags, PREG_SET_ORDER);
Expand Down
5 changes: 2 additions & 3 deletions src/Controller/LastDiscussionsByTagFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
namespace IanM\FlarumFeeds\Controller;

use Flarum\Api\Client as ApiClient;
use Flarum\Extension\ExtensionManager;
use Flarum\Http\UrlGenerator;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Tags\TagRepository;
Expand All @@ -57,8 +56,8 @@ class LastDiscussionsByTagFeedController extends TagsFeedController
{
protected $routeName = 'tag_discussions';

public function __construct(Factory $view, ApiClient $api, TranslatorInterface $translator, SettingsRepositoryInterface $settings, UrlGenerator $url, ExtensionManager $extensions, TagRepository $tagRepository)
public function __construct(Factory $view, ApiClient $api, TranslatorInterface $translator, SettingsRepositoryInterface $settings, UrlGenerator $url, TagRepository $tagRepository)
{
parent::__construct($view, $api, $translator, $settings, $url, $extensions, $tagRepository, true);
parent::__construct($view, $api, $translator, $settings, $url, $tagRepository, true);
}
}
7 changes: 1 addition & 6 deletions src/Controller/TagsFeedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
namespace IanM\FlarumFeeds\Controller;

use Flarum\Api\Client as ApiClient;
use Flarum\Extension\ExtensionManager;
use Flarum\Http\Exception\RouteNotFoundException;
use Flarum\Http\UrlGenerator;
use Flarum\Settings\SettingsRepositoryInterface;
Expand All @@ -62,15 +61,11 @@ class TagsFeedController extends DiscussionsActivityFeedController
*/
private $tagRepository;

public function __construct(Factory $view, ApiClient $api, TranslatorInterface $translator, SettingsRepositoryInterface $settings, UrlGenerator $url, ExtensionManager $extensions, TagRepository $tagRepository, $lastTopics = false)
public function __construct(Factory $view, ApiClient $api, TranslatorInterface $translator, SettingsRepositoryInterface $settings, UrlGenerator $url, TagRepository $tagRepository, $lastTopics = false)
{
parent::__construct($view, $api, $translator, $settings, $url, $lastTopics);

$this->tagRepository = $tagRepository;

if (!$extensions->isEnabled('flarum-tags')) {
throw new RouteNotFoundException('Tag feeds not available without the tag extension.');
}
}

protected function getTags(Request $request)
Expand Down

0 comments on commit b5baaa6

Please sign in to comment.