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

Commit 0d7d566

Browse files
authored
Merge pull request #28 from mmoreram/feature/refactored-and-added-exclude
Feature/refactored and added exclude
2 parents b8156d7 + 41147cd commit 0d7d566

34 files changed

+907
-1193
lines changed

.formatter.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use-sort:
66
sort-type: alph
77
sort-direction: asc
88

9-
strict: ~
9+
strict: true
1010
header: |
1111
/*
1212
* This file is part of the php-formatter package
1313
*
14-
* Copyright (c) 2014-2016 Marc Morera
14+
* Copyright (c) >=2014 Marc Morera
1515
*
1616
* For the full copyright and license information, please view the LICENSE
1717
* file that was distributed with this source code.

README.md

+41-55
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
1-
PHP Formatter
2-
=============
1+
# PHP Formatter
2+
33
[![Build Status](https://travis-ci.org/mmoreram/php-formatter.png?branch=master)](https://travis-ci.org/mmoreram/php-formatter)
4-
[![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)
5-
[![Latest Stable Version](https://poser.pugx.org/mmoreram/php-formatter/v/stable.png)](https://packagist.org/packages/mmoreram/php-formatter)
6-
[![Latest Unstable Version](https://poser.pugx.org/mmoreram/php-formatter/v/unstable.png)](https://packagist.org/packages/mmoreram/php-formatter)
74

85
This PHP formatter aims to provide you some bulk actions for you PHP projects to
96
ensure their consistency. None of them fixes PSR rules. If you want to fix PSR
10-
rules, please check [fabpot/php-cs-fixer](https://github.com/fabpot/PHP-CS-Fixer).
11-
12-
## Tags
13-
14-
* Use last unstable version ( alias of `dev-master` ) to stay in last commit
15-
* Use last stable version tag to stay in a stable release.
16-
* [![Latest Unstable Version](https://poser.pugx.org/mmoreram/php-formatter/v/unstable.png)](https://packagist.org/packages/mmoreram/php-formatter)
17-
[![Latest Stable Version](https://poser.pugx.org/mmoreram/php-formatter/v/stable.png)](https://packagist.org/packages/mmoreram/php-formatter)
7+
rules, please check [friendsofphp/php-cs-fixer](https://github.com/friendsofphp/PHP-CS-Fixer).
188

199
## Install
2010

@@ -51,14 +41,15 @@ $ cp build/php-formatter.phar /usr/local/bin/php-formatter
5141

5242
### Compile
5343

54-
Finally you can also compile your own version of the package. ( You need set `phar.readonly = Off` in your php.ini ).
44+
Finally you can also compile your own version of the package. ( You need set
45+
`phar.readonly = Off` in your php.ini ). For the compilation of this package you
46+
need the [box-project/box2](https://github.com/box-project/box2) library.
5547

5648
``` bash
5749
$ git clone [email protected]:mmoreram/php-formatter.git
5850
$ cd php-formatter
5951
$ composer update
60-
$ php bin/compile
61-
$ sudo chmod +x build/php-formatter.phar
52+
$ box build -v
6253
$ build/php-formatter.phar
6354
```
6455

@@ -136,8 +127,9 @@ Available commands:
136127
help Displays help for a command
137128
list Lists commands
138129
formatter
139-
formatter:header:fix Ensures that all PHP files has header defined in config file
140-
formatter:use:sort Sort Use statements
130+
formatter:header:fix Ensures that all PHP files has header defined in config file
131+
formatter:strict:fix Ensures that all PHP files have strict mode defined in config file. Only valid for >=PHP7.0
132+
formatter:use:sort Sort Use statements
141133
```
142134

143135
### Sort all Use Statements
@@ -148,21 +140,13 @@ process.
148140

149141
* command: `php-formatter formatter:use:sort`
150142
* argument: path
143+
* option: --exclude [***multiple***]
151144
* option: --group [***multiple***]
152145
* option: --group-type=***one***|***each***
153146
* option: --sort-type=***alph***|***length***
154147
* option: --sort-direction=***asc***|***desc***
155148
* option: --dry-run [***no value***]
156149

157-
#### Dry run
158-
159-
You can use this tool just to test the files will be modified, using option
160-
--dry-run
161-
162-
``` bash
163-
$ php-formatter formatter:use:sort src/ --dry-run
164-
```
165-
166150
#### Group
167151

168152
You can sort your Use statements using as many groups as you want (***--group***).
@@ -320,35 +304,9 @@ will check and fix that all PHP files have it properly.
320304

321305
* command: `php-formatter formatter:header:fix`
322306
* argument: path
307+
* option: --exclude [***multiple***]
323308
* option: --dry-run [***no value***]
324309

325-
#### Dry run
326-
327-
You can use this tool just to test the files will be modified, using the option
328-
--dry-run
329-
330-
``` bash
331-
$ php-formatter formatter:header:fix src/ --dry-run
332-
```
333-
334-
Your PHP Header definition must have this format.
335-
336-
``` yml
337-
header: |
338-
/*
339-
* This file is part of the php-formatter package
340-
*
341-
* Copyright (c) 2014 Marc Morera
342-
*
343-
* For the full copyright and license information, please view the LICENSE
344-
* file that was distributed with this source code.
345-
*
346-
* Feel free to edit as you please, and have fun.
347-
*
348-
* @author Marc Morera <[email protected]>
349-
*/
350-
```
351-
352310
### Fix all strict declarations
353311

354312
In your >=7.0 PHP applications you can use simple type declarations in your
@@ -359,6 +317,7 @@ exists and before the namespace declaration, you can use this command.
359317

360318
* command: `php-formatter formatter:strict:fix`
361319
* argument: path
320+
* option: --exclude [***multiple***]
362321
* option: --dry-run [***no value***]
363322

364323
You can have three values here. If you define a boolean, then each file found
@@ -373,4 +332,31 @@ removed.
373332

374333
``` yml
375334
strict: '~'
376-
```
335+
```
336+
337+
## Exclude folders/files
338+
339+
You can exclude folders and files by using the multi-option `--exclude` as many
340+
times as you need. This option works the same way the Symfony component
341+
[Finder](http://symfony.com/doc/current/components/finder.html) works, so to
342+
make sure you properly understand the way this option works, just check the
343+
documentation.
344+
345+
``` bash
346+
$ php-formatter formatter:header:fix src/ --exclude="vendor"
347+
```
348+
349+
In that case, maybe the most used way, you will exclude all vendors from your
350+
process.
351+
352+
## Dry run
353+
354+
You can use this tool just to test the files will be modified, using option
355+
--dry-run
356+
357+
``` bash
358+
$ php-formatter formatter:use:sort src/ --dry-run
359+
```
360+
361+
Any command from this library will never have any impact in your code as long as
362+
you have defined this option.

bin/compile

-31
This file was deleted.

bin/php-formatter

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @author Marc Morera <[email protected]>
1515
*/
1616

17-
require __DIR__ . '/../src/bootstrap.php';
17+
require __DIR__ . '/../vendor/autoload.php';
1818

1919
use Mmoreram\PHPFormatter\Console\Application;
2020

box.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"algorithm": "SHA1",
3+
"alias": "php-formatter.phar",
4+
"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]>",
5+
"chmod": "0755",
6+
"compactors": [
7+
"Herrera\\Box\\Compactor\\Json",
8+
"Herrera\\Box\\Compactor\\Php"
9+
],
10+
"directories": "src",
11+
"extract": true,
12+
"files": [
13+
"LICENSE",
14+
"vendor/autoload.php",
15+
"vendor/composer/installed.json",
16+
"vendor/composer/LICENSE"
17+
],
18+
"finder": [
19+
{
20+
"exclude": [
21+
"tests",
22+
"Tests"
23+
],
24+
"in": [
25+
"vendor/symfony",
26+
"vendor/composer",
27+
"vendor/paragonie"
28+
],
29+
"name": "*.php"
30+
}
31+
],
32+
"git-version": "package_version",
33+
"main": "bin/php-formatter",
34+
"output": "build/php-formatter.phar",
35+
"stub": true
36+
}

