10
10
use Doctrine \RST \ErrorManager ;
11
11
use Doctrine \RST \Event \PostNodeCreateEvent ;
12
12
use Doctrine \RST \Meta \Metas ;
13
+ use Symfony \CodeBlockChecker \Issue \IssueCollection ;
13
14
use Symfony \CodeBlockChecker \Listener \CodeNodeCollector ;
14
15
use Symfony \CodeBlockChecker \Service \Baseline ;
15
16
use Symfony \CodeBlockChecker \Service \CodeNodeRunner ;
@@ -81,22 +82,9 @@ protected function initialize(InputInterface $input, OutputInterface $output)
81
82
82
83
protected function execute (InputInterface $ input , OutputInterface $ output ): int
83
84
{
84
- $ files = $ input ->getArgument ('files ' );
85
- if ([] === $ files ) {
86
- $ files = $ this ->findFiles ($ input ->getArgument ('source-dir ' ));
87
- }
88
-
89
- $ parseQueue = new ParseQueue ();
90
- foreach ($ files as $ filename ) {
91
- // Remove ".rst"
92
- if ('.rst ' === substr ($ filename , -4 )) {
93
- $ filename = substr ($ filename , 0 , -4 );
94
- }
95
- $ parseQueue ->addFile (ltrim ($ filename , '/ ' ), true );
96
- }
97
-
98
85
// This will collect all CodeNodes
99
- $ this ->queueProcessor ->process ($ parseQueue );
86
+ $ this ->queueProcessor ->process ($ this ->prepareParseQueue ($ input ));
87
+
100
88
// Verify code blocks
101
89
$ issues = $ this ->validator ->validateNodes ($ this ->collector ->getNodes ());
102
90
if ($ applicationDir = $ input ->getOption ('symfony-application ' )) {
@@ -119,25 +107,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
119
107
$ issues = $ this ->baseline ->filter ($ issues , $ baseline );
120
108
}
121
109
122
- $ issueCount = count ($ issues );
123
- if ($ issueCount > 0 ) {
124
- $ format = $ input ->getOption ('output-format ' );
125
- if ('console ' === $ format ) {
126
- foreach ($ issues as $ issue ) {
127
- $ this ->io ->writeln ($ issue ->__toString ());
128
- }
129
-
130
- $ this ->io ->error (sprintf ('Build completed with %s errors ' , $ issueCount ));
131
- } elseif ('github ' === $ format ) {
132
- foreach ($ issues as $ issue ) {
133
- // We use urlencoded '\n'
134
- $ text = str_replace (PHP_EOL , '%0A ' , $ issue ->getText ());
135
- $ this ->io ->writeln (sprintf ('::error file=%s,line=%s::[%s] %s ' , $ issue ->getFile (), $ issue ->getLine (), $ issue ->getType (), $ text ));
136
- }
137
- }
110
+ if (count ($ issues ) > 0 ) {
111
+ $ this ->outputIssue ($ input ->getOption ('output-format ' ), $ issues );
138
112
139
113
return Command::FAILURE ;
140
114
}
115
+
141
116
$ this ->io ->success ('Build completed successfully! ' );
142
117
143
118
return Command::SUCCESS ;
@@ -155,4 +130,57 @@ private function findFiles(string $directory): array
155
130
156
131
return $ files ;
157
132
}
133
+
134
+ private function prepareParseQueue (InputInterface $ input ): ParseQueue
135
+ {
136
+ $ sourceDirectory = $ input ->getArgument ('source-dir ' );
137
+ $ files = $ input ->getArgument ('files ' );
138
+ if ([] === $ files ) {
139
+ $ files = $ this ->findFiles ($ sourceDirectory );
140
+ } else {
141
+ foreach ($ files as $ i => $ file ) {
142
+ if (!file_exists ($ sourceDirectory .DIRECTORY_SEPARATOR .$ file )) {
143
+ unset($ files [$ i ]);
144
+ $ this ->outputWarning ($ input ->getOption ('output-format ' ), sprintf ('Could not find file "%s" ' , $ file ));
145
+ }
146
+ }
147
+ }
148
+
149
+ $ parseQueue = new ParseQueue ();
150
+ foreach ($ files as $ filename ) {
151
+ // Remove ".rst"
152
+ if ('.rst ' === substr ($ filename , -4 )) {
153
+ $ filename = substr ($ filename , 0 , -4 );
154
+ }
155
+ $ parseQueue ->addFile (ltrim ($ filename , '/ ' ), true );
156
+ }
157
+
158
+ return $ parseQueue ;
159
+ }
160
+
161
+ private function outputWarning (string $ format , string $ text ): void
162
+ {
163
+ if ('console ' === $ format ) {
164
+ $ this ->io ->warning ($ text );
165
+ } elseif ('github ' === $ format ) {
166
+ $ this ->io ->writeln ('::warning:: ' .$ text );
167
+ }
168
+ }
169
+
170
+ private function outputIssue (string $ format , IssueCollection $ issues ): void
171
+ {
172
+ if ('console ' === $ format ) {
173
+ foreach ($ issues as $ issue ) {
174
+ $ this ->io ->writeln ($ issue ->__toString ());
175
+ }
176
+
177
+ $ this ->io ->error (sprintf ('Build completed with %s errors ' , $ issues ->count ()));
178
+ } elseif ('github ' === $ format ) {
179
+ foreach ($ issues as $ issue ) {
180
+ // We use urlencoded '\n'
181
+ $ text = str_replace (PHP_EOL , '%0A ' , $ issue ->getText ());
182
+ $ this ->io ->writeln (sprintf ('::error file=%s,line=%s::[%s] %s ' , $ issue ->getFile (), $ issue ->getLine (), $ issue ->getType (), $ text ));
183
+ }
184
+ }
185
+ }
158
186
}
0 commit comments