Skip to content

Commit b270da2

Browse files
committed
Move method further up the file
This class is (too) long.
1 parent d1bfb0a commit b270da2

File tree

1 file changed

+87
-87
lines changed

1 file changed

+87
-87
lines changed

src/Config.php

Lines changed: 87 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,93 @@ public function processLongArgument($arg, $pos)
12591259
}//end processLongArgument()
12601260

12611261

1262+
/**
1263+
* Parse supplied string into a list of validated sniff codes.
1264+
*
1265+
* @param string $input Comma-separated string of sniff codes.
1266+
* @param string $argument The name of the argument which is being processed.
1267+
*
1268+
* @return string[]
1269+
* @throws DeepExitException When any of the provided codes are not valid as sniff codes.
1270+
*/
1271+
private function parseSniffCodes($input, $argument)
1272+
{
1273+
$errors = [];
1274+
$sniffs = [];
1275+
1276+
$possibleSniffs = array_filter(explode(',', $input));
1277+
1278+
if ($possibleSniffs === []) {
1279+
$errors[] = 'No codes specified / empty argument';
1280+
}
1281+
1282+
foreach ($possibleSniffs as $sniff) {
1283+
$sniff = trim($sniff);
1284+
1285+
$partCount = substr_count($sniff, '.');
1286+
if ($partCount === 2) {
1287+
// Correct number of parts.
1288+
$sniffs[] = $sniff;
1289+
continue;
1290+
}
1291+
1292+
if ($partCount === 0) {
1293+
$errors[] = 'Standard codes are not supported: '.$sniff;
1294+
} else if ($partCount === 1) {
1295+
$errors[] = 'Category codes are not supported: '.$sniff;
1296+
} else if ($partCount === 3) {
1297+
$errors[] = 'Message codes are not supported: '.$sniff;
1298+
} else {
1299+
$errors[] = 'Too many parts: '.$sniff;
1300+
}
1301+
1302+
if ($partCount > 2) {
1303+
$parts = explode('.', $sniff, 4);
1304+
$sniffs[] = $parts[0].'.'.$parts[1].'.'.$parts[2];
1305+
}
1306+
}//end foreach
1307+
1308+
$sniffs = array_reduce(
1309+
$sniffs,
1310+
static function ($carry, $item) {
1311+
$lower = strtolower($item);
1312+
1313+
foreach ($carry as $found) {
1314+
if ($lower === strtolower($found)) {
1315+
// This sniff is already in our list.
1316+
return $carry;
1317+
}
1318+
}
1319+
1320+
$carry[] = $item;
1321+
1322+
return $carry;
1323+
},
1324+
[]
1325+
);
1326+
1327+
if ($errors !== []) {
1328+
$error = 'ERROR: The --'.$argument.' option only supports sniff codes.'.PHP_EOL;
1329+
$error .= 'Sniff codes are in the form "Standard.Category.Sniff".'.PHP_EOL;
1330+
$error .= PHP_EOL;
1331+
$error .= 'The following problems were detected:'.PHP_EOL;
1332+
$error .= '* '.implode(PHP_EOL.'* ', $errors).PHP_EOL;
1333+
1334+
if ($sniffs !== []) {
1335+
$error .= PHP_EOL;
1336+
$error .= 'Perhaps try --'.$argument.'="'.implode(',', $sniffs).'" instead.'.PHP_EOL;
1337+
}
1338+
1339+
$error .= PHP_EOL;
1340+
$error .= $this->printShortUsage(true);
1341+
throw new DeepExitException(ltrim($error), 3);
1342+
}
1343+
1344+
return $sniffs;
1345+
1346+
}//end parseSniffCodes()
1347+
1348+
12621349
/**
12631350
* Processes an unknown command line argument.
12641351
*
@@ -1640,91 +1727,4 @@ public function printConfigData($data)
16401727
}//end printConfigData()
16411728

16421729

1643-
/**
1644-
* Parse supplied string into a list of validated sniff codes.
1645-
*
1646-
* @param string $input Comma-separated string of sniff codes.
1647-
* @param string $argument The name of the argument which is being processed.
1648-
*
1649-
* @return string[]
1650-
* @throws DeepExitException When any of the provided codes are not valid as sniff codes.
1651-
*/
1652-
private function parseSniffCodes($input, $argument)
1653-
{
1654-
$errors = [];
1655-
$sniffs = [];
1656-
1657-
$possibleSniffs = array_filter(explode(',', $input));
1658-
1659-
if ($possibleSniffs === []) {
1660-
$errors[] = 'No codes specified / empty argument';
1661-
}
1662-
1663-
foreach ($possibleSniffs as $sniff) {
1664-
$sniff = trim($sniff);
1665-
1666-
$partCount = substr_count($sniff, '.');
1667-
if ($partCount === 2) {
1668-
// Correct number of parts.
1669-
$sniffs[] = $sniff;
1670-
continue;
1671-
}
1672-
1673-
if ($partCount === 0) {
1674-
$errors[] = 'Standard codes are not supported: '.$sniff;
1675-
} else if ($partCount === 1) {
1676-
$errors[] = 'Category codes are not supported: '.$sniff;
1677-
} else if ($partCount === 3) {
1678-
$errors[] = 'Message codes are not supported: '.$sniff;
1679-
} else {
1680-
$errors[] = 'Too many parts: '.$sniff;
1681-
}
1682-
1683-
if ($partCount > 2) {
1684-
$parts = explode('.', $sniff, 4);
1685-
$sniffs[] = $parts[0].'.'.$parts[1].'.'.$parts[2];
1686-
}
1687-
}//end foreach
1688-
1689-
$sniffs = array_reduce(
1690-
$sniffs,
1691-
static function ($carry, $item) {
1692-
$lower = strtolower($item);
1693-
1694-
foreach ($carry as $found) {
1695-
if ($lower === strtolower($found)) {
1696-
// This sniff is already in our list.
1697-
return $carry;
1698-
}
1699-
}
1700-
1701-
$carry[] = $item;
1702-
1703-
return $carry;
1704-
},
1705-
[]
1706-
);
1707-
1708-
if ($errors !== []) {
1709-
$error = 'ERROR: The --'.$argument.' option only supports sniff codes.'.PHP_EOL;
1710-
$error .= 'Sniff codes are in the form "Standard.Category.Sniff".'.PHP_EOL;
1711-
$error .= PHP_EOL;
1712-
$error .= 'The following problems were detected:'.PHP_EOL;
1713-
$error .= '* '.implode(PHP_EOL.'* ', $errors).PHP_EOL;
1714-
1715-
if ($sniffs !== []) {
1716-
$error .= PHP_EOL;
1717-
$error .= 'Perhaps try --'.$argument.'="'.implode(',', $sniffs).'" instead.'.PHP_EOL;
1718-
}
1719-
1720-
$error .= PHP_EOL;
1721-
$error .= $this->printShortUsage(true);
1722-
throw new DeepExitException(ltrim($error), 3);
1723-
}
1724-
1725-
return $sniffs;
1726-
1727-
}//end parseSniffCodes()
1728-
1729-
17301730
}//end class

0 commit comments

Comments
 (0)