/** * visitFile(): defined by FileRuleInterface. * * @see FileRuleInterface::visitFile() * @param File $file * @return void */ public function visitFile(File $file) { foreach ($file->getLines() as $line => $data) { if (preg_match('(\\s+$)', $data['content'])) { $this->addViolation($file, $line, 0, 'Line contains trailing whitespace'); } } }
/** * visitFile(): defined by FileRuleInterface. * * @see FileRuleInterface::visitFile() * @param File $file * @return void */ public function visitFile(File $file) { foreach ($file->getLines() as $line => $data) { if ($data['ending'] !== '' && $data['ending'] !== $this->eolChar) { $ending = str_replace(array("\r", "\n"), array('\\r', '\\n'), $data['ending']); $this->addViolation($file, $line, 0, sprintf('Line must end with "%s", found "%s"', $this->eolName, $ending)); } } }
/** * visitFile(): defined by FileRuleInterface. * * @see FileRuleInterface::visitFile() * @param File $file * @return void */ public function visitFile(File $file) { foreach ($file->getLines() as $line => $data) { $lineLength = iconv_strlen(str_replace("\t", str_repeat(' ', $this->tabExpand), $data['content']), $file->getEncoding()); $violationLimit = null; $severity = null; if ($this->errorLimit !== null && $lineLength > $this->errorLimit) { $violationLimit = $this->errorLimit; $severity = Violation::SEVERITY_ERROR; } elseif ($this->warningLimit !== null && $lineLength > $this->warningLimit) { $violationLimit = $this->warningLimit; $severity = Violation::SEVERITY_WARNING; } elseif ($this->infoLimit !== null && $lineLength > $this->infoLimit) { $violationLimit = $this->infoLimit; $severity = Violation::SEVERITY_INFO; } if ($violationLimit !== null) { $this->addViolation($file, $line, 0, sprintf('Line is longer than %d characters', $violationLimit), $severity); } } }