Gert-dev / php-ide-serenata

Atom IDE package that integrates the Serenata server to provide PHP code assistance
https://serenata.gitlab.io/
Other
274 stars 19 forks source link

A small problem with PHP document annotations #455

Closed linjialiang closed 5 years ago

linjialiang commented 5 years ago

The php-idea-serenata plug-in will report an error to the integer annotation and must use an int, but the atom annotation plug-in docblockr will only generate an integer

1

linjialiang commented 5 years ago

Now that I can only disable these three features, the PHP framework looks normal

snipaste_2018-11-05_15-25-07

linjialiang commented 5 years ago

@Gert-dev

infomaniac50 commented 5 years ago

Scalar types can not be aliased in PHP 7. An integer must be declared with int. PHP 7 will interpret integer as a class or interface name. [1.]

Docblockr is at fault here for not following the PHP spec. You can change this behavior in Docblockr by setting short_primitives = true [2.]

Here is some code that tests the differences between int and integer. https://ideone.com/sxDV1o

  1. http://php.net/manual/en/functions.arguments.php#functions.arguments.type-declaration
  2. https://github.com/nikhilkalige/docblockr#configuration
linjialiang commented 5 years ago

All right, docblockr is a relatively simple change to a single code, mainly because PHP framework annotations are integer

infomaniac50 commented 5 years ago

There was an issue about this long ago on Docblockr's repo. https://github.com/nikhilkalige/docblockr/issues/153

Just set short_primitives = true and then you don't have to worry about anymore.

I don't know which PHP framework you are talking about. If they are using integer then they are wrong. All annotations and type hints should use the short forms; bool, int, and float. Everything else is invalid and will only cause problems.

Even PHP itself is wrong. The error message Argument 1 passed to Thing::doStuffWithInteger() must be an instance of integer, integer given should be Argument 1 passed to Thing::doStuffWithInteger() must be an instance of integer, int given. Nobody has gotten around to implementing the correct semantics in the PHP interpreter. The phrase must be an instance of integer, integer given is just too confusing.

linjialiang commented 5 years ago

Ok, I will give feedback to the framework author

Gert-dev commented 5 years ago

@linjialiang I've also replied in #454, please don't create duplicate issues, though.

@infomaniac50 is right: integer is a name that predates PHP 7 type hints and should probably be avoided in new code. Thanks for following this up for me, by the way!