XF 2.2 UserAlert Author

LPH

Well-known member
The following code has worked for quite some time, but I've moved it to its own class and am now getting the statement:

Expected parameter of type 'void|\XF\Entity\User', '\XF\Mvc\Entity\Entity' provided

PHP:
   /**
     * @param $post
     *
     * @return void
     */
    public function setAlert($post){

        $author = XF::app()->find('XF:User', $post->post_author);

        // Get thread ID from WordPress post meta in order to get first post id
        $thread_ID = get_post_meta( $post->ID, 'thread_id', true );

        $thread = XF::app()->find( 'XF:Thread', $thread_ID );

        $alertUsers = XF::app()->finder('XF:User')->fetch();

        foreach ( $alertUsers AS $alertUser ) {
            /** @var UserAlert $alertRepo */
            $alertRepo = XF::app()->repository('XF:UserAlert');

            $alertRepo->alertFromUser($alertUser, $author, 'post', $thread['first_post_id'], 'insert');
        }
    }

The author is pulled using find.

PHP:
$author = XF::app()->find('XF:User', $post->post_author);

Is that the issue? And is there a better way to pull the author?

Update: Added a comment to the $author in order to remove the message

PHP:
        /** @var XF\Entity\User $author */
        $author = XF::app()->find('XF:User', $post->post_author);

But is that appropriate?
 
Last edited:
But is that appropriate?
Assuming this is just a lint message from your IDE/editor, yeah. If you are using PhpStorm (or a language server/linter which supports PhpStorm metadata), you can export metadata by running php cmd.php xf-dev:generate-phpstorm-meta which will improve hinting for a lot of return types automatically.
 
Top Bottom