Skip to content

Commit

Permalink
chore(phpstan): enable phpstan in bundled extensions (#3667)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
SychO9 authored Jan 19, 2023
1 parent 25c9394 commit b9ca434
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
24 changes: 12 additions & 12 deletions src/ConfigureMentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Flarum\User\User;
use Illuminate\Support\Str;
use s9e\TextFormatter\Configurator;
use s9e\TextFormatter\Parser\Tag;

class ConfigureMentions
{
Expand All @@ -39,7 +40,7 @@ public function __invoke(Configurator $config)
$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' => '']);

Expand All @@ -66,9 +67,8 @@ private function configureUserMentions(Configurator $config)
}

/**
* @param $tag
*
* @return bool
* @param Tag $tag
* @return bool|void
*/
public static function addUserId($tag)
{
Expand All @@ -81,7 +81,7 @@ public static function addUserId($tag)
}

if (isset($user)) {
$tag->setAttribute('id', $user->id);
$tag->setAttribute('id', (string) $user->id);
$tag->setAttribute('displayname', $user->display_name);

return true;
Expand All @@ -90,7 +90,7 @@ public static function addUserId($tag)
$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' => '']);

Expand Down Expand Up @@ -122,8 +122,8 @@ private function configurePostMentions(Configurator $config)
}

/**
* @param $tag
* @return bool
* @param Tag $tag
* @return bool|void
*/
public static function addPostId($tag, User $actor)
{
Expand All @@ -132,8 +132,8 @@ public static function addPostId($tag, User $actor)
->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);
Expand Down Expand Up @@ -171,7 +171,7 @@ private function configureGroupMentions(Configurator $config)

/**
* @param $tag
* @return bool
* @return bool|void
*/
public static function addGroupId($tag)
{
Expand Down Expand Up @@ -208,7 +208,7 @@ public static function isDark(?string $hexColor): bool

$hexNumbers = Str::replace('#', '', $hexColor);
if (Str::length($hexNumbers) === 3) {
$hexNumbers += $hexNumbers;
$hexNumbers .= $hexNumbers;
}

$r = hexdec(Str::substr($hexNumbers, 0, 2));
Expand Down
6 changes: 3 additions & 3 deletions src/Formatter/FormatPostMentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function __construct(TranslatorInterface $translator)
/**
* 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)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Formatter/FormatUserMentions.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ public function __construct(SlugManager $slugManager, TranslatorInterface $trans
/**
* 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)
Expand Down
2 changes: 1 addition & 1 deletion src/Listener/UpdateMentionsMetadataWhenVisible.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(NotificationSyncer $notifications)
*/
public function handle($event)
{
$content = $event->post->parsedContent;
$content = $event->post->parsed_content;

$this->syncUserMentions(
$event->post,
Expand Down

0 comments on commit b9ca434

Please sign in to comment.