for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace JoaoRobertoPB\PhpGitHookSniffer\Pipelines;
use JoaoRobertoPB\PhpGitHookSniffer\Contracts\PipelineInterface;
class CsFixerStage implements PipelineInterface
{
/**
* Runs php -l on PHP staged files.
*
* @return void
*/
public function __invoke($payload)
echo "[ ] ----- Fix Code Standards -----\n";
foreach ($payload as $file) {
$fileName = trim($file);
$ext = pathinfo($fileName, PATHINFO_EXTENSION);
$return = 0;
if ('php' != $ext) {
continue;
}
$csOutput = [];
exec(__DIR__.'/../../../../../vendor/bin/php-cs-fixer --using-cache=no fix '.escapeshellarg($fileName), $csOutput, $return);
exec("git add {$fileName}");
if ($return != 0) {
$return
foreach
19
echo implode("\n", $csOutput), "\n";
$csOutput
echo "[FAIL] ----- Fix Code Standards -----\n";
exit(1);
exit
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.
echo "[OK] ----- Fix Code Standards -----\n";
return $payload;