Commit d7debc8
committed
Config: only determine screen width if/when needed
Follow up on 3761 for which tests were added in 3820.
I'm not sure about *nix, but on Windows, the call to `shell_exec('stty ...')` is slow.
As things were, the call to `shell_exec('stty ...')` would be:
* Made when the initial default value for `reportWidth` is being set in `restoreDefaults()`.
* Potentially made a second time if the users `CodeSniffer.conf` file contained a `report_width => 'auto'` entry.
* Potentially made a third time if any of the rulesets used for the run contained a `<config name="report-width" value="auto"/>` entry.
* Potentially made a fourth time if `--report-width=auto` would be passed from the command-line.
This is inefficient for the following reasons:
1. The output from `shell_exec('stty ...')` does not change between calls (well, providing the user doesn't resize their terminal in the microseconds between calls)
2. We don't actually need to _know_ the value `'auto'` translates to, until the `reportWidth` will be _used_.
Taking the above into account, making the same call up to four times is not desirable.
This commit moves the translation from `'auto'` to an actual terminal width from the `__set()` method to the `__get()` method and overwrites the `reportWidth` value from `'auto'` with the actual terminal width value, if available, and with the default value if the terminal width could not be determined.
This means that subsequent calls to `__get()` for the `reportWidth` will automatically use the previously determined value instead of trying to determine value again.
This removes the inefficiency and should make PHPCS runs a little bit faster (at the very least on Windows).
The only time multiple calls to `shell_exec('stty...')` could now need to be made, would be if the `reportWidth` would be changed (back to `'auto'`) between the first retrieval and a subsequent retrieval of the `reportWidth` value. As things are, this will never happen in a normal PHPCS run, though could possibly happen in a test situation.1 parent 4ac5785 commit d7debc8
1 file changed
+20
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
210 | 226 | | |
211 | 227 | | |
212 | 228 | | |
| |||
229 | 245 | | |
230 | 246 | | |
231 | 247 | | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
239 | 251 | | |
240 | 252 | | |
241 | 253 | | |
| |||
246 | 258 | | |
247 | 259 | | |
248 | 260 | | |
| 261 | + | |
249 | 262 | | |
250 | 263 | | |
251 | 264 | | |
| |||
0 commit comments