eloquent / enumeration

An enumeration implementation for PHP.
MIT License
147 stars 8 forks source link

Improve documentation #22

Open berturion opened 8 years ago

berturion commented 8 years ago

Hi, In Java Styles enumeration implementations, members are called with static methods that are not explicitly declared. So, in IDE like Eclipse PHP or other, those methods are not listed for auto-completion.

I found that adding appropriate PHPDocumentor doc blocks resolves this issue.

For example, if you have those members in a Exemple class extending AbstractMultiton:

Exemple::FOO()
Exemple::BAR()

You can add this doc block:

/**
 * @method static Exemple FOO()
 * @method static Exemple BAR()
 */
class Exemple extends AbstractMultiton
{
    (...)
}

Trust me, it is very useful !

ezzatron commented 8 years ago

Seems like useful information to have. I'll try to include this in the README when I get a chance.

Bilge commented 8 years ago

This is entirely unnecessary. If you do not like those semantics use Enumeration::memberByKey() instead. Static analysis will work in your editor with this calling convention.

berturion commented 8 years ago

I agree, this is not necessary, but it is more convenient, at least for me.

Exemple::FOO() is shorter than Exemple::memberByKey(Exemple::FOO) or Exemple::memberByKey('FOO') and auto-completion in IDE is called once instead of two.

Without those @method annotations, auto-completion only propose the static member of the enumeration (FOO) so we always need to add parentheses at the end to call the Enumeration object (FOO()). But the IDE doesn't recognize the static method Exemple::FOO() because it is not explicitly declared.

Anyway, it is up to you to add this tip. I just wanted to share it. You can close the issue if you mind.

Bilge commented 7 years ago

Perhaps you should submit a PR rather than an issue if you want to share this information.