All Projects → mmoreram → Php Formatter

mmoreram / Php Formatter

Licence: mit
PHP Formatter is a PHP developer friendly set of tools

Projects that are alternatives of or similar to Php Formatter

Java
All Algorithms implemented in Java
Stars: ✭ 42,893 (+26214.72%)
Mutual labels:  sort
Java Ds Algorithms
Data Structures and Algorithms in Java
Stars: ✭ 125 (-23.31%)
Mutual labels:  sort
Laravel Api Handler
Package providing helper functions for a Laravel REST-API
Stars: ✭ 150 (-7.98%)
Mutual labels:  sort
Faltu
Search sort, filter, limit an array of objects in Mongo-style.
Stars: ✭ 112 (-31.29%)
Mutual labels:  sort
Deep sort pytorch
MOT using deepsort and yolov3 with pytorch
Stars: ✭ 1,948 (+1095.09%)
Mutual labels:  sort
Store
A better way to use localStorage and sessionStorage
Stars: ✭ 1,646 (+909.82%)
Mutual labels:  namespace
Ar Position
ActiveRecord behavior, which provides ability for custom records order setup
Stars: ✭ 107 (-34.36%)
Mutual labels:  sort
C Plus Plus
Collection of various algorithms in mathematics, machine learning, computer science and physics implemented in C++ for educational purposes.
Stars: ✭ 17,151 (+10422.09%)
Mutual labels:  sort
Ng2 Smart Table
Angular Smart Data Table component
Stars: ✭ 1,590 (+875.46%)
Mutual labels:  sort
Rummage phoenix
Full Phoenix Support for Rummage. It can be used for searching, sorting and paginating collections in phoenix.
Stars: ✭ 144 (-11.66%)
Mutual labels:  sort
Jortsort
the official website for jortSorting
Stars: ✭ 112 (-31.29%)
Mutual labels:  sort
Channeltagview
一个新闻频道管理view
Stars: ✭ 115 (-29.45%)
Mutual labels:  sort
Rails sortable
Easy drag & drop sorting with persisting the arranged order for rails
Stars: ✭ 127 (-22.09%)
Mutual labels:  sort
Rdf.sh
A multi-tool shell script for doing Semantic Web jobs on the command line.
Stars: ✭ 109 (-33.13%)
Mutual labels:  namespace
Android Video Listing Mvp
Android video listing with swipe view tabs based on mvp design pattern with complete functionalities like search and sort
Stars: ✭ 151 (-7.36%)
Mutual labels:  sort
Gods
GoDS (Go Data Structures). Containers (Sets, Lists, Stacks, Maps, Trees), Sets (HashSet, TreeSet, LinkedHashSet), Lists (ArrayList, SinglyLinkedList, DoublyLinkedList), Stacks (LinkedListStack, ArrayStack), Maps (HashMap, TreeMap, HashBidiMap, TreeBidiMap, LinkedHashMap), Trees (RedBlackTree, AVLTree, BTree, BinaryHeap), Comparators, Iterators, …
Stars: ✭ 10,883 (+6576.69%)
Mutual labels:  sort
List.js
The perfect library for adding search, sort, filters and flexibility to tables, lists and various HTML elements. Built to be invisible and work on existing HTML.
Stars: ✭ 10,650 (+6433.74%)
Mutual labels:  sort
Algorithm
The repository algorithms implemented on the Go
Stars: ✭ 163 (+0%)
Mutual labels:  sort
Ordinare
Ordinare sorts gems in your Gemfile alphabetically
Stars: ✭ 153 (-6.13%)
Mutual labels:  sort
Human Falling Detect Tracks
AlphaPose + ST-GCN + SORT.
Stars: ✭ 135 (-17.18%)
Mutual labels:  sort

PHP Formatter

Build Status

This PHP formatter aims to provide you some bulk actions for you PHP projects to ensure their consistency. None of them fixes PSR rules. If you want to fix PSR rules, please check friendsofphp/php-cs-fixer.

Install

Install PHP Formatter in this way:

$ composer global require mmoreram/php-formatter=dev-master

If it is the first time you globally install a dependency then make sure you include ~/.composer/vendor/bin in $PATH as shown here.

Always keep your PHP Formatter installation up to date:

$ composer global update mmoreram/php-formatter

.phar file

You can also use already last built .phar.

$ git clone [email protected]:mmoreram/php-formatter.git
$ cd php-formatter
$ php build/php-formatter.phar

You can copy the .phar file as a global script

$ cp build/php-formatter.phar /usr/local/bin/php-formatter

Compile

Finally you can also compile your own version of the package. ( You need set phar.readonly = Off in your php.ini ). For the compilation of this package you need the box-project/box2 library.

$ git clone [email protected]:mmoreram/php-formatter.git
$ cd php-formatter
$ composer update --no-dev
$ box build -v
$ build/php-formatter.phar

You can copy the .phar file as a global script

$ cp build/php-formatter.phar /usr/local/bin/php-formatter

Config

You can place a file named .formatter.yml in the root of your project. In every command execution, this will be the priority of the definitions.

If an option is set in the command, this will be used. Otherwise, if is defined in a found config file, this will be used. Otherwise, default value will be used.

This is the config reference

use-sort:
    group:
        - _main
        - Mmoreram
    group-type: each
    sort-type: alph
    sort-direction: asc

strict: ~
header: |
    /*
     * This file is part of the php-formatter package
     *
     * Copyright (c) 2014 Marc Morera
     *
     * For the full copyright and license information, please view the LICENSE
     * file that was distributed with this source code.
     *
     * Feel free to edit as you please, and have fun.
     *
     * @author Marc Morera <[email protected]>
     */

you can also define where to search the .formatter.yml file using the --config|-c option

