Skip to content

Commit 517711f

Browse files
committed
Improve README
1 parent 6665608 commit 517711f

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

README.md

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,55 @@ Some code is copied from phpstan. See [#4122](https://github.com/phpstan/phpstan
1313

1414
## Example usages
1515

16+
### Format errors
17+
18+
```php
19+
use CodeLts\CliTools\Error;
20+
use CodeLts\CliTools\AnalysisResult;
21+
use CodeLts\CliTools\OutputFormat;
22+
use CodeLts\CliTools\Exceptions\FormatNotFoundException;
23+
24+
// if the value is from an user input
25+
// Will throw FormatNotFoundException
26+
// See valid formats at OutputFormat::VALID_OUTPUT_FORMATS
27+
OutputFormat::checkOutputFormatIsValid('notValidFormat');
28+
29+
$fileSpecificErrors = [
30+
new Error(
31+
'My error message',
32+
'/file/path/to/File.php',
33+
15 // Line number
34+
),
35+
];
36+
37+
$notFileSpecificErrors = [
38+
'Just an error message',
39+
];
40+
41+
$internalErrors = [
42+
'Oops the internal engine did crash !',
43+
];
44+
45+
$warnings = [
46+
'I warn you that most of this code is tested',
47+
'Contributions are very welcome',
48+
];
49+
50+
$analysisResult = new AnalysisResult(
51+
$fileSpecificErrors,
52+
$notFileSpecificErrors,
53+
$internalErrors,
54+
$warnings
55+
);
56+
57+
OutputFormat::displayUserChoiceFormat(
58+
OutputFormat::OUTPUT_FORMAT_TABLE,// The phpstan table error format, you can have a lot more formats in OutputFormat::VALID_OUTPUT_FORMATS
59+
$analysisResult,
60+
$this->sourceRootDirectory,// can be null, if null the error paths will not be pretty and will be displayed as given
61+
$this->output // Implement CodeLts\CliTools\Output or use CodeLts\CliTools\Symfony\SymfonyOutput
62+
);
63+
```
64+
1665
### Read/Write files
1766

1867
```php
@@ -23,8 +72,16 @@ $fileName = 'myFile.txt';
2372

2473
FileWriter::write(
2574
$fileName,
26-
'the contents of your file'
75+
'Some data, blob, blob, blob.'
2776
);
2877

29-
FileReader::read($fileName);// -> the contents of your file
78+
FileReader::read($fileName);// -> Some data, blob, blob, blob.
79+
```
80+
81+
### ANSI codes
82+
83+
```php
84+
use CodeLts\CliTools\File\AnsiEscapeSequences;
85+
86+
$this->output->writeFormatted(AnsiEscapeSequences::ERASE_TO_LINE_END);
3087
```

0 commit comments

Comments
 (0)