Skip to content

Instantly share code, notes, and snippets.

@elbakly
Forked from martinbean/pre-commit
Created January 31, 2016 16:58
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 elbakly/701570963b21f7398103 to your computer and use it in GitHub Desktop.
Save elbakly/701570963b21f7398103 to your computer and use it in GitHub Desktop.
Pre-commit hook to detect if any files contain dd()
#!/usr/bin/php
<?php
$files = shell_exec('git diff-index --name-only --cached --diff-filter=ACMR HEAD | grep "\.php$"');
$files = explode("\n", trim($files));
$exitCode = 0;
foreach ($files as $file) {
if (empty($file)) {
continue;
}
$lines = file($file);
foreach ($lines as $line => $content) {
if (preg_match('/\sdd\(/', $content)) {
printf("\033[0;31mdd() found on line %d in %s\033[0m\n", $line + 1, $file);
$exitCode = 1;
}
}
}
exit($exitCode);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment