phpfmt/fmt

This package is abandoned and no longer maintained. No replacement package was suggested.

K&R and phpfmt coding standard

Maintainers

Details

github.com/phpfmt/fmt

Source

Issues

Installs: 1 379

Dependents: 0

Suggesters: 0

Security: 0

Stars: 630

Watchers: 34

Forks: 44

Type:application

dev-master 2016-06-01 02:11 UTC

This package is not auto-updated.

Last update: 2016-06-01 02:11:30 UTC


README

This project follows a Code of Conduct.

Report issues.

Build statuses

  • Master: Build Status

Requirements

  • PHP >= 7.0.0 to run the formatter. Note that the formatter can parse and format even a PHP file version 4 in case needed. HHVM is not supported.

Editor Plugins

Usage

$ php fmt.phar filename.php

$ php fmt.phar --help
Usage: fmt.phar [-hv] [-o=FILENAME] [--config=FILENAME] [--cache[=FILENAME]] [options] <target>
  --cache[=FILENAME]                cache file. Default: .php.tools.cache
  --config=FILENAME                 configuration file. Default: .phpfmt.ini
  --dry-run                         Runs the formatter without atually changing files;
                                    returns exit code 1 if changes would have been applied
  --ignore=PATTERN-1,PATTERN-N,...  ignore file names whose names contain any PATTERN-N
  --lint-before                     lint files before pretty printing (PHP must be declared in %PATH%/$PATH)
  --no-backup                       no backup file (original.php~)
  --profile=NAME                    use one of profiles present in configuration file
  --version                         version
  -h, --help                        this help message
  -o=-                              output the formatted code to standard output
  -o=file                           output the formatted code to "file"
  -v                                verbose

If <target> is "-", it reads from stdin

What does the Code Formatter do?

K&R configuration

Before After
<?php
for($i = 0; $i < 10; $i++)
{
if($i%2==0)
echo "Flipflop";
}
<?php
for ($i = 0; $i < 10; $i++) {
    if ($i%2 == 0) {
        echo "Flipflop";
    }
}
<?php
$a = 10;
$otherVar = 20;
$third = 30;
<?php
$a        = 10;
$otherVar = 20;
$third    = 30;
<?php
namespace NS\Something;
use \OtherNS\C;
use \OtherNS\B;
use \OtherNS\A;
use \OtherNS\D;

$a = new A();
$b = new C();
$d = new D();
<?php
namespace NS\Something;

use \OtherNS\A;
use \OtherNS\C;
use \OtherNS\D;

$a = new A();
$b = new C();
$d = new D();
note how it sorts the use clauses, and removes unused ones