@@ -13,6 +13,55 @@ Some code is copied from phpstan. See [#4122](https://github.com/phpstan/phpstan
13
13
14
14
## Example usages
15
15
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
+
16
65
### Read/Write files
17
66
18
67
``` php
@@ -23,8 +72,16 @@ $fileName = 'myFile.txt';
23
72
24
73
FileWriter::write(
25
74
$fileName,
26
- 'the contents of your file '
75
+ 'Some data, blob, blob, blob. '
27
76
);
28
77
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);
30
87
```
0 commit comments