Is there any tool out there which could tell the useless files in the code base?
We have a big code base (PHP, HTML, CSS, JS files) and I want to be able to remove the not needed files. Any help would be appreciated.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I’m guessing deleting files and running your phpunit tests is a none starter.
If your files are not already in a version-control system – add them. Having the files in a version control system (such as svn or git) is crucial to allow you to recover from deleting any files that you thought were not being used but you later find out were.
Then, you can delete anything you think may not be being used, and if it doesn’t affect the running of your application you can conclude that the files aren’t used. If adverse effects show up – you can restore them from your repository with ease.
The above is most appropriate (probably) for frontend files (css, js, images). Any files you delete that are requested will show up in your webserver error log giving you a quick reference for files that nolonger exist that you need to restore.
For your php files, that’s quite a bit more tricky, How did you arrive at a position where you have php files which you aren’t using? Anyway you could for example:
and you would then have a profile which includes all files you loaded. Scanning the generated profile for each php file in your codebase will give you some indication of which files you didn’t use.
If you are only looking for unused files, don’t be tempted to use code coverage analysis – it is very intensive and not the level of detail you’re asking for.
A slightly less risky way would be to log whenever a file is loaded. e.g. put this at line one of each file:
and simply leave your application to be used for a while (days, weeks). Thereafter just scan that log, for any file that is named – remove the above line of code. For any that are not – delete (preferably after looking for the filename in your whole sourcecode and confirming it’s nowhere).
OR: you could use a shutdown function which dumps the response of
get_included_files()to a log file. This would allow you to achieve the same without editing all php files in your source tree.Caveat: Be careful deleting your php files. Whereas a missing css/js/image will probably mean your application still works, a missing php file of course will have rather more impact :).