erichard / SublimePHPCompanion

A Sublime Text plugin that provides cool stuff for PHP 5.3+ coding session.
MIT License
932 stars 115 forks source link

Avoid problem when argument has type hinting #147

Closed ptcong closed 2 years ago

ptcong commented 2 years ago

Users should insert comma by themselves

erichard commented 2 years ago

Hello @ptcong. I don't see the problem with typehint when using this feature.

Can you provide a use case where you have a problem ?

ptcong commented 2 years ago

For example,

class A {
public function __construct(HintA $a @1)
}

When you at @1 then press CMD + E, it will do

class A {
public function __construct(HintA $a, $PROPERTY)
}

but if you watn to use type hint as a class (not php native type)

class A {
public function __construct(HintA $a, HintB @2)
}

at @2, when press CMD + E, it will be:

public function __construct(HintA $a, HintB, $PROPERTY)

so have to movev the cursor to delete the comma.

Because class property does not support type hinting as a class name, so back to @1, it can't be

class A {
protected HintB $PROPERTY;
public function __construct(HintA $a, HintB $PROPERTY)
}
erichard commented 2 years ago

Ok I see.

The command can be used wherever the cursor is but need a valid constructor signature to work. And after use, you still have a valid signature function.

You are using it in a semi automated way by starting to create the argument AND fire the command to add an argument. This is not the intendend way. Maybe try to first add the argument then add the typehint. This is generally quicker as your typehint is often similar to the argument name, so you can copy/paste.

Your proposal will break the command for everyone so I can't merge your PR in this state.