コード例 #1
0
 function let(TextSanitizer $textSanitizer, LocationSanitizer $locationSanitizer, Text $text)
 {
     $this->rootPath = __DIR__ . '/../../../../../';
     $filename = sprintf(self::ORIGINAL_FILENAME, $this->rootPath);
     $lines = file($filename, FILE_IGNORE_NEW_LINES);
     $line = $lines[self::LINE_NUMBER];
     $text->getLine(self::LINE_NUMBER)->willReturn($line);
     $this->beConstructedWith($textSanitizer, $locationSanitizer);
 }
コード例 #2
0
ファイル: TrailingWhitespace.php プロジェクト: wouterj/docbot
 public function reviewLine($line, $lineNumber, Text $file)
 {
     if (0 === strlen($line)) {
         return;
     }
     if (rtrim($line) !== $line) {
         $this->addError('There should be no trailing whitespace at the end of a line');
     } elseif (preg_match('/[\\w.]\\s{2,}\\w/', $line) && !preg_match('/^[\\w=]+$/', $file->getLine($line + 1))) {
         $this->addError('This line contains successive whitespaces');
     }
 }
コード例 #3
0
ファイル: TitleUnderline.php プロジェクト: wouterj/docbot
 public function reviewLine($line, $lineNumber, Text $file)
 {
     if (preg_match('/^(^[\\~\\!\\"\\#\\$\\%\\&\'\\(\\)\\*\\+,-.\\\\\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\_\\`\\{\\|\\}])\\1{3,}$/', trim($line))) {
         if ($lineNumber === 0) {
             return;
         }
         $titleText = $file->getLine($lineNumber - 1);
         if (strlen(trim($titleText)) !== strlen(trim($line))) {
             $this->addError('The underline of a title should have exact the same length as the text of the title');
         }
     }
 }
コード例 #4
0
 public function reviewLine($line, $lineNumber, Text $file)
 {
     if (preg_match('/^\\s*\\.\\. ([\\w-]+)::|::$/', $line, $data)) {
         $nextLine = $file->getLine($lineNumber + 1);
         if (isset($data[1]) && 'versionadded' === $data[1]) {
             if (trim($nextLine) === '') {
                 $this->addError('There should be no empty line between the start of a versionadded directive and the body', array(), $lineNumber + 3);
             }
             return;
         }
         if (':' === substr(trim($nextLine), 0, 1) || isset($data[1]) && 'index' === $data[1]) {
             return;
         }
         if (trim($nextLine) !== '') {
             $this->addError('There should be an empty line between the body and the start of a directive (except from versionadded directives)', array(), $lineNumber + 2);
         }
     }
 }
コード例 #5
0
ファイル: ShortPhpSyntax.php プロジェクト: wouterj/docbot
 public function reviewLine($line, $lineNumber, Text $file)
 {
     if ('.. code-block:: php' === trim($line)) {
         $lineBefore = null;
         $lineBeforeNumber = $lineNumber;
         while ($lineBeforeNumber > 0) {
             $lineBefore = $file->getLine(--$lineBeforeNumber);
             if (trim($lineBefore) !== '') {
                 break;
             }
         }
         if (null === $lineBefore) {
             return;
         }
         if (preg_match('/:$/', rtrim($lineBefore))) {
             $this->addError('The short syntax for PHP code (::) should be used here');
         }
     }
 }
コード例 #6
0
ファイル: TitleCase.php プロジェクト: wouterj/docbot
 public function reviewLine($line, $lineNumber, Text $file)
 {
     if (preg_match('/^([\\~\\!\\"\\#\\$\\%\\&\'\\(\\)\\*\\+,-.\\\\\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\_\\`\\{\\|\\}])\\1{3,}$/', trim($line))) {
         if ($lineNumber === 0) {
             return;
         }
         $titleText = trim($file->getLine($lineNumber - 1));
         $words = explode(' ', $titleText);
         if (count($words) === 1) {
             return;
         }
         $correctTitle = '';
         $nextShouldBeCapitialized = false;
         foreach ($words as $word) {
             $wordIsInClosedClass = in_array(strtolower($word), self::$closedClassWords);
             if (!$nextShouldBeCapitialized && $wordIsInClosedClass) {
                 // lowercase
                 $correctTitle .= strtolower($word[0]) . substr($word, 1);
             } else {
                 // capitialize
                 $correctTitle .= ucfirst($word);
             }
             if (in_array(substr($correctTitle, -1), array(':', '.'))) {
                 $nextShouldBeCapitialized = true;
             } else {
                 $nextShouldBeCapitialized = false;
             }
             $correctTitle .= ' ';
         }
         $correctTitle = trim(ucfirst($correctTitle));
         if (ucfirst($correctTitle) !== $titleText) {
             // exception: field type references start with a lowercase word
             if (preg_match('/^[a-z]+ Field Type$/', trim($titleText))) {
                 return;
             }
             $this->addError('All words, except from closed-class words, have to be capitalized: "%correct_title%"', array('%correct_title%' => $correctTitle), $lineNumber);
         }
     }
 }
コード例 #7
0
ファイル: Console.php プロジェクト: wouterj/docbot
 private function printLine(Text $file, $lineNumber)
 {
     $line = $file->getLine($lineNumber - 1);
     $this->output->writeln('<comment>[' . $lineNumber . ']</comment> "' . $line . '"');
 }