public function analyze(File $file)
 {
     if (!$file instanceof PhpFile || !$this->getSetting('enabled')) {
         return;
     }
     $this->phpFile = $file;
     $this->stream->setCode($file->getContent());
     $this->analyzeStream();
 }
 public final function analyze(File $file)
 {
     if (!$file instanceof PhpFile) {
         return;
     }
     $this->phpFile = $file;
     $this->stream->setInput($file->getContent(), $file->getAst());
     $this->analyzeStream();
 }
 public function analyze(File $file)
 {
     if (!$file instanceof PhpFile) {
         return;
     }
     $this->codingStyle = $this->analyzer->getPhpCodingStyle();
     $this->tokens = token_get_all($content = $file->getContent());
     $this->i = -1;
     $this->lines = explode("\n", $content);
     $this->curLine = 1;
     parent::analyze($file);
     while ($this->next()) {
         $this->checkWhitespace();
         if (T_OPEN_TAG === $this->token[0] && '<?' === $this->token[1] && !$this->codingStyle->allowShortPhpOpenTag) {
             $this->addComment(1, 'Please do not use the short-opening tag, but "<?php" instead.');
             continue;
         }
     }
     // Check that file ends with a linefeed character
     if ("\n" !== substr($content, -1)) {
         $this->addComment(count($this->lines), 'Please add a linefeed (\\n) at the end of the file.');
     }
     $foundTabs = $foundLinefeed = $foundTrailingWhitespace = false;
     foreach ($this->lines as $i => $line) {
         // Check that there are no tabs inside the file.
         if (!$foundTabs && preg_match('/^(?: )*\\t/', $line)) {
             $this->addComment($i + 1, 'Please do not use tabs for indentation, but 4 spaces for each tab.');
             // Assume that the users fixes all further occurrences of tabs.
             $foundTabs = true;
             continue;
         }
         // Check for correct line-ending character
         if (!$foundLinefeed && "\r" === substr($line, -1)) {
             $this->addComment($i + 1, 'Please do not use the line-ending (\\r\\n), but only \\n (0x0A).');
             // Assume that the user fixed all further occurrences.
             $foundLinefeed = true;
             continue;
         }
         // Check for trailing white-space
         if (!$foundTrailingWhitespace && preg_match('/\\s+$/', $line)) {
             $this->addComment($i + 1, 'Please do not add trailing whitespace.');
             $foundTrailingWhitespace = true;
             continue;
         }
     }
 }
 public function add(File $file)
 {
     if (isset($this->files[$name = $file->getName()])) {
         throw new \InvalidArgumentException(sprintf('There already exists a file named "%s".', $name));
     }
     $this->files[$name] = $file;
     $this->size += strlen($file->getContent());
 }