Skip to content

Commit f4259f1

Browse files
committed
Fix readme and sorting
1 parent 6af91cd commit f4259f1

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

README.md

+16-3
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,30 @@ composer require noximo/phpstan-fileoutput
88

99
## Usage
1010
Edit or create your phpstan.neon file and register new error formatter.
11-
First parameter is mandatory and specifies path to file in which data will be outputed.
11+
First two parameters are mandatory.
12+
13+
- First specifies path to file in which data will be outputed.
14+
15+
- Second specifies which other formatter will be used with FileOutput formatter running silently in the background. You can set it to null if you wish to only work with FileOutput-generated files.
1216
```
1317
services:
1418
errorFormatter.fileoutput: # Can be any name after errorFormatter
15-
class: noximo\FileOutput(./example/phpstan.html)
19+
class: noximo\FileOutput(./example/phpstan.html, null)
1620
```
1721

18-
You can add second parameter to use one of the other formatters as well, so console output can be unaffected:
22+
You can (and should) specify second parameter to use one of the other formatters as well, so console output will be unaffected:
1923
```
2024
class: noximo\FileOutput(./example/phpstan.html, @errorFormatter.raw)
2125
```
26+
At the time of writing of this readme these formatters were available by default in PHPStan:
27+
- ```errorFormatter.checkstyle```,
28+
- ```errorFormatter.json```,
29+
- ```errorFormatter.prettyJson```,
30+
- ```errorFormatter.raw```,
31+
- ```errorFormatter.table```
32+
33+
_Check [PHPStan repository](https://github.com/phpstan/phpstan) for possible updates._
34+
2235
Third parameter sets custom output template.
2336
```
2437
class: noximo\FileOutput(./example/phpstan.html, null, ./tests/alternative_table.phtml)

example/phpstan.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<title>PHPStan analysis result</title>
5353
</head>
5454
<h1>PHPStan analysis result</h1>
55-
<div class="time">2018-11-02 01:16:58</div>
55+
<div class="time">2018-11-02 01:46:21</div>
5656

5757

5858
<div>
@@ -69,24 +69,24 @@ <h1>PHPStan analysis result</h1>
6969
</thead>
7070
<tr>
7171
<td class="line">
72-
<a href='editor://open/?file=C:\wamp64\www\PHPStanFileOutput\tests\MessedUpClass.php&line=23'>23</a>
72+
<a href='editor://open/?file=C:\wamp64\www\PHPStanFileOutput\tests\MessedUpClass.php&line=25'>25</a>
7373
</td>
7474
<td>
75-
PHPDoc tag <b>@param</b> for parameter <b>$problem</b> with type <b>string</b> is incompatible with native type <b>int</b> </td>
75+
Method <b>noximo\MessedUpClass::doSOmething()</b> should return <b>string</b> but returns <b>int.</b> </td>
7676
</tr>
7777
<tr>
7878
<td class="line">
7979
<a href='editor://open/?file=C:\wamp64\www\PHPStanFileOutput\tests\MessedUpClass.php&line=23'>23</a>
8080
</td>
8181
<td>
82-
PHPDoc tag <b>@return</b> with type <b>int</b> is incompatible with native type <b>string</b> </td>
82+
PHPDoc tag <b>@param</b> for parameter <b>$problem</b> with type <b>string</b> is incompatible with native type <b>int</b> </td>
8383
</tr>
8484
<tr>
8585
<td class="line">
86-
<a href='editor://open/?file=C:\wamp64\www\PHPStanFileOutput\tests\MessedUpClass.php&line=25'>25</a>
86+
<a href='editor://open/?file=C:\wamp64\www\PHPStanFileOutput\tests\MessedUpClass.php&line=23'>23</a>
8787
</td>
8888
<td>
89-
Method <b>noximo\MessedUpClass::doSOmething()</b> should return <b>string</b> but returns <b>int.</b> </td>
89+
PHPDoc tag <b>@return</b> with type <b>int</b> is incompatible with native type <b>string</b> </td>
9090
</tr>
9191

9292
</table>

src/FileOutput.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ private function generateFile(AnalysisResult $analysisResult): void
124124
];
125125
}
126126

127-
ksort($output);
127+
foreach ($output[self::FILES] as &$file) {
128+
usort($file, function ($a, $b) {
129+
return -1 * ($a[self::LINE] <=> $b[self::LINE]);
130+
});
131+
}
128132

129133
FileSystem::write($this->outputFile, $this->getTable($output));
130134
}

0 commit comments

Comments
 (0)