Skip to content

Instantly share code, notes, and snippets.

@it-can
Forked from martinbean/pre-commit
Last active May 22, 2016 12:24
Show Gist options
  • Save it-can/f23bce73563a3b6ececc to your computer and use it in GitHub Desktop.
Save it-can/f23bce73563a3b6ececc to your computer and use it in GitHub Desktop.
Pre-commit hook to detect if any files contain dd()
#!/usr/bin/php
<?php
function contains($needle, $haystack)
{
return stripos($haystack, $needle) !== false;
}
$files = shell_exec('git diff-index --name-only --cached --diff-filter=ACMR HEAD');
$files = explode("\n", trim($files));
$exitCode = 0;
foreach ($files as $file)
{
if (empty($file) or contains('resources/views', $file) or contains('blade.php', $file) or ! contains('.php', $file))
{
continue;
}
$lines = file($file);
foreach ($lines as $line => $content) {
if (preg_match('/dd\(/', $content)) {
printf("\033[0;31mdd() found on line %d in %s\033[0m\n", $line + 1, $file);
$exitCode = 1;
}
}
}
exit($exitCode);
#!/usr/bin/php
<?php
function contains($needle, $haystack)
{
return stripos($haystack, $needle) !== false;
}
$files = shell_exec('git diff-index --name-only --cached --diff-filter=ACMR HEAD');
$files = explode("\n", trim($files));
$exitCode = 0;
foreach ($files as $file)
{
if (empty($file) or ! contains('.php', $file))
{
continue;
}
$lines = file($file);
foreach ($lines as $line => $content) {
if (preg_match('/fatal\(/', $content) and ! preg_match('/function fatal\(/', $content)) {
printf("\033[0;31mfatal() 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