Example #1
0
     $fmt->enablePass('NormalizeLnAndLtrimLines');
     $fmt->enablePass('MergeParenCloseWithCurlyOpen');
     $fmt->enablePass('MergeCurlyCloseAndDoWhile');
     $fmt->enablePass('MergeDoubleArrowAndArray');
     $fmt->enablePass('ResizeSpaces');
     $fmt->enablePass('ReindentColonBlocks');
     $fmt->enablePass('AlignEquals');
     $fmt->enablePass('AlignDoubleArrow');
     $fmt->enablePass('ReindentAndAlignObjOps');
     $fmt->enablePass('Reindent');
     $fmt->enablePass('EliminateDuplicatedEmptyLines');
     $fmt->enablePass('LeftAlignComment');
     $fmt->enablePass('RTrim');
     $fmt->enablePass('ReindentSwitchBlocks');
 }
 $got = $fmt->formatCode($content);
 $expected = '';
 if (file_exists($caseOut)) {
     $expected = file_get_contents($caseOut);
 }
 if ($got != $expected) {
     $brokenTests[$caseOut] = $got;
     if (isset($opt['stop'])) {
         $bailOut = true;
         break;
     }
     echo '!';
 } else {
     echo '.';
 }
 stopAtStep();
Example #2
0
 }
 $debug = false;
 $fmt = new CodeFormatter($debug);
 if (isset($opts['from']) && isset($opts['to'])) {
     $argv = array_values(array_filter($argv, function ($v) {
         $param_from = '--from';
         $param_to = '--to';
         return substr($v, 0, strlen($param_from)) !== $param_from && substr($v, 0, strlen($param_to)) !== $param_to;
     }));
     $fmt->addPass(new RefactorPass($opts['from'], $opts['to']));
 }
 if (isset($opts['o'])) {
     unset($argv[1]);
     unset($argv[2]);
     $argv = array_values($argv);
     file_put_contents($opts['o'], $fmt->formatCode(file_get_contents($argv[1])));
 } elseif (isset($argv[1]) && is_file($argv[1])) {
     echo $fmt->formatCode(file_get_contents($argv[1]));
 } elseif (isset($argv[1]) && is_dir($argv[1])) {
     $dir = new RecursiveDirectoryIterator($argv[1]);
     $it = new RecursiveIteratorIterator($dir);
     $files = new RegexIterator($it, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH);
     foreach ($files as $file) {
         $file = $file[0];
         echo $file;
         $orig_code = file_get_contents($file);
         $new_code = $fmt->formatCode($orig_code);
         if ($orig_code != $new_code) {
             file_put_contents($file . '-tmp', $new_code);
             rename($file, $file . '~');
             rename($file . '-tmp', $file);
Example #3
0
		case 2:
			noop();
		break;
	}
}

if($a)
	noop3();
';
$fmt = new CodeFormatter();
$fmt->addPass(new TwoCommandsInSameLine());
$fmt->addPass(new RemoveIncludeParentheses());
$fmt->addPass(new NormalizeIsNotEquals());
$fmt->addPass(new OrderUseClauses());
$fmt->addPass(new AddMissingCurlyBraces());
$fmt->addPass(new ExtraCommaInArray());
$fmt->addPass(new NormalizeLnAndLtrimLines());
$fmt->addPass(new MergeParenCloseWithCurlyOpen());
$fmt->addPass(new MergeCurlyCloseAndDoWhile());
$fmt->addPass(new MergeDoubleArrowAndArray());
$fmt->addPass(new ResizeSpaces());
$fmt->addPass(new Tree());
$fmt->addPass(new ReindentColonBlocks());
$fmt->addPass(new ReindentLoopColonBlocks());
$fmt->addPass(new ReindentIfColonBlocks());
$fmt->addPass(new ReindentObjOps());
$fmt->addPass(new EliminateDuplicatedEmptyLines());
$fmt->addPass(new LeftAlignComment());
$fmt->addPass(new RTrim());
echo $fmt->formatCode($code);
Example #4
0
 }
 $debug = false;
 $fmt = new CodeFormatter($debug);
 if (isset($opts['from']) && isset($opts['to'])) {
     $argv = array_values(array_filter($argv, function ($v) {
         $param_from = '--from';
         $param_to = '--to';
         return substr($v, 0, strlen($param_from)) !== $param_from && substr($v, 0, strlen($param_to)) !== $param_to;
     }));
     $fmt->addPass(new RefactorPass($opts['from'], $opts['to']));
 }
 if (isset($opts['o'])) {
     unset($argv[1]);
     unset($argv[2]);
     $argv = array_values($argv);
     file_put_contents($opts['o'], $fmt->formatCode(file_get_contents($argv[1])));
 } elseif (isset($argv[1]) && is_file($argv[1])) {
     echo $fmt->formatCode(file_get_contents($argv[1]));
 } elseif (isset($argv[1]) && is_dir($argv[1])) {
     $dir = new RecursiveDirectoryIterator($argv[1]);
     $it = new RecursiveIteratorIterator($dir);
     $files = new RegexIterator($it, '/^.+\\.php$/i', RecursiveRegexIterator::GET_MATCH);
     foreach ($files as $file) {
         $file = $file[0];
         echo $file;
         file_put_contents($file . '-tmp', $fmt->formatCode(file_get_contents($file)));
         rename($file, $file . '~');
         rename($file . '-tmp', $file);
         echo PHP_EOL;
     }
 } else {
Example #5
0
    echo PHP_EOL, 'It reads input from stdin, and outputs content on stdout.', PHP_EOL;
    echo PHP_EOL, 'It will derive "Pass" into a file in local directory appended with ".php" ("Pass.php"). Make sure it inherits from SandboxedPass.', PHP_EOL;
}
$getoptLongOptions = ['help', 'pass::'];
if ($inPhar) {
    $getoptLongOptions[] = 'version';
}
$opts = getopt('h', $getoptLongOptions);
if (isset($opts['version'])) {
    if ($inPhar) {
        echo $argv[0], ' ', VERSION, PHP_EOL;
    }
    exit(0);
}
if (!isset($opts['pass'])) {
    fwrite(STDERR, 'pass is not declared. cannot run.');
    exit(1);
}
$pass = sprintf('%s.php', basename($opts['pass']));
if (!file_get_contents($pass)) {
    fwrite(STDERR, sprintf('pass file "%s" is not found. cannot run.', $pass));
    exit(1);
}
include $pass;
if (isset($opts['h']) || isset($opts['help'])) {
    showHelp($argv, $enableCache, $inPhar);
    exit(0);
}
$fmt = new CodeFormatter(basename($opts['pass']));
echo $fmt->formatCode(file_get_contents('php://stdin'));
exit(0);