Example #1
0
 /**
  * @return int One of the result constants
  */
 public function handle(ConstraintViolationListInterface $constraintViolationList, Text $file)
 {
     $diff = null;
     if ($file instanceof File) {
         foreach ($this->diff as $d) {
             if (substr($d->getTo(), 2) === $file->getFilename()) {
                 $diff = $d;
                 break;
             }
         }
         if (null === $diff) {
             return Reporter::SUCCESS;
         }
     }
     foreach ($constraintViolationList as $offset => $violation) {
         /** @var ConstraintViolation $violation */
         $lineNumber = $this->getLineNumber($violation);
         foreach ($diff->getChunks() as $chunk) {
             if ($chunk->getEnd() > $lineNumber || $chunk->getEnd() + $chunk->getEndRange() < $lineNumber) {
                 $constraintViolationList->remove($offset);
             }
         }
     }
     return $this->reporter->handle($constraintViolationList, $file);
 }
Example #2
0
 public function reviewLine($line, $lineNumber, Text $file)
 {
     if (preg_match('/^([\\~\\!\\"\\#\\$\\%\\&\'\\(\\)\\*\\+,-.\\\\\\/\\:\\;\\<\\=\\>\\?\\@\\[\\]\\^\\_\\`\\{\\|\\}])\\1{3,}$/', trim($line), $data)) {
         $character = $data[1];
         $level = array_search($character, $this->levels);
         if (false === $level) {
             $this->addError('Only =, -, ~, . and " should be used as title underlines');
             return;
         }
         // .inc files are allowed to start with a deeper level.
         $isIncludedFile = $file instanceof File && preg_match('/\\.inc/', $file->getFilename());
         if ($isIncludedFile && !$this->startLevelIsDetermined) {
             $this->startLevelIsDetermined = true;
             $this->currentLevel = $level;
         }
         if ($level <= $this->currentLevel) {
             $this->currentLevel = $level;
             return;
         }
         if ($this->currentLevel + 1 !== $level) {
             $this->addError('The "%underline_char%" character should be used for a title level %level%', array('%underline_char%' => $this->levels[$this->currentLevel + 1], '%level%' => $this->currentLevel + 1));
         } else {
             $this->currentLevel = $level;
         }
     }
 }
Example #3
0
 public function reviewLine($line, $lineNumber, Text $file)
 {
     // exception to the rule: The Quick Tour and Best Practices sections are allowed to use the first person.
     if ($file instanceof File && preg_match('/^(?:quick_tour|best_practices)/', $file->getFilename())) {
         return;
     }
     if (preg_match('/\\b(I(?!\\.)|we|let\'s)\\b/i', $line)) {
         $this->addError('The first person ("I", "we", "let\'s") should always be avoided');
     }
 }
 /**
  * @param mixed $pattern
  * @param Text  $text
  */
 public function __construct($pattern, Text $text)
 {
     $this->pattern = $pattern;
     $this->text = $text;
     $patternMessage = 'given pattern';
     if (is_string($pattern) || is_int($pattern)) {
         $patternMessage .= ' "' . strval($pattern) . '"';
     }
     $textMessage = 'the given text';
     if ($text instanceof File) {
         $textMessage = 'the given file ' . $text->getFilename();
     }
     $message = sprintf('The %s couldn\'t be find in %s', $patternMessage, $textMessage);
     parent::__construct($message);
 }