Mercurial > hg > cmmr2012-drupal-site
diff vendor/squizlabs/php_codesniffer/src/Ruleset.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | a9cd425dd02b |
children |
line wrap: on
line diff
--- a/vendor/squizlabs/php_codesniffer/src/Ruleset.php Thu Feb 28 13:11:55 2019 +0000 +++ b/vendor/squizlabs/php_codesniffer/src/Ruleset.php Thu May 09 15:34:47 2019 +0100 @@ -67,7 +67,7 @@ * The key is the fully qualified name of the sniff class * and the value is the sniff object. * - * @var array<string, \PHP_CodeSniffer\Sniff> + * @var array<string, \PHP_CodeSniffer\Sniffs\Sniff> */ public $sniffs = []; @@ -87,7 +87,7 @@ * The key is the token name being listened for and the value * is the sniff object. * - * @var array<int, \PHP_CodeSniffer\Sniff> + * @var array<int, \PHP_CodeSniffer\Sniffs\Sniff> */ public $tokenListeners = []; @@ -161,8 +161,7 @@ $this->name .= ', '; } - $this->name .= $standardName; - $this->paths[] = $standard; + $this->name .= $standardName; // Allow autoloading of custom files inside this standard. if (isset($ruleset['namespace']) === true) { @@ -305,7 +304,7 @@ * is only used for debug output. * * @return string[] - * @throws RuntimeException If the ruleset path is invalid. + * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the ruleset path is invalid. */ public function processRuleset($rulesetPath, $depth=0) { @@ -315,15 +314,26 @@ echo 'Processing ruleset '.Util\Common::stripBasepath($rulesetPath, $this->config->basepath).PHP_EOL; } - $ruleset = @simplexml_load_string(file_get_contents($rulesetPath)); + libxml_use_internal_errors(true); + $ruleset = simplexml_load_string(file_get_contents($rulesetPath)); if ($ruleset === false) { - throw new RuntimeException("Ruleset $rulesetPath is not valid"); + $errorMsg = "Ruleset $rulesetPath is not valid".PHP_EOL; + $errors = libxml_get_errors(); + foreach ($errors as $error) { + $errorMsg .= '- On line '.$error->line.', column '.$error->column.': '.$error->message; + } + + libxml_clear_errors(); + throw new RuntimeException($errorMsg); } + libxml_use_internal_errors(false); + $ownSniffs = []; $includedSniffs = []; $excludedSniffs = []; + $this->paths[] = $rulesetPath; $rulesetDir = dirname($rulesetPath); $this->rulesetDirs[] = $rulesetDir; @@ -410,7 +420,7 @@ } } else if (empty($newSniffs) === false) { $newSniff = $newSniffs[0]; - if (in_array($newSniff, $ownSniffs) === false) { + if (in_array($newSniff, $ownSniffs, true) === false) { // Including a sniff that hasn't been included higher up, but // only including a single message from it. So turn off all messages in // the sniff, except this one. @@ -457,7 +467,7 @@ } else { $excludedSniffs = array_merge( $excludedSniffs, - $this->expandRulesetReference($exclude['name'], $rulesetDir, ($depth + 1)) + $this->expandRulesetReference((string) $exclude['name'], $rulesetDir, ($depth + 1)) ); } }//end foreach @@ -578,7 +588,7 @@ // sniff list, but filter out any excluded sniffs. $files = []; foreach ($includedSniffs as $sniff) { - if (in_array($sniff, $excludedSniffs) === true) { + if (in_array($sniff, $excludedSniffs, true) === true) { continue; } else { $files[] = Util\Common::realpath($sniff); @@ -660,7 +670,7 @@ * is only used for debug output. * * @return array - * @throws RuntimeException If the reference is invalid. + * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If the reference is invalid. */ private function expandRulesetReference($ref, $rulesetDir, $depth=0) { @@ -715,7 +725,7 @@ if (Util\Common::isPharFile($path) === true && strpos($path, 'ruleset.xml') === false) { // If the ruleset exists inside the phar file, use it. if (file_exists($path.DIRECTORY_SEPARATOR.'ruleset.xml') === true) { - $path = $path.DIRECTORY_SEPARATOR.'ruleset.xml'; + $path .= DIRECTORY_SEPARATOR.'ruleset.xml'; } else { $path = null; } @@ -836,13 +846,13 @@ /** * Processes a rule from a ruleset XML file, overriding built-in defaults. * - * @param SimpleXMLElement $rule The rule object from a ruleset XML file. - * @param string[] $newSniffs An array of sniffs that got included by this rule. - * @param int $depth How many nested processing steps we are in. - * This is only used for debug output. + * @param \SimpleXMLElement $rule The rule object from a ruleset XML file. + * @param string[] $newSniffs An array of sniffs that got included by this rule. + * @param int $depth How many nested processing steps we are in. + * This is only used for debug output. * * @return void - * @throws RuntimeException If rule settings are invalid. + * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If rule settings are invalid. */ private function processRule($rule, $newSniffs, $depth=0) { @@ -1073,7 +1083,7 @@ /** * Determine if an element should be processed or ignored. * - * @param SimpleXMLElement $element An object from a ruleset XML file. + * @param \SimpleXMLElement $element An object from a ruleset XML file. * * @return bool */ @@ -1174,7 +1184,7 @@ * Populates the array of PHP_CodeSniffer_Sniff's for this file. * * @return void - * @throws RuntimeException If sniff registration fails. + * @throws \PHP_CodeSniffer\Exceptions\RuntimeException If sniff registration fails. */ public function populateTokenListeners() {