Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Probably missing attribute classes? #37

Closed
toddy15 opened this issue Apr 27, 2021 · 4 comments
Closed

Probably missing attribute classes? #37

toddy15 opened this issue Apr 27, 2021 · 4 comments

Comments

@toddy15
Copy link
Contributor

toddy15 commented Apr 27, 2021

Q A
Type Bug
Concorcet version 3.0.1
PHP version 8.0.3
Installation Method Custom

Hi,

first, thanks a lot for this very nice library. I'm looking into the source code and cloned your repository. While browsing your sources, I noticed that you're using the new attributes feature of PHP8.

However, you write e.g. this:
use CondorcetPHP\Condorcet\CondorcetDocAttributes\{Description, Examples, FunctionReturn, PublicAPI, Related};

There are no corresponding classes, there is not even a "CondorcetDocAttributes" folder in your project. Maybe you've created those files locally and did not yet add them to the git repository?

Regards,
Tobias

@julien-boudry
Copy link
Owner

Hi @toddy15

Actually, I never need to use the corresponding attribute class (static or object). I must declare them with use keywords, but then, I use reflection based on the class name, to read the value of the attribute; so PHP never needs to load the corresponding class. It's used only for documentation generation.

PHP 8 allows it. If there is a PSR for attributes class, properties for documentation, probably I will use it instead. But there is not yet, so I have build a custom system.

@julien-boudry
Copy link
Owner

julien-boudry commented Apr 28, 2021

To be more precise : The use it only for using then alias. If I don't make the use, then I must do it each time :

#[CondorcetPHP\Condorcet\CondorcetDocAttributes\Description("Get the actual Ranking of this Vote.")] #[CondorcetPHP\Condorcet\CondorcetDocAttributes\FunctionReturn("Multidimenssionnal array populated by Candidate object.")] #[CondorcetPHP\Condorcet\CondorcetDocAttributes\Related("Vote::setRanking")] public function getRanking () : array { return $this->_ranking; }

@toddy15
Copy link
Contributor Author

toddy15 commented Apr 28, 2021

Yes, I see, it does not make sense to use that long form for the attributes. However, it seems to me that creating minimal classes for attributes is recommended by PHP, see https://www.php.net/manual/en/language.attributes.classes.php for details.

I've just created PR #39 with new classes, please take a look and decide if that works for you.

@julien-boudry
Copy link
Owner

#39 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants