Conversation
This matches up with WP Core and constitutes a non-breaking change. As a follow-up, we should still test passing different args for terms shared between taxonomies, and define exactly what those semantics are.
See also: #2087
also make a note about a test that randomly failed because it turns out I am not a time lord.
|
Awesome, thanks @acobster! Things are looking good on the testing side. There are some failures (not in PHPUnit, but static analysis). Most of them are in code not connected to this PR — but there's one we should def. take a look at ... |
Codecov Report
@@ Coverage Diff @@
## 2.x-factories #2203 +/- ##
================================================
Coverage ? 91.28%
Complexity ? 1626
================================================
Files ? 53
Lines ? 4097
Branches ? 0
================================================
Hits ? 3740
Misses ? 357
Partials ? 0Continue to review full report at Codecov.
|
|
@jarednova thanks for that - fixed. I'll make a note to start running the analyzer before making PRs, too. @szepeviktor not directly related to this PR, but some of my code is getting flagged: what about |
|
new static() is unsafe when the class is not final. |
|
Someone can extend from your class and override the constructor with different arguments, so that your You have these options:
|
|
|
Thanks @ondrejmirtes and @szepeviktor - making the constructors final seems heavy-handed to me for this case but sound like we have some other good options. @jarednova this discussion made me realize that I never actually implemented |
|
OK @jarednova I'll have an update soon but in the meantime I wanted to get back to this discussion about the @szepeviktor - please note that this is not about the cost/benefit of syntax checks, coding standards, or static analysis in general. The net benefit of all those things is clear and is taken as a given (tip of the hat to @ondrejmirtes - I'm already liking this tool a lot more that phpcs! 😃). This is about answering the question: what is the cost vs. the benefit for our users of appeasing or ignoring this specific warning? Here is why I think each option won't work in our particular case:
class MyPost extends Post {
protected function __construct($stuff, $things) {
// do something special with $stuff and $things
}
public static function build( WP_Post $wp_post ) {
[ $stuff, $things ] = SomeApi::special_sauce();
return new static($stuff, $things);
}
}
To sum up, following the letter of this specific error just swaps out a (already very rare) Fatal Error about required arguments with one about final constructors, and moreover limits our users' movement for very little benefit to them. |
|
The most non-disrupting way would probably be to introduce a new interface implemented by the class where the |
I think a developer has to have some ground rules I am looking at things from a 2 years perspective. |
Agreed. It seems we only differ on what those ground rules are. Here are some of mine:
|
You're right. |
|
Hahaha. The WP core is a rat's nest, no two ways about it! Sometimes WP is the right tool for the job, and sometimes it isn't. |
|
Thanks everyone for the thoughts and expertise on this issue. I'm really glad we've been able to work out both the guidelines and the exceptions we need to make given the circumstances. @acobster do you have any more commits coming to this branch, or is ready for final review? |
|
@jarednova @gchtr turned out there was quite a bit more work that I'd missed once I made the constructor protected. Should be ready for review now. |
|
@gchtr I was definitely coming at it with PHPUnit-induced tunnel vision. 😆 You're right on with all of this; I'll circle back this week. Thanks for the detailed review! cc @jarednova |
|
@acobster @gchtr looking good! I second the notes/comments made above. As for ... public function terms( $query_args = [], $options = [] ) {}
Yup! I'll get to work on a PR for that Update: the PR is #2208 |
2203/post terms api
Co-Authored-By: Lukas Gächter <lukas.gaechter@mind.ch>
|
@gchtr @jarednova I think I've addressed all the review feedback except the docs update. Take another look at let me know? |
|
Copy that, added one last test — and presto! |
Implements the Terms API.
Per my recommendation on #2094, this drops support for automatically including
'hide_empty' => falsein Term query params.I did manage to keep the "corrections" e.g. fixing
taxonomies => taxonomyandtags => post_tag, etc. without too much fanfare. So we don't have to break code that relies on that.