diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 0000000..9ce3b0e --- /dev/null +++ b/.github/workflows/backend.yml @@ -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: . diff --git a/.github/workflows/build.yml b/.github/workflows/frontend.yml similarity index 88% rename from .github/workflows/build.yml rename to .github/workflows/frontend.yml index ca3526b..ac91dac 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/frontend.yml @@ -1,4 +1,4 @@ -name: Javascript +name: Syndication JS on: [workflow_dispatch, push, pull_request] @@ -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 }} diff --git a/composer.json b/composer.json index 7d27535..4ea09dd 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ } ], "require": { - "flarum/core": "^1.3.1" + "flarum/core": "^1.8.3" }, "extra": { "flarum-extension": { @@ -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" } } diff --git a/extend.php b/extend.php index 05715ad..5258d4e 100644 --- a/extend.php +++ b/extend.php @@ -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), @@ -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) + ]; + }) ]; diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..03cf261 --- /dev/null +++ b/phpstan.neon @@ -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'] diff --git a/src/Controller/AbstractFeedController.php b/src/Controller/AbstractFeedController.php index 82a2a3f..f75869b 100644 --- a/src/Controller/AbstractFeedController.php +++ b/src/Controller/AbstractFeedController.php @@ -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; @@ -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) { @@ -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); diff --git a/src/Controller/LastDiscussionsByTagFeedController.php b/src/Controller/LastDiscussionsByTagFeedController.php index e72e542..65647d8 100644 --- a/src/Controller/LastDiscussionsByTagFeedController.php +++ b/src/Controller/LastDiscussionsByTagFeedController.php @@ -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; @@ -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); } } diff --git a/src/Controller/TagsFeedController.php b/src/Controller/TagsFeedController.php index c56d7b6..9813839 100644 --- a/src/Controller/TagsFeedController.php +++ b/src/Controller/TagsFeedController.php @@ -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; @@ -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)