PHP Frameworks Code Complexity Comparison
medium.com
medium.com
This leaves you digging through dozens of tiny files, some barely longer than the class definition itself, just to find even high level logic. I normally learn frameworks by simply reading the code, but I can't help but feel fatigued when having to try and find where a line of logic actually lives in Laravel. It is almost always a journey.
Here's a small example where things are pretty segregated:
https://github.com/illuminate/support/blob/master/Traits/Cap...
https://github.com/illuminate/queue/blob/master/Capsule/Mana...
And then the queue capsule manager is not to be confused with the database capsule manager:
https://github.com/laravel/framework/blob/master/src/Illumin...
When you're looking through a bunch of things similar to that, it can be a bit confusing to take it all in and remember what is what.
The other problem with anything built with Symfony components is that Symfony components never come with good defaults, they are a pain in the ass to instantiate manually, with huge object graphs because "decoupling". That's shouldn't be the case, one shouldn't have to create 15+ objects just to use a form factory for instance. Even Doctrine which is much more complicated than Symfony comes with acceptable defaults. Arrays/Maps of options passed as arguments of class constructors is a blatant demonstration that something is broken.
Are those pieces counted in these statistics or the "half the size" thought?
> The primary goal of this comparison is to compare how I personally write code vs. how other projects are writing code.
I find Laravel easy to understand when browsing code because of the short methods.
There are tradeoffs, of course, as sometimes it can take several hops through the code to trace down some functionality. But I prefer more short methods vs. one long method any day for readability.
Slim + Doctrine is a pretty good stack. Pick your favorite templating format and away you go. I think anyone else in modern PHP is generally overkill.
Longest Method: Sometimes the functionality provided by a method is irreducible. And breaking off chunks of it into other one-time-use methods just to reduce method length can be detrimental to readability and understanding. This is a judgement call and it's not really "bad" unless it's >1000LoC.
"Complexity": Cyclomatic complexity is a near-worthless metric, especially in a language like PHP. It's easy to convert a series of 10 if statements into one while loop by leveraging call_user_func and deterministic method names. The resulting while statement is infinitely more complex than the if statements and reduces the benefits of using an IDE. So unless your CC algorithm treats this kind of programming as wildly complex, then it's not giving you a true complexity value (in fact, it's actually lying to you).
% of non-static methods: Unless this metric also includes singleton patterns, then it's useless. Foo::bar() is no different than Foo::getInstance()->bar() or (new Foo())->bar(). Also, in PHP-land, static methods are considered acceptable, as long as they have no side-effects or use static variables.
So I think the author is genuinely wasting his time capturing and optimizing for these metrics, because I don't think they provide any meaningful improvement to the product.
Just because you have a way of cheating it, doesn't make it worthless.
I agree that cyclomatic complexity is good, but it's not enough on it's own, that's why you have other metrics, rules and manual reviews.
https://github.com/illuminate/queue/blob/master/Worker.php#L... Here's 17 LOC in the first file I checked.
Not to say that's excessive or a bad thing, just seems the count isn't quite accurate.
If they aren't counting Illuminate components, seems somewhat unfaithful, since that's really the Laravel nitty-gritty.
It's also worth noting that 'static' doesn't feel like a good metric in PHP. There's certainly not a great correlation of static to pure when you're in global-DI-container contexts. So why do we want statics? Global static singletons, too, don't feel like a particularly good pattern.
If I'm writing PHP, I -do- try to make 'static' mean 'this function accesses no globals and has no side effects', because in my opinion it can make PHP a bit cleaner, but in most PHP frameworks that's not the pattern they're going for.
In that context, the more statics the better!
Side note: The queue-related bits of Illuminate were pretty difficult to decompose and work with outside of laravel context, though that's partly because PHP is a kind of unfortunate language for worker processes in general because of how the opcache works together with a kludged CLI.
https://github.com/laravel/framework/blob/5.3/src/Illuminate...
Maybe you meant "without closing brackets"?
https://github.com/sebastianbergmann/phploc
Maybe it's doing things like contracting method calls to one line and making single statement if blocks one line.
A more fair comparison would be to compare Lavavel against both the Symfony HttpKernel component (which is the framework part of Symfony) and the Zend MVC module (which is framework part of Zend Framework). But then again, it's probably not that straight forward.
I mean, when testing Laravel the Symfony HttpFoundation component is left out but when testing Symfony it's included, not really fair..