PHP code example of badoo / phpcf
1. Go to this page and download the library: Download badoo/phpcf library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
badoo / phpcf example snippets
$ cat minifier.php
$tokens=token_get_all(file_get_contents($argv[1]));$contents='';foreach($tokens as $tok){if($tok[0]===T_WHITESPACE||$tok[0]===T_COMMENT)continue;if($tok[0]===T_AS||$tok[0]===T_ELSE)$contents.=' '.$tok[1].' '; else $contents.=is_array($tok)?$tok[1]:$tok;}echo$contents."\n";
$ phpcf apply minifier.php
minifier.php formatted successfully
$ cat minifier.php
$tokens = token_get_all(file_get_contents($argv[1]));
$contents = '';
foreach ($tokens as $tok) {
if ($tok[0] === T_WHITESPACE || $tok[0] === T_COMMENT) continue;
if ($tok[0] === T_AS || $tok[0] === T_ELSE) $contents .= ' ' . $tok[1] . ' ';
else $contents .= is_array($tok) ? $tok[1] : $tok;
}
echo $contents . "\n";
$ phpcf check minifier.php; echo $?
minifier.php does not need formatting
0
$ cat zebra.php
echo "White "."strip".PHP_EOL;
echo "Black "."strip".PHP_EOL; // not formatted
echo "Arse".PHP_EOL;
$ phpcf apply zebra.php:1-2,4
zebra.php formatted successfully
$ cat zebra.php
echo "White " . "strip" . PHP_EOL;
echo "Black "."strip".PHP_EOL; // not formatted
echo "Arse" . PHP_EOL;
$ phpcf check zebra.php
zebra.php issues:
Expected one space before binary operators (= < > * . etc) on line 3 column 14
Expected one space after binary operators (= < > * . etc) on line 3 column 15
...
$ echo $?
1