Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions .github/workflows/REUSABLE_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,24 +94,10 @@ jobs:
prefix: flarum_
prefixStr: (prefix)

# @TODO: remove in 2.0
# Include testing PHP 8.2 with deprecation warnings disabled.
- php: 8.2
php_ini_values: error_reporting=E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED

# To reduce number of actions, we exclude some PHP versions from running with some DB versions.
exclude:
- php: ${{ fromJSON(inputs.php_versions)[1] }}
service: 'mysql:8.0.30'
- php: ${{ fromJSON(inputs.php_versions)[2] }}
service: 'mysql:8.0.30'
- php: ${{ fromJSON(inputs.php_versions)[3] }}
service: 'mysql:8.0.30'

# @TODO: remove in 2.0
# Exclude testing PHP 8.2 with deprecation warnings enabled.
- php: 8.2
php_ini_values: error_reporting=E_ALL

services:
mysql:
Expand All @@ -137,14 +123,10 @@ jobs:
tools: phpunit, composer:v2
ini-values: ${{ matrix.php_ini_values }}

# The authentication alter is necessary because newer mysql versions use the `caching_sha2_password` driver,
# which isn't supported prior to PHP7.4
# When we drop support for PHP7.3, we should remove this from the setup.
- name: Create MySQL Database
run: |
sudo systemctl start mysql
mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 13306
mysql -uroot -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'root';" --port 13306

- name: Install Composer dependencies
run: composer install
Expand Down Expand Up @@ -180,6 +162,12 @@ jobs:
matrix:
php: ${{ fromJSON(inputs.php_versions) }}

services:
mysql:
image: mysql:8.0.30
ports:
- 33306:3306

name: 'PHPStan PHP ${{ matrix.php }}'

if: >-
Expand All @@ -202,5 +190,15 @@ jobs:
run: composer install
working-directory: ${{ inputs.backend_directory }}

- name: Create MySQL Database
run: |
sudo systemctl start mysql
mysql -uroot -proot -e 'CREATE DATABASE flarum_test;' --port 33306

- name: Run PHPStan
run: composer analyse:phpstan
env:
DB_PORT: 33306
DB_PASSWORD: root
COMPOSER_PROCESS_TIMEOUT: 600
FLARUM_TEST_TMP_DIR_LOCAL: ./tmp
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
"symfony/console": "^6.3",
"symfony/event-dispatcher": "^6.3",
"symfony/http-client": "^6.3",
"symfony/mailer": "^6.3",
"symfony/mailgun-mailer": "^6.3",
"symfony/mime": "^6.3",
"symfony/polyfill-intl-messageformatter": "^1.27",
"symfony/postmark-mailer": "^6.3",
Expand All @@ -164,7 +166,7 @@
"wikimedia/less.php": "^3.0"
},
"require-dev": {
"mockery/mockery": "^1.4",
"mockery/mockery": "^1.5",
"phpunit/phpunit": "^9.0",
"phpstan/phpstan": "^1.10.0",
"nunomaduro/larastan": "^2.6",
Expand Down
15 changes: 8 additions & 7 deletions extensions/mentions/src/ConfigureMentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Flarum\Extension\ExtensionManager;
use Flarum\Group\Group;
use Flarum\Http\UrlGenerator;
use Flarum\Post\Post;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Tags\Tag;
use Flarum\User\User;
Expand Down Expand Up @@ -80,10 +81,10 @@ private function configureUserMentions(Configurator $config): void

/**
* @param FormatterTag $tag
* @param array<string, Collection> $mentions
* @param array{users: Collection<int, User>} $mentions
* @return bool|void
*/
public static function addUserId($tag, array $mentions)
public static function addUserId(FormatterTag $tag, array $mentions)
{
$allow_username_format = (bool) resolve(SettingsRepositoryInterface::class)->get('flarum-mentions.allow_username_format');

Expand Down Expand Up @@ -139,10 +140,10 @@ private function configurePostMentions(Configurator $config): void

/**
* @param FormatterTag $tag
* @param array<string, Collection> $mentions
* @param array{posts: Collection<int, Post>} $mentions
* @return bool|void
*/
public static function addPostId($tag, array $mentions)
public static function addPostId(FormatterTag $tag, array $mentions)
{
$post = $mentions['posts']->where('id', $tag->getAttribute('id'))->first();

Expand Down Expand Up @@ -212,7 +213,7 @@ private function configureGroupMentions(Configurator $config)
/**
* @param FormatterTag $tag
* @param User $actor
* @param array<string, Collection> $mentions
* @param array{groups: Collection<int, Group>} $mentions
* @return bool|void
*/
public static function addGroupId(FormatterTag $tag, User $actor, array $mentions)
Expand All @@ -228,7 +229,7 @@ public static function addGroupId(FormatterTag $tag, User $actor, array $mention
$group = $mentions['groups']->where('id', $id)->first();

if ($group) {
$tag->setAttribute('id', $group->id);
$tag->setAttribute('id', (string) $group->id);
$tag->setAttribute('groupname', $group->name_plural);

return true;
Expand Down Expand Up @@ -301,7 +302,7 @@ private function configureTagMentions(Configurator $config)

/**
* @param FormatterTag $tag
* @param array<string, Collection> $mentions
* @param array{tags: Collection<int, Tag>} $mentions
* @return true|void
*/
public static function addTagId(FormatterTag $tag, array $mentions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public function run(InputInterface $input, ?Task $task = null): ComposerOutput
$exitCode = $this->application->run($input, $this->output);
chdir($currDir);

// @phpstan-ignore-next-line
$command = $input->__toString();
$output = $this->output->fetch();

Expand Down
2 changes: 1 addition & 1 deletion extensions/pusher/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
],
"require": {
"flarum/core": "^2.0",
"pusher/pusher-php-server": "^2.2"
"pusher/pusher-php-server": "^7.2"
},
"require-dev": {
"flarum/tags": "^1.0"
Expand Down
3 changes: 1 addition & 2 deletions extensions/pusher/src/Api/Controller/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Pusher;
use Pusher\Pusher;

class AuthController implements RequestHandlerInterface
{
Expand All @@ -36,7 +36,6 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$this->settings->get('flarum-pusher.app_key'),
$this->settings->get('flarum-pusher.app_secret'),
$this->settings->get('flarum-pusher.app_id'),
// @phpstan-ignore-next-line
['cluster' => $this->settings->get('flarum-pusher.app_cluster')]
);

Expand Down
6 changes: 3 additions & 3 deletions extensions/pusher/src/Listener/PushNewPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Flarum\User\Guest;
use Flarum\User\User;
use Illuminate\Support\Str;
use Pusher;
use Pusher\Pusher;

class PushNewPost
{
Expand All @@ -32,15 +32,15 @@ public function handle(Posted $event): void
$channels[] = 'public';
} else {
// Retrieve private channels, used for each user.
$response = $this->pusher->get_channels([
$response = $this->pusher->getChannels([
'filter_by_prefix' => 'private-user'
]);

// @phpstan-ignore-next-line
if (! $response) {
return;
}

// @phpstan-ignore-next-line
foreach ($response->channels as $name => $channel) {
$userId = Str::after($name, 'private-user');

Expand Down
3 changes: 1 addition & 2 deletions extensions/pusher/src/Provider/PusherProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

use Flarum\Foundation\AbstractServiceProvider;
use Flarum\Settings\SettingsRepositoryInterface;
use Pusher;
use Pusher\Pusher;

class PusherProvider extends AbstractServiceProvider
{
Expand All @@ -30,7 +30,6 @@ public function register(): void
$settings->get('flarum-pusher.app_key'),
$settings->get('flarum-pusher.app_secret'),
$settings->get('flarum-pusher.app_id'),
// @phpstan-ignore-next-line
$options
);
});
Expand Down
2 changes: 1 addition & 1 deletion extensions/pusher/src/SendPusherNotificationsJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Flarum\Notification\Blueprint\BlueprintInterface;
use Flarum\Queue\AbstractJob;
use Flarum\User\User;
use Pusher;
use Pusher\Pusher;

class SendPusherNotificationsJob extends AbstractJob
{
Expand Down
1 change: 1 addition & 0 deletions extensions/tags/src/Listener/UpdateTagMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public function whenPostIsRestored(PostRestored $event): void
}

/**
* @param Collection<int, Tag>|null $tags
* @param Post|null $post This is only used when a post has been hidden
*/
protected function updateTags(Discussion $discussion, int $delta = 0, ?Collection $tags = null, ?Post $post = null): void
Expand Down
4 changes: 2 additions & 2 deletions extensions/tags/src/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
*
* @property TagState $state
* @property Tag|null $parent
* @property-read Collection<Tag> $children
* @property-read Collection<Discussion> $discussions
* @property-read Collection<int, Tag> $children
* @property-read Collection<int, Discussion> $discussions
* @property Discussion|null $lastPostedDiscussion
* @property User|null $lastPostedUser
*/
Expand Down
2 changes: 1 addition & 1 deletion extensions/tags/src/TagRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function findOrFail(int $id, User $actor = null): Tag
* Find all tags, optionally making sure they are visible to a
* certain user.
*
* @return Collection<Tag>
* @return Collection<int, Tag>
*/
public function all(User $user = null): Collection
{
Expand Down
9 changes: 7 additions & 2 deletions framework/core/src/Api/ApiKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,18 @@
* @property string|null $allowed_ips
* @property string|null $scopes
* @property int|null $user_id
* @property \Flarum\User\User|null $user
* @property \Carbon\Carbon $created_at
* @property \Carbon\Carbon|null $last_activity_at
* @property-read \Flarum\User\User|null $user
*/
class ApiKey extends AbstractModel
{
protected $casts = ['last_activity_at' => 'datetime'];
protected $casts = [
'id' => 'integer',
'user_id' => 'integer',
'created_at' => 'datetime',
'last_activity_at' => 'datetime'
];

public static function generate(): static
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private function loadPosts(Discussion $discussion, User $actor, int $offset, int

/** @var Post $post */
foreach ($posts as $post) {
$post->discussion = $discussion;
$post->setRelation('discussion', $discussion);
}

$this->loadRelations($posts, $include, $request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Flarum\Http\RememberAccessToken;
use Flarum\Http\RequestUtil;
use Flarum\Http\SessionAccessToken;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Psr\Http\Message\ServerRequestInterface;

class TerminateAllOtherSessionsController extends AbstractDeleteController
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Flarum\Discussion\Command\ReadDiscussion;
use Flarum\Discussion\Discussion;
use Flarum\Http\RequestUtil;
use Flarum\Post\Post;
use Illuminate\Contracts\Bus\Dispatcher;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Arr;
Expand All @@ -35,6 +36,7 @@ protected function data(ServerRequestInterface $request, Document $document): Di
$discussionId = Arr::get($request->getQueryParams(), 'id');
$data = Arr::get($request->getParsedBody(), 'data', []);

/** @var Discussion $discussion */
$discussion = $this->bus->dispatch(
new EditDiscussion($discussionId, $actor, $data)
);
Expand All @@ -50,6 +52,7 @@ protected function data(ServerRequestInterface $request, Document $document): Di
}

if ($posts = $discussion->getModifiedPosts()) {
/** @var Collection<int, Post> $posts */
$posts = (new Collection($posts))->load('discussion', 'user');
$discussionPosts = $discussion->posts()->whereVisibleTo($actor)->oldest()->pluck('id')->all();

Expand Down
4 changes: 1 addition & 3 deletions framework/core/src/Api/Serializer/AbstractSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,9 @@ protected function getRelationshipData(object|array $model, string $relation): m
{
if (is_object($model)) {
return $model->$relation;
} elseif (is_array($model)) {
return $model[$relation];
}

return null;
return $model[$relation];
}

/**
Expand Down
1 change: 1 addition & 0 deletions framework/core/src/Console/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Schedule extends LaravelSchedule
{
public function dueEvents($app)
{
/** @phpstan-ignore-next-line */
return (new Collection($this->events))->filter->isDue(new class($app) {
protected Config $config;

Expand Down
7 changes: 7 additions & 0 deletions framework/core/src/Database/Eloquent/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@

namespace Flarum\Database\Eloquent;

use Flarum\Database\AbstractModel;
use Illuminate\Database\Eloquent\Collection as BaseCollection;

/**
* @template TKey of array-key
* @template TModel of AbstractModel
*
* @extends BaseCollection<TKey, TModel>
*/
class Collection extends BaseCollection
{
/**
Expand Down
Loading