diff vendor/squizlabs/php_codesniffer/src/Runner.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/Runner.php	Thu Feb 28 13:11:55 2019 +0000
+++ b/vendor/squizlabs/php_codesniffer/src/Runner.php	Thu May 09 15:34:47 2019 +0100
@@ -230,9 +230,10 @@
 
 
     /**
-     * Exits if the minimum requirements of PHP_CodSniffer are not met.
+     * Exits if the minimum requirements of PHP_CodeSniffer are not met.
      *
      * @return array
+     * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
      */
     public function checkRequirements()
     {
@@ -242,8 +243,34 @@
             throw new DeepExitException($error, 3);
         }
 
-        if (extension_loaded('tokenizer') === false) {
-            $error = 'ERROR: PHP_CodeSniffer requires the tokenizer extension to be enabled.'.PHP_EOL;
+        $requiredExtensions = [
+            'tokenizer',
+            'xmlwriter',
+            'SimpleXML',
+        ];
+        $missingExtensions  = [];
+
+        foreach ($requiredExtensions as $extension) {
+            if (extension_loaded($extension) === false) {
+                $missingExtensions[] = $extension;
+            }
+        }
+
+        if (empty($missingExtensions) === false) {
+            $last      = array_pop($requiredExtensions);
+            $required  = implode(', ', $requiredExtensions);
+            $required .= ' and '.$last;
+
+            if (count($missingExtensions) === 1) {
+                $missing = $missingExtensions[0];
+            } else {
+                $last     = array_pop($missingExtensions);
+                $missing  = implode(', ', $missingExtensions);
+                $missing .= ' and '.$last;
+            }
+
+            $error = 'ERROR: PHP_CodeSniffer requires the %s extensions to be enabled. Please enable %s.'.PHP_EOL;
+            $error = sprintf($error, $required, $missing);
             throw new DeepExitException($error, 3);
         }
 
@@ -254,6 +281,7 @@
      * Init the rulesets and other high-level settings.
      *
      * @return void
+     * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
      */
     public function init()
     {
@@ -265,6 +293,9 @@
         // be detected properly for files created on a Mac with the /r line ending.
         ini_set('auto_detect_line_endings', true);
 
+        // Disable the PCRE JIT as this caused issues with parallel running.
+        ini_set('pcre.jit', false);
+
         // Check that the standards are valid.
         foreach ($this->config->standards as $standard) {
             if (Util\Standards::isInstalledStandard($standard) === false) {
@@ -280,7 +311,7 @@
         }
 
         // Saves passing the Config object into other objects that only need
-        // the verbostity flag for deubg output.
+        // the verbosity flag for debug output.
         if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
             define('PHP_CODESNIFFER_VERBOSITY', $this->config->verbosity);
         }
@@ -312,6 +343,8 @@
      * Performs the run.
      *
      * @return int The number of errors and warnings found.
+     * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
+     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException
      */
     private function run()
     {
@@ -506,7 +539,10 @@
                 }//end if
             }//end for
 
-            $this->processChildProcs($childProcs);
+            $success = $this->processChildProcs($childProcs);
+            if ($success === false) {
+                throw new RuntimeException('One or more child processes failed to run');
+            }
         }//end if
 
         restore_error_handler();
@@ -558,6 +594,7 @@
      * @param int    $line    The line number the error was raised at.
      *
      * @return void
+     * @throws \PHP_CodeSniffer\Exceptions\RuntimeException
      */
     public function handleErrors($code, $message, $file, $line)
     {
@@ -577,6 +614,7 @@
      * @param \PHP_CodeSniffer\Files\File $file The file to be processed.
      *
      * @return void
+     * @throws \PHP_CodeSniffer\Exceptions\DeepExitException
      */
     public function processFile($file)
     {
@@ -677,20 +715,35 @@
         $numProcessed = 0;
         $totalBatches = count($childProcs);
 
+        $success = true;
+
         while (count($childProcs) > 0) {
             foreach ($childProcs as $key => $procData) {
                 $res = pcntl_waitpid($procData['pid'], $status, WNOHANG);
                 if ($res === $procData['pid']) {
                     if (file_exists($procData['out']) === true) {
                         include $procData['out'];
-                        if (isset($childOutput) === true) {
-                            $this->reporter->totalFiles    += $childOutput['totalFiles'];
-                            $this->reporter->totalErrors   += $childOutput['totalErrors'];
-                            $this->reporter->totalWarnings += $childOutput['totalWarnings'];
-                            $this->reporter->totalFixable  += $childOutput['totalFixable'];
-                            $this->reporter->totalFixed    += $childOutput['totalFixed'];
+
+                        unlink($procData['out']);
+                        unset($childProcs[$key]);
+
+                        $numProcessed++;
+
+                        if (isset($childOutput) === false) {
+                            // The child process died, so the run has failed.
+                            $file = new DummyFile(null, $this->ruleset, $this->config);
+                            $file->setErrorCounts(1, 0, 0, 0);
+                            $this->printProgress($file, $totalBatches, $numProcessed);
+                            $success = false;
+                            continue;
                         }
 
+                        $this->reporter->totalFiles    += $childOutput['totalFiles'];
+                        $this->reporter->totalErrors   += $childOutput['totalErrors'];
+                        $this->reporter->totalWarnings += $childOutput['totalWarnings'];
+                        $this->reporter->totalFixable  += $childOutput['totalFixable'];
+                        $this->reporter->totalFixed    += $childOutput['totalFixed'];
+
                         if (isset($debugOutput) === true) {
                             echo $debugOutput;
                         }
@@ -701,11 +754,6 @@
                             }
                         }
 
-                        unlink($procData['out']);
-                        unset($childProcs[$key]);
-
-                        $numProcessed++;
-
                         // Fake a processed file so we can print progress output for the batch.
                         $file = new DummyFile(null, $this->ruleset, $this->config);
                         $file->setErrorCounts(
@@ -720,20 +768,22 @@
             }//end foreach
         }//end while
 
+        return $success;
+
     }//end processChildProcs()
 
 
     /**
      * Print progress information for a single processed file.
      *
-     * @param File $file         The file that was processed.
-     * @param int  $numFiles     The total number of files to process.
-     * @param int  $numProcessed The number of files that have been processed,
-     *                           including this one.
+     * @param \PHP_CodeSniffer\Files\File $file         The file that was processed.
+     * @param int                         $numFiles     The total number of files to process.
+     * @param int                         $numProcessed The number of files that have been processed,
+     *                                                  including this one.
      *
      * @return void
      */
-    public function printProgress($file, $numFiles, $numProcessed)
+    public function printProgress(File $file, $numFiles, $numProcessed)
     {
         if (PHP_CODESNIFFER_VERBOSITY > 0
             || $this->config->showProgress === false