Skip to content

Instantly share code, notes, and snippets.

@pascaldevink
Created April 22, 2015 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pascaldevink/b86fd10302fc86d0e899 to your computer and use it in GitHub Desktop.
Save pascaldevink/b86fd10302fc86d0e899 to your computer and use it in GitHub Desktop.
Find the cyclomatic complexity of the most changed PHP files
git log --pretty=format: --name-only | sort | uniq -c | grep .php | sort -rg | head -100 | awk -F ' ' '{print $2}' | xargs -I input phpmd input text codesize | grep class | grep complexity | awk -F " " '{print $1 " " $10}'
@pascaldevink
Copy link
Author

Will print the cyclomatic complexity of the 100 most changed files, like so:

/application/modules/Default/Controller/XXX.php:30 68
/application/modules/Default/Controller/YYY.php:26 72
/application/modules/Default/Controller/Foo.php:26 174

The first part of the script is useful if you want to know exactly how many changes a file has had:
git log --pretty=format: --name-only | sort | uniq -c | grep .php | sort -rg | head -100
This will output something like:
250 /application/modules/Default/Controller/XXX.php
184 /application/modules/Default/Controller/YYY.php
102 /application/modules/Default/Controller/Foo.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment