Last week as I was refactoring and cleaning Laravel for the 5.4 release, Graham Campbell showed me some code complexity statistics for the framework. I decided to compare this against some other PHP frameworks to see how Laravel stacks up.

I looked at a few metrics. One is average method complexity which is a measurement of Cyclomatic complexity. When looking at this score, lower is better. While not an absolute “end-all” metric to measuring code quality, it does give a decent indicator of “hot spots” in your code that could use refactoring.

I was pleased to see Laravel has the lowest average method complexity of any of the frameworks measured. In addition, Laravel does not contain any method longer than 13 lines of code. The only two frameworks with a maximum method complexity under 50 were Laravel (17) and Slim (13). No framework other than Laravel had an average method complexity under 2.

It is worth noting that Laravel utilizes Symfony’s HTTPFoundation component and Console component. No other Symfony components are heavily utilized throughout the framework. The primary goal of this comparison is to compare how *I* personally write code vs. how other projects are writing code. All project’s measured have a large enough sample size of pure, first-party code to accurately measure that.

I also measured Laravel’s Eloquent ORM against Doctrine’s ORM. The results of that comparison can be found at the bottom of the result listing.

Laravel

Lines of code: 54,398

Longest method: 13 lines of code

Average method complexity: 1.62

Maximum method complexity: 17

Percentage of methods that are non-static: 94.81%

Symfony (Only Components, No Twig, No Doctrine)

Lines of code: 118,636

Longest method: 136 lines of code

Average method complexity: 2.72

Maximum method complexity: 155

Percentage of methods that are non-static: 97.09%

Zend (Minimal Installation Option Selected)

Lines of code: 55,904

Longest method: 73 lines of code

Average method complexity: 2.76

Maximum method complexity: 53

Percentage of methods that are non-static: 93.55%

Cake

Lines of code: 62,860

Longest method: 56

Average method complexity: 3.30

Maximum method complexity: 75

Percentage of methods that are non-static: 89.87%

Slim

Lines of code: 4,127

Longest method: 26

Average method complexity: 2.40

Maximum method complexity: 13

Percentage of methods that are non-static: 96.58%

Eloquent (ORM)

Lines of code: 6,026

Longest method: 13

Average method complexity: 1.76

Maxium method complexity: 17

Percentage of methods that are non-static: 91.57%

Doctrine (ORM Only, No DBAL)