Git Product home page Git Product logo

php.tools's Introduction

php.tools

Build statuses

  • Master: Build Status

Throughput Graph

Requirements

  • PHP >= 5.6.0 to run the formatter. Note that the formatter can parse even a PHP file version 4 in case needed.

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
  --cakephp                         Apply CakePHP coding style
  --config=FILENAME                 configuration file. Default: .php.tools.ini
  --constructor=type                analyse classes for attributes and generate constructor - camel, snake, golang
  --enable_auto_align               disable auto align of ST_EQUAL and T_DOUBLE_ARROW
  --exclude=pass1,passN,...         disable specific passes
  --help-pass                       show specific information for one pass
  --ignore=PATTERN-1,PATTERN-N,...  ignore file names whose names contain any PATTERN-N
  --indent_with_space=SIZE          use spaces instead of tabs for indentation. Default 4
  --laravel                         Apply Laravel coding style (deprecated)
  --lint-before                     lint files before pretty printing (PHP must be declared in %PATH%/$PATH)
  --list                            list possible transformations
  --list-simple                     list possible transformations - greppable
  --no-backup                       no backup file (original.php~)
  --passes=pass1,passN,...          call specific compiler pass
  --profile=NAME                    use one of profiles present in configuration file
  --psr                             activate PSR1 and PSR2 styles
  --psr1                            activate PSR1 style
  --psr1-naming                     activate PSR1 style - Section 3 and 4.3 - Class and method names case.
  --psr2                            activate PSR2 style
  --selfupdate                      self-update fmt.phar from Github
  --setters_and_getters=type        analyse classes for attributes and generate setters and getters - camel, snake, golang
  --smart_linebreak_after_curly     convert multistatement blocks into multiline blocks
  --version                         version
  --visibility_order                fixes visibiliy order for method in classes - PSR-2 4.2
  --yoda                            yoda-style comparisons
  -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;
This can be disabled with the option "disable_auto_align"
<?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

PSR 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";
    }
}
Note the identation of 4 spaces.
<?php
class A {
function a(){
return 10;
}
}
<?php
class A
{
    public function a()
    {
        return 10;
    }
}
Note the braces position, and the visibility adjustment in the method a().
<?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

php.tools's People

Contributors

ccirello avatar cute avatar dericofilho avatar junstyle avatar phpfmt avatar shaked avatar tlshaheen avatar ucirello avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.