WP_Query::get_posts()

Every call to retrieve posts goes through WP_Query, and the bulk of the logic is in the method get_posts. Here’s some potentially useful information about the current state of what is arguably the most important function in WordPress.

WP_Query::get_posts is 890 lines long, and has a cyclomatic complexity of 256. A good cyclomatic complexity is ~2-6, with a maximum of 10.

WP_Query::get_posts has an NPath complexity of 1.43573394139742×10^48. This can also be expressed as:

1,435,733,941,397,422,709,124,940,625,188,500,371,668,992,000,000

Or 1.435 Quindecillion. This is 25 orders of magnitude greater than the number of stars in the visible universe. It is also the number of unit tests required to fully test WP_Query::get_posts.

Should unit tests be written for WP_Query::get_posts, averaging 1.5kb each, and these tests are stored on 1TB Samsung Hard drives weighing 0.4kg each, the resulting storage would weigh a little more than 4 solar masses, or 80 Undecillion KG. For comparison, the smallest stellar black hole known is XTE J1650-500, weighing in at 3.8 solar masses

The bright star shown, Beta Sagittae is of a similar weight, perhaps this is the location of the missing unit tests?

The bright star shown, Beta Sagittae, is of a similar weight, perhaps this is the location of the missing unit tests?

7 thoughts on “WP_Query::get_posts()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.