@@ -5,6 +5,17 @@ PHP Formatter
5
5
[ ![ Latest Stable Version] ( https://poser.pugx.org/mmoreram/php-formatter/v/stable.png )] ( https://packagist.org/packages/mmoreram/php-formatter )
6
6
[ ![ Latest Unstable Version] ( https://poser.pugx.org/mmoreram/php-formatter/v/unstable.png )] ( https://packagist.org/packages/mmoreram/php-formatter )
7
7
8
+ This PHP formatter aims to provide you some bulk actions for you PHP projects to
9
+ ensure their consistency. Any 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 )
18
+
8
19
## Install
9
20
10
21
Install PHP Formatter in this way:
@@ -76,13 +87,27 @@ use-sort:
76
87
group-type : each
77
88
sort-type : alph
78
89
sort-direction : asc
90
+
91
+ header : |
92
+ /**
93
+ * This file is part of the php-formatter package
94
+ *
95
+ * Copyright (c) 2014 Marc Morera
96
+ *
97
+ * For the full copyright and license information, please view the LICENSE
98
+ * file that was distributed with this source code.
99
+ *
100
+ * Feel free to edit as you please, and have fun.
101
+ *
102
+ * @author Marc Morera <[email protected] >
103
+ */
79
104
` ` `
80
105
81
106
you can also define where to search the ` .formatter.yml` file using the
82
107
` --config|-c` option
83
108
84
109
` ` ` bash
85
- $ php-formatter use:sort src/ --config="src/"
110
+ $ php-formatter formatter: use:sort src/ --config="src/"
86
111
` ` `
87
112
88
113
# # Commands
@@ -107,10 +132,11 @@ Options:
107
132
--no-interaction -n Do not ask any interactive question.
108
133
109
134
Available commands:
110
- help Displays help for a command
111
- list Lists commands
112
- use
113
- use:sort Sort Use statements
135
+ help Displays help for a command
136
+ list Lists commands
137
+ formatter
138
+ formatter:header:fix Ensures that all PHP files has header defined in config file
139
+ formatter:use:sort Sort Use statements
114
140
` ` `
115
141
116
142
# ## Sort all Use Statements
@@ -119,7 +145,7 @@ You can sort your Use Statements in a very different ways. For this command you
119
145
must provide as an argument the path where to look for the PHP files you want to
120
146
process.
121
147
122
- * command: `php-formatter use:sort`
148
+ * command: `php-formatter formatter: use:sort`
123
149
* argument: path
124
150
* option: --group [***multiple***]
125
151
* option: --group-type=***one***|***each***
@@ -133,7 +159,7 @@ You can use this tool just to test the files will be modified, using option
133
159
--dry-run
134
160
135
161
` ` ` bash
136
- $ php-formatter use:sort src/ --dry-run
162
+ $ php-formatter formatter: use:sort src/ --dry-run
137
163
` ` `
138
164
139
165
# ### Group
@@ -146,7 +172,7 @@ Common group is named `_main` and if is not specified, is placed in the
146
172
begining. You can define where to place this group with `--group` option
147
173
148
174
` ` ` bash
149
- $ php-formatter use:sort src/ --group="Mmoreram" --group="_main" --group="Symfony"
175
+ $ php-formatter formatter: use:sort src/ --group="Mmoreram" --group="_main" --group="Symfony"
150
176
` ` `
151
177
152
178
This command will sort the code like this
@@ -169,7 +195,7 @@ Finally, the `--group-type` defines if you want one `use` literal in every
169
195
namespace line
170
196
171
197
` ` ` bash
172
- $ php-formatter use:sort src/ --group="Mmoreram" --group-type="each"
198
+ $ php-formatter formatter: use:sort src/ --group="Mmoreram" --group-type="each"
173
199
` ` `
174
200
175
201
This command will sort the code like this
@@ -187,7 +213,7 @@ use Mmoreram\MySecondClass;
187
213
or if you want only one use for all group.
188
214
189
215
` ` ` bash
190
- $ php-formatter use:sort src/ --group="Mmoreram" --group-type="one"
216
+ $ php-formatter formatter: use:sort src/ --group="Mmoreram" --group-type="one"
191
217
` ` `
192
218
193
219
This command will sort the code like this
@@ -208,7 +234,7 @@ There are two options of sorting. You can sort your namespaces alphabetically
208
234
***(default value)***
209
235
210
236
` ` ` bash
211
- $ php-formatter use:sort src/ --sort-type="alph"
237
+ $ php-formatter formatter: use:sort src/ --sort-type="alph"
212
238
` ` `
213
239
214
240
This command will sort the code like this
@@ -225,7 +251,7 @@ use Symfony\OneClass;
225
251
or by length (two namespaces with same length will be sorted alphabetically)
226
252
227
253
` ` ` bash
228
- $ php-formatter use:sort src/ --sort-type="length"
254
+ $ php-formatter formatter: use:sort src/ --sort-type="length"
229
255
` ` `
230
256
231
257
This command will sort the code like this
@@ -243,7 +269,7 @@ You can also define the direction of the sorting. This can be ascending
243
269
***(default value)***
244
270
245
271
` ` ` bash
246
- $ php-formatter use:sort src/ --sort-direction="asc"
272
+ $ php-formatter formatter: use:sort src/ --sort-direction="asc"
247
273
` ` `
248
274
249
275
This command will sort the code like this
@@ -260,7 +286,7 @@ use Symfony\OneClass;
260
286
or descending
261
287
262
288
` ` ` bash
263
- $ php-formatter use:sort src/ --sort-direction="desc"
289
+ $ php-formatter formatter: use:sort src/ --sort-direction="desc"
264
290
` ` `
265
291
266
292
This command will sort the code like this
@@ -273,3 +299,39 @@ use Mmoreram\MySecondClass;
273
299
use Mmoreram\M yClass;
274
300
use AnotherBundle\A notherClass;
275
301
` ` `
302
+
303
+ # ## Fix all PHP headers
304
+
305
+ You can define your PHP header in your `.formatter.yml` file an this command
306
+ will check and fix that all PHP files have it properly.
307
+
308
+ * command: `php-formatter formatter:header:fix`
309
+ * argument: path
310
+ * option: --dry-run [***no value***]
311
+
312
+ # ### Dry run
313
+
314
+ You can use this tool just to test the files will be modified, using option
315
+ --dry-run
316
+
317
+ ` ` ` bash
318
+ $ php-formatter formatter:header:fix src/ --dry-run
319
+ ` ` `
320
+
321
+ Your PHP Header definition must have this format.
322
+
323
+ ` ` ` yml
324
+ header: |
325
+ /**
326
+ * This file is part of the php-formatter package
327
+ *
328
+ * Copyright (c) 2014 Marc Morera
329
+ *
330
+ * For the full copyright and license information, please view the LICENSE
331
+ * file that was distributed with this source code.
332
+ *
333
+ * Feel free to edit as you please, and have fun.
334
+ *
335
+ * @author Marc Morera <[email protected] >
336
+ */
337
+ ` ` `
0 commit comments