Skip to content

Commit 4b912a7

Browse files
committed
Standards: introduce prepareInstalledStandardsForDisplay() method
This commit introduces a new `Standards::prepareInstalledStandardsForDisplay()` method. This new method only prepares the "list" into displayable phrases. It doesn't include output formatting with new lines, that's up to the actual display. This new method allows for getting rid of some output buffering calls in select places. Includes improving the readability of the "coding standard is not installed" error. Includes deprecating the `Standards::printInstalledStandards()` method, which is now no longer used by PHPCS itself.
1 parent d12e243 commit 4b912a7

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

src/Config.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -685,10 +685,7 @@ public function processShortArgument($arg, $pos)
685685
ob_end_clean();
686686
throw new DeepExitException($output, 0);
687687
case 'i' :
688-
ob_start();
689-
Standards::printInstalledStandards();
690-
$output = ob_get_contents();
691-
ob_end_clean();
688+
$output = Standards::prepareInstalledStandardsForDisplay().PHP_EOL;
692689
throw new DeepExitException($output, 0);
693690
case 'v' :
694691
if ($this->quiet === true) {

src/Runner.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,8 @@ public function init()
258258
if (Standards::isInstalledStandard($standard) === false) {
259259
// They didn't select a valid coding standard, so help them
260260
// out by letting them know which standards are installed.
261-
$error = 'ERROR: the "'.$standard.'" coding standard is not installed. ';
262-
ob_start();
263-
Standards::printInstalledStandards();
264-
$error .= ob_get_contents();
265-
ob_end_clean();
261+
$error = 'ERROR: the "'.$standard.'" coding standard is not installed.'.PHP_EOL.PHP_EOL;
262+
$error .= Standards::prepareInstalledStandardsForDisplay().PHP_EOL;
266263
throw new DeepExitException($error, 3);
267264
}
268265
}

src/Util/Standards.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,28 +312,45 @@ public static function getInstalledStandardPath($standard)
312312

313313

314314
/**
315-
* Prints out a list of installed coding standards.
315+
* Prepares a list of installed coding standards for display.
316316
*
317-
* @return void
317+
* @return string
318318
*/
319-
public static function printInstalledStandards()
319+
public static function prepareInstalledStandardsForDisplay()
320320
{
321321
$installedStandards = self::getInstalledStandards();
322322
$numStandards = count($installedStandards);
323323

324+
$output = '';
324325
if ($numStandards === 0) {
325-
echo 'No coding standards are installed.'.PHP_EOL;
326+
$output .= 'No coding standards are installed.';
326327
} else {
327328
$lastStandard = array_pop($installedStandards);
328329
if ($numStandards === 1) {
329-
echo "The only coding standard installed is $lastStandard".PHP_EOL;
330+
$output .= "The only coding standard installed is $lastStandard";
330331
} else {
331332
$standardList = implode(', ', $installedStandards);
332333
$standardList .= ' and '.$lastStandard;
333-
echo 'The installed coding standards are '.$standardList.PHP_EOL;
334+
$output .= 'The installed coding standards are '.$standardList;
334335
}
335336
}
336337

338+
return $output;
339+
340+
}//end prepareInstalledStandardsForDisplay()
341+
342+
343+
/**
344+
* Prints out a list of installed coding standards.
345+
*
346+
* @deprecated 4.0.0 Use `echo Standards::prepareInstalledStandardsForDisplay()` instead.
347+
*
348+
* @return void
349+
*/
350+
public static function printInstalledStandards()
351+
{
352+
echo self::prepareInstalledStandardsForDisplay(), PHP_EOL;
353+
337354
}//end printInstalledStandards()
338355

339356

0 commit comments

Comments
 (0)