annotate vendor/squizlabs/php_codesniffer/src/Files/DummyFile.php @ 19:fa3358dc1485 tip

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