annotate vendor/squizlabs/php_codesniffer/src/Files/DummyFile.php @ 4:a9cd425dd02b

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:11:55 +0000
parents
children 12f9dff5fda9
rev   line source
Chris@4 1 <?php
Chris@4 2 /**
Chris@4 3 * A dummy file represents a chunk of text that does not have a file system location.
Chris@4 4 *
Chris@4 5 * Dummy files can also represent a changed (but not saved) version of a file
Chris@4 6 * and so can have a file path either set manually, or set by putting
Chris@4 7 * phpcs_input_file: /path/to/file
Chris@4 8 * as the first line of the file contents.
Chris@4 9 *
Chris@4 10 * @author Greg Sherwood <gsherwood@squiz.net>
Chris@4 11 * @copyright 2006-2015 Squiz Pty Ltd (ABN 77 084 670 600)
Chris@4 12 * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
Chris@4 13 */
Chris@4 14
Chris@4 15 namespace PHP_CodeSniffer\Files;
Chris@4 16
Chris@4 17 use PHP_CodeSniffer\Ruleset;
Chris@4 18 use PHP_CodeSniffer\Config;
Chris@4 19
Chris@4 20 class DummyFile extends File
Chris@4 21 {
Chris@4 22
Chris@4 23
Chris@4 24 /**
Chris@4 25 * Creates a DummyFile object and sets the content.
Chris@4 26 *
Chris@4 27 * @param string $content The content of the file.
Chris@4 28 * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
Chris@4 29 * @param \PHP_CodeSniffer\Config $config The config data for the run.
Chris@4 30 *
Chris@4 31 * @return void
Chris@4 32 */
Chris@4 33 public function __construct($content, Ruleset $ruleset, Config $config)
Chris@4 34 {
Chris@4 35 $this->setContent($content);
Chris@4 36
Chris@4 37 // See if a filename was defined in the content.
Chris@4 38 // This is done by including: phpcs_input_file: [file path]
Chris@4 39 // as the first line of content.
Chris@4 40 $path = 'STDIN';
Chris@4 41 if ($content !== null) {
Chris@4 42 if (substr($content, 0, 17) === 'phpcs_input_file:') {
Chris@4 43 $eolPos = strpos($content, $this->eolChar);
Chris@4 44 $filename = trim(substr($content, 17, ($eolPos - 17)));
Chris@4 45 $content = substr($content, ($eolPos + strlen($this->eolChar)));
Chris@4 46 $path = $filename;
Chris@4 47
Chris@4 48 $this->setContent($content);
Chris@4 49 }
Chris@4 50 }
Chris@4 51
Chris@4 52 // The CLI arg overrides anything passed in the content.
Chris@4 53 if ($config->stdinPath !== null) {
Chris@4 54 $path = $config->stdinPath;
Chris@4 55 }
Chris@4 56
Chris@4 57 return parent::__construct($path, $ruleset, $config);
Chris@4 58
Chris@4 59 }//end __construct()
Chris@4 60
Chris@4 61
Chris@4 62 /**
Chris@4 63 * Set the error, warning, and fixable counts for the file.
Chris@4 64 *
Chris@4 65 * @param int $errorCount The number of errors found.
Chris@4 66 * @param int $warningCount The number of warnings found.
Chris@4 67 * @param int $fixableCount The number of fixable errors found.
Chris@4 68 * @param int $fixedCount The number of errors that were fixed.
Chris@4 69 *
Chris@4 70 * @return void
Chris@4 71 */
Chris@4 72 public function setErrorCounts($errorCount, $warningCount, $fixableCount, $fixedCount)
Chris@4 73 {
Chris@4 74 $this->errorCount = $errorCount;
Chris@4 75 $this->warningCount = $warningCount;
Chris@4 76 $this->fixableCount = $fixableCount;
Chris@4 77 $this->fixedCount = $fixedCount;
Chris@4 78
Chris@4 79 }//end setErrorCounts()
Chris@4 80
Chris@4 81
Chris@4 82 }//end class