-
Notifications
You must be signed in to change notification settings - Fork 385
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
Use PSR-4 namespaced classes #722
Conversation
β¦ragent() method
This PR is ready for merging. It is important for me to emphasize that all changes are backward compatible! If you notice something that leads to a BC break, please let me know. Nevertheless, I would like to hear feedback about some design decisions: 1. All globally defined constants are marked as deprecated.I moved the global constants (like The
// in library/SimplePie.php
// and in src/SimplePie.php
- define('SIMPLEPIE_NAME', 'SimplePie');
+ if(! defined('SIMPLEPIE_NAME'))
+ {
+ define('SIMPLEPIE_NAME', 'SimplePie');
+ }
By moving the constants to the Is the naming of the constants ok (e.g. Should all constants be defined in 2. The constant
|
Hey @mblaney, could you please review this PR or give me feedback on what you think of the PR? If it helps, I can still try to split the PR into smaller PRs, but really the individual commits should give you the ability to track the changes. I wrote down my plan for the roadmap in #731. I have a high interest in modernizing SimplePie a bit, but I can't do that without feedback from the SimplePie team. |
hi @Art4, sorry for the delay in reviewing this PR. I think removing |
Thank you for your feedback. I will shorten the prefix
Good question. I missed that point in my comment about the design decisions, so I will add this answer. The class So to keep BC for this deprecated methods we would have to create a namespaced class for the deprecated
I will reflect this changes in the |
@mblaney I renamed all
But I think this way is better than creating a new deprecated class |
Credits to @thomasrenes See FreshRSS/FreshRSS@916df41
thanks @Art4 these changes look great! I agree that calling |
@mblaney I resolved the merge conflicts. This PR is ready for merge. |
Hey π
Small note about myself: English is not my native language, so I apologize for any language mistakes. I am a long time user of SimplePie directly or indirectly (through WordPress or other libraries). I would like to give something back to the community.
I took some time over the weekend to refactor SimplePie to use namespaces. This means that this PR
is not yet ready for merging, but relies on merging #711 and stillneeds some work and a lot of discussion.Update: This PR is nearly ready for merge!
task list
library
classes to the namespaced classessrc
folder don't use any code from thelibrary
folderclass_alias('SimplePie\Cache', 'SimplePie_Cache');
SIMPLEPIE_*
constants into theSimplePie\SimplePie
classSIMPLEPIE_*
constantsautoloader.php
demo/
folderbuild/compile.php
library
classesFollow up changes
All the changes in this PR did not change any tests, so all tests (except the new tests from #711) run with the old non-namespaced classes. I intentionally did not change the old tests to show that the old code continues to work as before. These tests need to be modified (or better yet, first copied and then modified) to test the namespaced classes directly. Update: See #730
Possible roadmap
Since I couldn't find any information about the future development of SimplePie or a roadmap, I've sketched out a possible roadmap of how these changes could be released incrementally. If I missed an existing roadmap, I would be happy to be pointed to the right place.
Update: I moved the Roadmap into a separate issue: #731
More details
1. Why should #711 be released in a minor release?
Following semantic versioning we have three options:
2. Why did you move the
SIMPLEPIE_*
constants into theSimplePie\SimplePie
class?The
SIMPLEPIE_*
constants are defined in filelibrary/SimplePie.php
next to the class definition, but no code in thesrc
folder should use code from the oldlibrary
folder. Sure, we have the option to move the constant definitions in another file inside thesrc
folder. But this would also lead to two downsides.library/SimplePie.php
or the newsrc/SimplePie.php
file (so we don't know, which file would be load first) we have to keep and maintain this code in two places:By moving the constants to the
SimplePie\SimplePie
class, I was able to work around both issues. At the same time, we keep the global namespace clean of our constants, most of which are only used internally anyway.However, two questions remain that should be discussed:
SimplePie\SimplePie::SIMPLEPIE_NAME
), or should we rename them (e.g.SimplePie\SimplePie::NAME
)?SimplePie\SimplePie
or should we split them into different classes, where they will be primary used or even in a special constant class (e.g.\SimplePie\Constants::NAMESPACE_RSS_090
instead of\SimplePie\SimplePie::SIMPLEPIE_NAMESPACE_RSS_090
)?Trivia
When submitting a pull request
I've installed temporary PHPStan and analyzed the code in folders
src
andlibrary
with level 0 and fixed all errors and significant warnings.I've run
bin/phpunit
and all tests succeeded.β
Please see the single commits for better understanding of the refactoring.
Yes, this PR could definitely be done in many smaller chunks over a bigger time period. But I wanted to show how the result at the end will look like. I'm fully aware that this PR is possibly to big and could be closed or has to be reworked.
β
β
β
I would be happy to do this. π Let's talk and discuss!
β