2

i may have little be too general questions and if there are i am sorry for duplicates. (did not found the answer i was looking for).

First of all i am using symfony2 framework for developing and i am thinking about purchasing phpStorm. Its not a cheap program and i dont want to waste money. But i like it to now so i would like to ask if its a good step to future?

And my second and the main question

Sometimes happens i dont see auto-completed suggestions of methods of some objects...

Is there any way or some good practises i can do to help phpStorm understand with what object i am dealing with?

I have on my mind things like i saw in the code of someone else:

public function updateSomething(User $user

Or...

    /**
 * Draws an arc on a starting at a given x, y coordinates under a given
 * start and end angles
 *
 * @param Imagine\Image\PointInterface $center
 * @param Imagine\Image\BoxInterface   $size
 * @param integer                      $start
 * @param integer                      $end
 * @param Imagine\Image\Color          $color
 * @param integer                      $thickness
 *
 * @throws Imagine\Exception\RuntimeException
 *
 * @return DrawerInterface
 */

Do these things help and I should write them or there are just for better "user-read ability"?

2
  • My suggestion: Download a trial (30 days of full functionality) and try for yourself. This is the best option as you will be able to evaluate performance on your hardware; specific behaviour in certain features/situations; nuances in setup; have a feel o fthe app benefits; etc etc. But to answer your question -- Yes, type hints (language supported or via PHPDoc) do help a lot -- this is where IDE takes info about parameter types etc. just Ctrl+Click on any standard function/class and you will see how it's used inside (for all known to IDE classes/functions/etc) Commented Nov 11, 2013 at 21:17
  • Hm okay thx for your opinion and "answer". BTW: i of course have already phpStorm installed :) Commented Nov 11, 2013 at 21:27

1 Answer 1

2

Your first question is of a type that normally belongs outside of StackOverflow as its very subjective, there isn't really an answer, only people's opinions. For what it's worth, in my opinion PHPStorm is worth every penny compared to either a) using no IDE / a text editor, b) using the free Aptana IDE (eclipse based) which are the alternatives I tried before PHPStorm. For me there there are numerous productivity savings but one invaluable feature is the debugger which just works (once you have XDebug configured with PHP).

To answer your second question about the auto-completion of methods of some objects - Yes, both the examples you gave help and those along with additional use of PHPDoc comments should enable the PHPStorm method auto-completion to work in almost all cases. This should also have the side-effect of clearing out most of the spurious PHPStorm yellow highlights of undefined method calls so that genuine errors are more visible.

The least you can do to maximise method auto-completion:

1. Always provide type hints for method parameters where possible / appropriate - see PHP Type Hinting for more details e.g.

public function createUser (UserDetails $userDetails, array $roles)

2. Always give methods that have a return value PHPDoc comments (beginning /**) which at least define the @return type for the method (if not mixed) and the content type of any array parameters (if not mixed). e.g.

/**
 * @param UserDetails $userDetails
 * @param Role[] $roles
 * @return User
 */

3. Use PHPDoc comments with @var to define the type of class member variables and local variables e.g.

class UserManager
{
    /**
     * @var EntityManager
     */
    private $entityManager

    ...

    public function doSomething()
    {
        ...

        /** @var User $user */
        foreach($users as $user)
        {
           ...
        }
...

It is good practice generally to use PHP type hinting and to make appropriate use of PHPDoc.

Sign up to request clarification or add additional context in comments.

2 Comments

Apologies, I can't get the code to format properly. I've had this problem before. Hopefully someone it works for can edit it to fix it...
okay then. Thx for your opinion that's what i wanted hear + the answer with comments hints.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.