1
0
mirror of https://github.com/flarum/core.git synced 2025-08-10 18:35:56 +02:00

chore(phpstan): enable phpstan in bundled extensions (#3667)

* feat(phpstan): pick up extended model relations typings
* feat(phpstan): pick up extended model date attributes
* feat(core): introduce `castAttribute` extender
Stops using `dates` as it's deprecated in laravel 8
* feat(phpstan): pick up extended model attributes through casts
* fix: extenders not resolved when declared namespace
* fix(phpstan): new model attributes are always nullable
* chore(phpstan): add helpful cache clearing command
* Apply fixes from StyleCI
* chore: improve extend files provider logic
* chore: rename `castAttribute` to just `cast`
* chore: update phpstan package to detect `cast` method
* chore: enable phpstan in bundled extensions
* chore: rebasing conflicts
* chore: rebasing conflicts
* chore: typings for latest 1.7 changes

Signed-off-by: Sami Mazouz <sychocouldy@gmail.com>
This commit is contained in:
Sami Mazouz
2023-01-19 21:49:38 +01:00
committed by GitHub
parent ccf9442d79
commit da1bf8da21
59 changed files with 215 additions and 138 deletions

View File

@@ -16,6 +16,7 @@ use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\User\User;
use Illuminate\Support\Str;
use s9e\TextFormatter\Configurator;
use s9e\TextFormatter\Parser\Tag;
class ConfigureMentions
{
@@ -39,7 +40,7 @@ class ConfigureMentions
$this->configureGroupMentions($config);
}
private function configureUserMentions(Configurator $config)
private function configureUserMentions(Configurator $config): void
{
$config->rendering->parameters['PROFILE_URL'] = $this->url->to('forum')->route('user', ['username' => '']);
@@ -66,9 +67,8 @@ class ConfigureMentions
}
/**
* @param $tag
*
* @return bool
* @param Tag $tag
* @return bool|void
*/
public static function addUserId($tag)
{
@@ -81,7 +81,7 @@ class ConfigureMentions
}
if (isset($user)) {
$tag->setAttribute('id', $user->id);
$tag->setAttribute('id', (string) $user->id);
$tag->setAttribute('displayname', $user->display_name);
return true;
@@ -90,7 +90,7 @@ class ConfigureMentions
$tag->invalidate();
}
private function configurePostMentions(Configurator $config)
private function configurePostMentions(Configurator $config): void
{
$config->rendering->parameters['DISCUSSION_URL'] = $this->url->to('forum')->route('discussion', ['id' => '']);
@@ -122,8 +122,8 @@ class ConfigureMentions
}
/**
* @param $tag
* @return bool
* @param Tag $tag
* @return bool|void
*/
public static function addPostId($tag, User $actor)
{
@@ -132,8 +132,8 @@ class ConfigureMentions
->find($tag->getAttribute('id'));
if ($post) {
$tag->setAttribute('discussionid', (int) $post->discussion_id);
$tag->setAttribute('number', (int) $post->number);
$tag->setAttribute('discussionid', (string) $post->discussion_id);
$tag->setAttribute('number', (string) $post->number);
if ($post->user) {
$tag->setAttribute('displayname', $post->user->display_name);
@@ -171,7 +171,7 @@ class ConfigureMentions
/**
* @param $tag
* @return bool
* @return bool|void
*/
public static function addGroupId($tag)
{
@@ -208,7 +208,7 @@ class ConfigureMentions
$hexNumbers = Str::replace('#', '', $hexColor);
if (Str::length($hexNumbers) === 3) {
$hexNumbers += $hexNumbers;
$hexNumbers .= $hexNumbers;
}
$r = hexdec(Str::substr($hexNumbers, 0, 2));

View File

@@ -29,11 +29,11 @@ class FormatPostMentions
/**
* Configure rendering for post mentions.
*
* @param s9e\TextFormatter\Renderer $renderer
* @param \s9e\TextFormatter\Renderer $renderer
* @param mixed $context
* @param string|null $xml
* @param Psr\Http\Message\ServerRequestInterface $request
* @return void
* @param \Psr\Http\Message\ServerRequestInterface $request
* @return string
*/
public function __invoke(Renderer $renderer, $context, $xml, Request $request = null)
{

View File

@@ -37,9 +37,9 @@ class FormatUserMentions
/**
* Configure rendering for user mentions.
*
* @param s9e\TextFormatter\Renderer $renderer
* @param \s9e\TextFormatter\Renderer $renderer
* @param mixed $context
* @param string|null $xml
* @param string $xml
* @return string $xml to be rendered
*/
public function __invoke(Renderer $renderer, $context, string $xml)

View File

@@ -40,7 +40,7 @@ class UpdateMentionsMetadataWhenVisible
*/
public function handle($event)
{
$content = $event->post->parsedContent;
$content = $event->post->parsed_content;
$this->syncUserMentions(
$event->post,