Developing software in the Real World

Slim 4 Cyclomatic Complexity

There’s not much wrong with Slim 3; lots of people are using it very successfully producing APIs and websites of all kinds. For Slim 4 the main goals have been to support PSR-15, make it easier to use your own PSR-7 implementation, improve error handling and remove assumptions that look magical if you don’t know they are there. The latter one is the most important to me, personally!

Secondarily, Pierre has concentrated on making Slim’s code more flexible and hopefully making it easier to swap out our internal components with your own if you need to. On a whim, I ran phploc on the current Slim 3 and Slim 4-dev codebases to see what differences were. The full results are in this gist.

Note that Slim 4 doesn’t have the PSR-7 implementation or the container wrapper, so it’s maybe not possible to directly compare some of the numbers, but the cyclomatic complexity numbers are interesting and a direct outcome of Pierre’s work:

                                    Slim 3    Slim 4-dev
Cyclomatic Complexity                                   
  Average Complexity per LLOC         0.30          0.18
  Average Complexity per Class       10.40          4.76
    Minimum Class Complexity          1.00          1.00
    Maximum Class Complexity         67.00         25.00
  Average Complexity per Method       2.44          2.05
    Minimum Method Complexity         1.00          1.00
    Maximum Method Complexity        15.00         15.00

Cyclomatic complexity is a measure of the complexity of a codebase. It’s really hard to ensure that a method with a high cyclomatic complexity works as intended and I’m delighted to see these numbers go down! Hopefully this means that Slim 4’s internals are easier to understand and it will be easier to contribute to.

We need to find, assess and simplify the method that has that 15.00 though!

Thoughts? Leave a reply

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