$ php-formatter formatter:use:sort src/ --config="src/"

Commands

PHP Formatter is a set of commands useful for your PHP projects. They do not consider any kind of Common Coding Standard, like PSR-0 or PSR-1, is more like a useful way of working for developers and reviewers.

Console Tool

Usage:
  [options] command [arguments]

Options:
  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v|vv|vvv Increase the verbosity of messages
  --version        -V Display this application version.
  --ansi              Force ANSI output.
  --no-ansi           Disable ANSI output.
  --no-interaction -n Do not ask any interactive question.

Available commands:
  help                   Displays help for a command
  list                   Lists commands
formatter
  formatter:header:fix  Ensures that all PHP files has header defined in config file
  formatter:strict:fix  Ensures that all PHP files have strict mode defined in config file. Only valid for >=PHP7.0
  formatter:use:sort    Sort Use statements

Sort all Use Statements

You can sort your Use Statements in different ways. For this command you must provide as an argument the path where to look for the PHP files you want to process.

  • command: php-formatter formatter:use:sort
  • argument: path
  • option: --exclude [multiple]
  • option: --group [multiple]
  • option: --group-type=one|each
  • option: --sort-type=alph|length
  • option: --sort-direction=asc|desc
  • option: --dry-run [no value]

Group

You can sort your Use statements using as many groups as you want (***--group***). It means that you can group lines with same root (***Symfony\***) in a specific order.

Common group is named _main and if is not specified, is placed in the beginning. You can define where to place this group with the --group option

$ php-formatter formatter:use:sort src/ --group="Mmoreram" --group="_main" --group="Symfony"

This command will sort the code like this

use Mmoreram\MyClass;
use Mmoreram\MySecondClass;

use OneBundle\OneClass;
use AnotherBundle\AnotherClass;

use Symfony\OneClass;
use Symfony\AnotherClass;

As you can see, a blank line is placed between groups. If any group is defined, one big group is created with all namespaces.

When using a .formatter.yml you can also specify subgroups by entering an array

use-sort:
    group:
        - [Symfony\Component\HttpKernel, Symfony]
        - _main

This will create a Symfony group placing all Symfony\Component\HttpKernel classes on top.

Finally, the --group-type defines if you want one use literal in every namespace line

$ php-formatter formatter:use:sort src/ --group="Mmoreram" --group-type="each"

This command will sort the code like this

use AnotherBundle\AnotherClass;
use OneBundle\OneClass;
use Symfony\AnotherClass;
use Symfony\OneClass;

use Mmoreram\MyClass;
use Mmoreram\MySecondClass;

or if you want only one use for all groups.

$ php-formatter formatter:use:sort src/ --group="Mmoreram" --group-type="one"

This command will sort the code like this

use AnotherBundle\AnotherClass,
    OneBundle\OneClass,
    Symfony\AnotherClass,
    Symfony\OneClass;

use Mmoreram\MyClass,
    Mmoreram\MySecondClass;

Sort

There are two options of sorting. You can sort your namespaces alphabetically (default value)

$ php-formatter formatter:use:sort src/ --sort-type="alph"

This command will sort the code like this

use AnotherBundle\AnotherClass;
use Mmoreram\MyClass;
use Mmoreram\MySecondClass;
use OneBundle\OneClass;
use Symfony\AnotherClass;
use Symfony\OneClass;

or by length (two namespaces with same length will be sorted alphabetically)

$ php-formatter formatter:use:sort src/ --sort-type="length"

This command will sort the code like this

use AnotherBundle\AnotherClass;
use Mmoreram\MySecondClass;
use Symfony\AnotherClass;
use OneBundle\OneClass;
use Mmoreram\MyClass;
use Symfony\OneClass;

You can also define the direction of the sorting. This can be ascending (default value)

$ php-formatter formatter:use:sort src/ --sort-direction="asc"

This command will sort the code like this

use AnotherBundle\AnotherClass;
use Mmoreram\MyClass;
use Mmoreram\MySecondClass;
use OneBundle\OneClass;
use Symfony\AnotherClass;
use Symfony\OneClass;

or descending

$ php-formatter formatter:use:sort src/ --sort-direction="desc"

This command will sort the code like this

use Symfony\OneClass;
use Symfony\AnotherClass;
use OneBundle\OneClass;
use Mmoreram\MySecondClass;
use Mmoreram\MyClass;
use AnotherBundle\AnotherClass;

Fix all PHP headers

You can define your PHP header in your .formatter.yml file and this command will check and fix that all PHP files have it properly.

  • command: php-formatter formatter:header:fix
  • argument: path
  • option: --exclude [multiple]
  • option: --dry-run [no value]

Fix all strict declarations

In your >=7.0 PHP applications you can use simple type declarations in your methods. You can define your application as relaxed as you want by declaring the strict_mode variable in your files. Each php file must be configured itself, so in order to make sure all your files have the definition after the header if exists and before the namespace declaration, you can use this command.

  • command: php-formatter formatter:strict:fix
  • argument: path
  • option: --exclude [multiple]
  • option: --dry-run [no value]

You can have three values here. If you define a boolean, then each file found will have the declaration with the boolean given.

strict: true

Otherwise, if you define a '~' value then your declaration lines will be removed.

strict: '~'

Exclude folders/files

You can exclude folders and files by using the multi-option --exclude as many times as you need. This option works the same way the Symfony component Finder works, so to make sure you properly understand the way this option works, just check the documentation.

$ php-formatter formatter:header:fix src/ --exclude="vendor"

In that case, maybe the most used way, you will exclude all vendors from your process.

Dry run

You can use this tool just to test the files will be modified, using option --dry-run

$ php-formatter formatter:use:sort src/ --dry-run

Any command from this library will never have any impact in your code as long as you have defined this option.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].