3

Today I am faced with a spaghetti of some new unknown code for a webservice, and I need to make sense of it. The code is using CodeIgniter with a HMVC extension which helps, but the problem is that it contains many unused/old/etc... files/folders. It also does not help that I recently converted to using PHP, so I am still learning my way around best practices.

  • Is there a way to set the debugger up in a way that it breaks at the beginning of every single PHP file? (I have Xdebug set up ready to rock)
  • What is the most effective way to analyse code for unused files? ( I saw a few projects for this, but unsure where to start)

Thanks!

halfer
  • 19,824
  • 17
  • 99
  • 186
Crocodile
  • 5,724
  • 11
  • 41
  • 67
  • 5
    Do some searching on "PHP execution coverage", XDebug supports this. Basically you need to run some code (ideally some tests) and then detect what does not get run. – halfer Mar 10 '15 at 17:41
  • You can use hosted tools like Scrutinizer for this ([here's a recent project of mine](https://github.com/halfer/awooga-app) - see the 82% coverage). However if your work is not open-source, this will cost. You can likely do the same for free, but perhaps with a bit more effort. Also, see what Blackfire.io can do for you, there's some buzz around that at the moment. – halfer Mar 10 '15 at 17:48
  • Thanks halfer! I am looking into both options now – Crocodile Mar 10 '15 at 17:54
  • 2
    Also have a look at profiling in production with XHProf: http://stackoverflow.com/questions/4370795/profiling-code-on-production – Tom Mar 10 '15 at 18:16
  • @halfer It looks like Xdebug's code coverage feature might just fits the bill! All I had to do is add 'xdebug_start_code_coverage();' to the beginning of my source code, then add 'xdebug_get_code_coverage();' to my watches to see which files/lines have been executed. If you care to add a reply I will accept it. – Crocodile Mar 11 '15 at 15:46

1 Answers1

2

As per the discussion in the comments, I'd wondered if the execution coverage tools in XDebug would help here. This is a low-level code monitor that watches what lines of PHP code have been executed when you start a program. As you'd expect, this adds a certain level of overhead, so it is generally not added to live environments.

Hosted build systems like Travis and Scrutinizer do code coverage reporting, though they probably rely on tools like PHPUnit and XDebug to actually make them work.

halfer
  • 19,824
  • 17
  • 99
  • 186