build/php-formatter.phar

100644100755
112 KB
Binary file not shown.

composer.json

+10-14
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@
1414
],
1515
"require": {
1616
"php": ">=7.0",
17-
"symfony/console": "^3.0",
18-
"symfony/process": "^3.0",
19-
"symfony/finder": "^3.0",
20-
"symfony/filesystem": "^3.0",
21-
"symfony/yaml": "^3.0",
22-
"symfony/event-dispatcher": "^3.0",
23-
"symfony/property-access": "^3.0"
17+
"symfony/console": "^3.2",
18+
"symfony/process": "^3.2",
19+
"symfony/finder": "^3.2",
20+
"symfony/filesystem": "^3.2",
21+
"symfony/yaml": "^3.2",
22+
"symfony/event-dispatcher": "^3.2",
23+
"symfony/property-access": "^3.2"
2424
},
2525
"require-dev": {
2626
"friendsofphp/php-cs-fixer": "^1.12.4",
@@ -35,16 +35,12 @@
3535
"autoload-dev": {
3636
"psr-4": {"Mmoreram\\PHPFormatter\\Tests\\": "tests/PHPFormatter"}
3737
},
38-
"extra": {
39-
"branch-alias": {
40-
"dev-master": "1.0-dev"
41-
}
42-
},
4338
"scripts": {
4439
"fix-code": [
4540
"vendor/bin/php-cs-fixer fix --config-file=.php_cs",
46-
"vendor/bin/php-formatter f:h:f .",
47-
"vendor/bin/php-formatter f:u:s ."
41+
"bin/php-formatter f:h:f . --exclude=vendor --verbose",
42+
"bin/php-formatter f:s:f . --exclude=vendor --verbose",
43+
"bin/php-formatter f:u:s . --exclude=vendor --verbose"
4844
],
4945
"test": "vendor/bin/phpunit"
5046
}

0 commit comments

Comments
 (0)