Skip to content
This repository was archived by the owner on Feb 21, 2022. It is now read-only.

Feature/refactored and added exclude #28

Merged
merged 3 commits into from
Dec 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .formatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use-sort:
sort-type: alph
sort-direction: asc

strict: ~
strict: true
header: |
/*
* This file is part of the php-formatter package
*
* Copyright (c) 2014-2016 Marc Morera
* Copyright (c) >=2014 Marc Morera
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
96 changes: 41 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
PHP Formatter
=============
# PHP Formatter

[![Build Status](https://travis-ci.org/mmoreram/php-formatter.png?branch=master)](https://travis-ci.org/mmoreram/php-formatter)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/mmoreram/php-formatter/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/mmoreram/php-formatter/?branch=master)
[![Latest Stable Version](https://poser.pugx.org/mmoreram/php-formatter/v/stable.png)](https://packagist.org/packages/mmoreram/php-formatter)
[![Latest Unstable Version](https://poser.pugx.org/mmoreram/php-formatter/v/unstable.png)](https://packagist.org/packages/mmoreram/php-formatter)

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 [fabpot/php-cs-fixer](https://github.com/fabpot/PHP-CS-Fixer).

## Tags

* Use last unstable version ( alias of `dev-master` ) to stay in last commit
* Use last stable version tag to stay in a stable release.
* [![Latest Unstable Version](https://poser.pugx.org/mmoreram/php-formatter/v/unstable.png)](https://packagist.org/packages/mmoreram/php-formatter)
[![Latest Stable Version](https://poser.pugx.org/mmoreram/php-formatter/v/stable.png)](https://packagist.org/packages/mmoreram/php-formatter)
rules, please check [friendsofphp/php-cs-fixer](https://github.com/friendsofphp/PHP-CS-Fixer).

## Install

Expand Down Expand Up @@ -51,14 +41,15 @@ $ 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 ).
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](https://github.com/box-project/box2) library.

``` bash
$ git clone [email protected]:mmoreram/php-formatter.git
$ cd php-formatter
$ composer update
$ php bin/compile
$ sudo chmod +x build/php-formatter.phar
$ box build -v
$ build/php-formatter.phar
```

Expand Down Expand Up @@ -136,8 +127,9 @@ 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:use:sort Sort Use statements
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
Expand All @@ -148,21 +140,13 @@ 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***]

#### Dry run

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

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

#### Group

You can sort your Use statements using as many groups as you want (***--group***).
Expand Down Expand Up @@ -320,35 +304,9 @@ 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***]

#### Dry run

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

``` bash
$ php-formatter formatter:header:fix src/ --dry-run
```

Your PHP Header definition must have this format.

``` yml
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]>
*/
```

### Fix all strict declarations

In your >=7.0 PHP applications you can use simple type declarations in your
Expand All @@ -359,6 +317,7 @@ 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
Expand All @@ -373,4 +332,31 @@ removed.

``` yml
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](http://symfony.com/doc/current/components/finder.html) works, so to
make sure you properly understand the way this option works, just check the
documentation.

``` bash
$ 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

``` bash
$ 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.
31 changes: 0 additions & 31 deletions bin/compile

This file was deleted.

2 changes: 1 addition & 1 deletion bin/php-formatter
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @author Marc Morera <[email protected]>
*/

require __DIR__ . '/../src/bootstrap.php';
require __DIR__ . '/../vendor/autoload.php';

use Mmoreram\PHPFormatter\Console\Application;

Expand Down
36 changes: 36 additions & 0 deletions box.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"algorithm": "SHA1",
"alias": "php-formatter.phar",
"banner": "This file is part of the php-formatter package\n\nCopyright (c) >=2014 Marc Morera\n\nFor the full copyright and license information, please view the LICENSE\nfile that was distributed with this source code.\n\nFeel free to edit as you please, and have fun.\n\n@author Marc Morera <[email protected]>",
"chmod": "0755",
"compactors": [
"Herrera\\Box\\Compactor\\Json",
"Herrera\\Box\\Compactor\\Php"
],
"directories": "src",
"extract": true,
"files": [
"LICENSE",
"vendor/autoload.php",
"vendor/composer/installed.json",
"vendor/composer/LICENSE"
],
"finder": [
{
"exclude": [
"tests",
"Tests"
],
"in": [
"vendor/symfony",
"vendor/composer",
"vendor/paragonie"
],
"name": "*.php"
}
],
"git-version": "package_version",
"main": "bin/php-formatter",
"output": "build/php-formatter.phar",
"stub": true
}
Binary file modified build/php-formatter.phar
100644 → 100755
Binary file not shown.
24 changes: 10 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
],
"require": {
"php": ">=7.0",
"symfony/console": "^3.0",
"symfony/process": "^3.0",
"symfony/finder": "^3.0",
"symfony/filesystem": "^3.0",
"symfony/yaml": "^3.0",
"symfony/event-dispatcher": "^3.0",
"symfony/property-access": "^3.0"
"symfony/console": "^3.2",
"symfony/process": "^3.2",
"symfony/finder": "^3.2",
"symfony/filesystem": "^3.2",
"symfony/yaml": "^3.2",
"symfony/event-dispatcher": "^3.2",
"symfony/property-access": "^3.2"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^1.12.4",
Expand All @@ -35,16 +35,12 @@
"autoload-dev": {
"psr-4": {"Mmoreram\\PHPFormatter\\Tests\\": "tests/PHPFormatter"}
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"scripts": {
"fix-code": [
"vendor/bin/php-cs-fixer fix --config-file=.php_cs",
"vendor/bin/php-formatter f:h:f .",
"vendor/bin/php-formatter f:u:s ."
"bin/php-formatter f:h:f . --exclude=vendor --verbose",
"bin/php-formatter f:s:f . --exclude=vendor --verbose",
"bin/php-formatter f:u:s . --exclude=vendor --verbose"
],
"test": "vendor/bin/phpunit"
}
Expand Down
Loading