Пример #1
0
 /**
  * Creates a LocalFile object and sets the content.
  *
  * @param string                   $path    The absolute path to the file.
  * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
  * @param \PHP_CodeSniffer\Config  $config  The config data for the run.
  *
  * @return void
  */
 public function __construct($path, Ruleset $ruleset, Config $config)
 {
     $path = trim($path);
     if (is_readable($path) === false) {
         parent::__construct($path, $ruleset, $config);
         $error = 'Error opening file; file no longer exists or you do not have access to read the file';
         $this->addMessage(true, $error, 1, 1, 'Internal.LocalFile', array(), 5, false);
         $this->ignored = true;
         return;
     }
     // Before we go and spend time tokenizing this file, just check
     // to see if there is a tag up top to indicate that the whole
     // file should be ignored. It must be on one of the first two lines.
     $handle = fopen($path, 'r');
     if ($handle !== false) {
         $firstContent = fgets($handle);
         $firstContent .= fgets($handle);
         fclose($handle);
         if (strpos($firstContent, '@codingStandardsIgnoreFile') !== false) {
             // We are ignoring the whole file.
             if (PHP_CODESNIFFER_VERBOSITY > 0) {
                 echo 'Ignoring ' . basename($path) . PHP_EOL;
             }
             $this->ignored = true;
             return;
         }
     }
     $this->path = $path;
     $this->reloadContent();
     return parent::__construct($path, $ruleset, $config);
 }
Пример #2
0
 /**
  * Creates a DummyFile object and sets the content.
  *
  * @param string                   $content The content of the file.
  * @param \PHP_CodeSniffer\Ruleset $ruleset The ruleset used for the run.
  * @param \PHP_CodeSniffer\Config  $config  The config data for the run.
  *
  * @return void
  */
 public function __construct($content, Ruleset $ruleset, Config $config)
 {
     $this->setContent($content);
     // See if a filename was defined in the content.
     // This is done by including: phpcs_input_file: [file path]
     // as the first line of content.
     $path = 'STDIN';
     if ($content !== null) {
         if (substr($content, 0, 17) === 'phpcs_input_file:') {
             $eolPos = strpos($content, $this->eolChar);
             $filename = trim(substr($content, 17, $eolPos - 17));
             $content = substr($content, $eolPos + strlen($this->eolChar));
             $path = $filename;
             $this->setContent($content);
         }
     }
     // The CLI arg overrides anything passed in the content.
     if ($config->stdinPath !== null) {
         $path = $config->stdinPath;
     }
     return parent::__construct($path, $ruleset, $config);
 }