Skip to content

Commit

Permalink
Check whether ->state is null before checking its user id
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Jul 13, 2024
1 parent f11d7e1 commit e2266cb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/AddTagSubscriptionAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ public function __invoke(TagSerializer $serializer, Tag $tag, array $attributes)
*/
public function getStateFor(Tag $tag, User $actor): TagState
{
if (!$tag->relationLoaded('state') || $tag->state->user_id !== $actor->id) {
// If $tag->state is loaded *and* null, this might be because the actor doesn't have tag-specific state
// OR because the wrong actor has been used for loading it. `$tag->stateFor()` will return the correct state.
// If it doesn't exist, it returns a dummy state with the correct actor & tag IDs.
if (!$tag->relationLoaded('state') || is_null($tag->state) || $tag->state->user_id !== $actor->id) {

Check failure on line 44 in src/AddTagSubscriptionAttribute.php

View workflow job for this annotation

GitHub Actions / run / PHPStan PHP 8.0

Call to function is_null() with Flarum\Tags\TagState will always evaluate to false.

Check failure on line 44 in src/AddTagSubscriptionAttribute.php

View workflow job for this annotation

GitHub Actions / run / PHPStan PHP 8.2

Call to function is_null() with Flarum\Tags\TagState will always evaluate to false.
$tag->setRelation('state', $tag->stateFor($actor));
}

Expand Down

0 comments on commit e2266cb

Please sign in to comment.