1

I was wondering if there is some way to ignore warning generated by PHP_CodeSniffer which refer to Eloquent mappings.

For example:

/**
 * @param User $user
 * @param string $message
 * @param string $type
 * @return Comment
 * @throws Exception
 */
public function createComment(User $user, $message, $type)
{
    $comment = new Comment();
    $comment->creator()->associate($user);
    $comment->Message = $message;          //PHPCS warning: Property accessed via magic method         
    $comment->AddedDate = new Carbon();    
    $comment->Type = $type;
    $comment->save();
    return $comment;
}

P.S: I wouldn't want to exclude this warnings that are not related to Models (keep them for other class tipes), and preferably exclude setters and getters fora each property

ka_lin
  • 9,329
  • 6
  • 35
  • 56
  • 1
    Search for ide-helper for laravel. It's a package that generate phpdoc for this fields and fix this warnings. – Elias Soares Jan 30 '20 at 01:36
  • 1
    Or document the model with [@property](https://docs.phpdoc.org/latest/references/phpdoc/tags/property.html) Since it's retrieving database values you cannot strictly type it except for attribute setters and getters inside Eloquent. But you can satisfy the inspection via this phpDoc way. – Rimble Jan 30 '20 at 01:52

1 Answers1

1

If "Comment" is a Model you have created, add class phpDoc comments to hint the IDE about the properties available.

/**
 * Class Comment
 * @property int id
 * @property string Message
 */
class Comment extends Model {

This is good for auto-complete as well

xelber
  • 4,197
  • 3
  • 25
  • 33