PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, April 18, 2022

[FIXED] How to annotate Laravel Collection elements during iteration

 April 18, 2022     laravel, php, phpstorm, psalm-php     No comments   

Issue

I was thinking about how to annotate types in PhpStorm. I believe PhpStorm is using Psalm to resolve types, but I can't find how to annotate type to get suggestions here:

enter image description here

$row in my app will always be Collection object and I want to have it marked somewhere here with annotations.

Does anyone have an idea how to accomplish that?

    /**
     * @param Collection $rows
     */
    public function collection(Collection $rows)
    {
        foreach ($rows as $row)
        {
            dump($row->); // $row is also Collection object
        }
    }

Solution

you can mark var type like this:

/**
 @var $row Collection
**/
dump($row->);

https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000701884-Using-var-type-hinting-with-properties-instantiated-by-Traits



Answered By - Eden Moshe
Answer Checked By - David Goodson (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing