Skip to content

Commit 0273752

Browse files
committed
minor #4662 DX: generate headers in README.rst (kubawerlos)
This PR was merged into the 2.15 branch. Discussion ---------- DX: generate headers in README.rst Motivated by https://github.com/FriendsOfPHP/PHP-CS-Fixer/pull/4560/files#diff-88b99bb28683bd5b7e3a204826ead112R98 Commits ------- db78f9c DX: generate headers in README.rst
2 parents 82b6e2b + db78f9c commit 0273752

File tree

3 files changed

+38
-42
lines changed

3 files changed

+38
-42
lines changed

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ You can update ``php-cs-fixer`` through this command:
134134
$ brew upgrade php-cs-fixer
135135
136136
Locally (PHIVE)
137-
~~~~~~~~~~~~~~~~~~~
137+
~~~~~~~~~~~~~~~
138138

139139
.. code-block:: bash
140140

src/Console/Command/ReadmeCommand.php

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ protected function configure()
4040
*/
4141
protected function execute(InputInterface $input, OutputInterface $output)
4242
{
43-
$header = <<<'EOF'
44-
PHP Coding Standards Fixer
45-
==========================
43+
$header = <<<EOF
44+
{$this->header('PHP Coding Standards Fixer', '=')}
4645
4746
The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards;
4847
whether you want to follow PHP coding standards as defined in the PSR-1, PSR-2, etc.,
@@ -62,21 +61,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
6261
You can talk to us at https://gitter.im/PHP-CS-Fixer/Lobby about the project,
6362
configuration, possible improvements, ideas and questions, please visit us!
6463
65-
Requirements
66-
------------
64+
{$this->header('Requirements', '-')}
6765
6866
PHP needs to be a minimum version of PHP 5.6.0.
6967
70-
Installation
71-
------------
68+
{$this->header('Installation', '-')}
7269
73-
Locally
74-
~~~~~~~
70+
{$this->header('Locally', '~')}
7571
7672
Download the `php-cs-fixer.phar`_ file and store it somewhere on your computer.
7773
78-
Globally (manual)
79-
~~~~~~~~~~~~~~~~~
74+
{$this->header('Globally (manual)', '~')}
8075
8176
You can run these commands to easily access latest ``php-cs-fixer`` from anywhere on
8277
your system:
@@ -106,8 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
106101
107102
Then, just run ``php-cs-fixer``.
108103
109-
Globally (Composer)
110-
~~~~~~~~~~~~~~~~~~~
104+
{$this->header('Globally (Composer)', '~')}
111105
112106
To install PHP CS Fixer, `install Composer <https://getcomposer.org/download/>`_ and issue the following command:
113107
@@ -119,79 +113,69 @@ protected function execute(InputInterface $input, OutputInterface $output)
119113
120114
.. code-block:: bash
121115
122-
$ export PATH="$PATH:$HOME/.composer/vendor/bin"
116+
$ export PATH="\$PATH:\$HOME/.composer/vendor/bin"
123117
124-
Globally (homebrew)
125-
~~~~~~~~~~~~~~~~~~~
118+
{$this->header('Globally (homebrew)', '~')}
126119
127120
.. code-block:: bash
128121
129122
$ brew install php-cs-fixer
130123
131-
Locally (PHIVE)
132-
~~~~~~~~~~~~~~~
124+
{$this->header('Locally (PHIVE)', '~')}
133125
134126
Install `PHIVE <https://phar.io>`_ and issue the following command:
135127
136128
.. code-block:: bash
137129
138130
$ phive install php-cs-fixer # use `--global` for global install
139131
140-
Update
141-
------
132+
{$this->header('Update', '-')}
142133
143-
Locally
144-
~~~~~~~
134+
{$this->header('Locally', '~')}
145135
146136
The ``self-update`` command tries to update ``php-cs-fixer`` itself:
147137
148138
.. code-block:: bash
149139
150140
$ php php-cs-fixer.phar self-update
151141
152-
Globally (manual)
153-
~~~~~~~~~~~~~~~~~
142+
{$this->header('Globally (manual)', '~')}
154143
155144
You can update ``php-cs-fixer`` through this command:
156145
157146
.. code-block:: bash
158147
159148
$ sudo php-cs-fixer self-update
160149
161-
Globally (Composer)
162-
~~~~~~~~~~~~~~~~~~~
150+
{$this->header('Globally (Composer)', '~')}
163151
164152
You can update ``php-cs-fixer`` through this command:
165153
166154
.. code-block:: bash
167155
168156
$ ./composer.phar global update friendsofphp/php-cs-fixer
169157
170-
Globally (homebrew)
171-
~~~~~~~~~~~~~~~~~~~
158+
{$this->header('Globally (homebrew)', '~')}
172159
173160
You can update ``php-cs-fixer`` through this command:
174161
175162
.. code-block:: bash
176163
177164
$ brew upgrade php-cs-fixer
178165
179-
Locally (PHIVE)
180-
~~~~~~~~~~~~~~~~~~~
166+
{$this->header('Locally (PHIVE)', '~')}
181167
182168
.. code-block:: bash
183169
184170
$ phive update php-cs-fixer
185171
186-
Usage
187-
-----
172+
{$this->header('Usage', '-')}
188173
189174
EOF;
190175

191-
$footer = <<<'EOF'
176+
$footer = <<<EOF
192177
193-
Helpers
194-
-------
178+
{$this->header('Helpers', '-')}
195179
196180
Dedicated plugins exist for:
197181
@@ -202,20 +186,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
202186
* `Vim`_
203187
* `VS Code`_
204188
205-
Contribute
206-
----------
189+
{$this->header('Contribute', '-')}
207190
208191
The tool comes with quite a few built-in fixers, but everyone is more than
209192
welcome to `contribute`_ more of them.
210193
211-
Fixers
212-
~~~~~~
194+
{$this->header('Fixers', '~')}
213195
214196
A *fixer* is a class that tries to fix one CS issue (a ``Fixer`` class must
215197
implement ``FixerInterface``).
216198
217-
Configs
218-
~~~~~~~
199+
{$this->header('Configs', '~')}
219200
220201
A *config* knows about the CS rules and the files and directories that must be
221202
scanned by the tool when run in the directory of your project. It is useful for
@@ -290,4 +271,9 @@ static function (array $matches) {
290271

291272
return 0;
292273
}
274+
275+
private function header($name, $underline)
276+
{
277+
return $name."\n".str_repeat($underline, \strlen($name));
278+
}
293279
}

tests/Console/Command/ReadmeCommandTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
namespace PhpCsFixer\Tests\Console\Command;
1414

1515
use PhpCsFixer\Console\Application;
16+
use PhpCsFixer\Console\Command\ReadmeCommand;
1617
use PhpCsFixer\Tests\TestCase;
1718
use Symfony\Component\Console\Tester\CommandTester;
1819

@@ -55,4 +56,13 @@ public function testIfReadmeFileIsCorrect()
5556
'README.rst file is not up to date! Do not modify it manually! Regenerate readme with command: `php php-cs-fixer readme > README.rst`.'
5657
);
5758
}
59+
60+
public function testCodeNotHaveUnderlinishStyleOfHeaders()
61+
{
62+
static::assertNotRegExp(
63+
'/([^\s])\1{4,}/',
64+
file_get_contents((new \ReflectionClass(ReadmeCommand::class))->getFileName()),
65+
'Five same characters in row found'
66+
);
67+
}
5868
}

0 commit comments

Comments
 (0)