Remove redundant counters and optimize loops
Just found your tiny CMS and liked the performance so decided to look under the hood and thought I can pay back my 5 cents on a few code improvements to remove unnecessary counter variables and provide some code improvements.
Having that said, the original code would definitely work as is, it is just as small improvement in terms of readability and habits of PHP Devs to use $key => $value in for() loops. Besides that, I've added a few checks to prevent unnecessary loops where a break was needed where an if() criteria is not met... Like I said, Share-ing is Care-ing ;)
Hello,
Thanks for the PR. Yes, it is quite old code indeed, and there are many functions that need to be refactored. Let's try to improve it in the future.
I already reviewed it. There is one problem, so when the contents of views.json are empty or the file does not exist, it takes some of the latest posts. It should display: <ul><li>No popular posts found</li></ul>
I will have a look, maybe I overdid some parts as I am not 100% sure how to test all functions and it might have slipped through. If you have any idea on the method responsible for it, it will speed the things up as I've touched a few and have to dig a bit deeper now :)