Author: James Brooks (jbrooksuk@me.com)
Exemplo n.º 1
0
 /**
  * Set the severity level of the check.
  *
  * @param int $severity
  *
  * @return \HippoPHP\Hippo\AbstractCheck
  */
 public function setSeverity($severity)
 {
     if (null !== ($severity = Violation::getSeverityFromString($severity))) {
         $this->severity = $severity;
     }
     return $this;
 }
Exemplo n.º 2
0
 private function handleQuietArgument($argValue)
 {
     $this->loggedSeverities = $argValue ? [] : Violation::getSeverities();
 }
Exemplo n.º 3
0
 /**
  * @param FileSystem $fileSystem
  */
 public function __construct(FileSystem $fileSystem)
 {
     $this->fileSystem = $fileSystem;
     $this->loggedSeverities = Violation::getSeverities();
 }
Exemplo n.º 4
0
 /**
  * Generates a key for a violation.
  *
  * @param Violation $violation
  *
  * @return string
  */
 private function getArrayKey(Violation $violation)
 {
     return $violation->getFile()->getFilename() . ':' . $violation->getLine();
 }
Exemplo n.º 5
0
 /**
  * checkFileInternal(): defined by AbstractCheck.
  *
  * @see AbstractCheck::checkFileInternal()
  *
  * @param CheckContext $checkContext
  * @param Config       $config
  */
 protected function checkFileInternal(CheckContext $checkContext, Config $config)
 {
     $file = $checkContext->getFile();
     $lines = $file->getLines();
     $severityError = Violation::SEVERITY_ERROR;
     $severityWarning = Violation::SEVERITY_WARNING;
     $severityInfo = Violation::SEVERITY_INFO;
     if (count($lines) > 0) {
         $this->setLimit($severityError, $config->get('error_limit', $this->limits[$severityError]));
         $this->setLimit($severityWarning, $config->get('warning_limit', $this->limits[$severityWarning]));
         $this->setLimit($severityInfo, $config->get('info_limit', $this->limits[$severityInfo]));
         $this->setTabExpand($config->get('tab_expand', $this->tabExpand));
         foreach ($lines as $line => $data) {
             $lineLength = iconv_strlen(str_replace("\t", str_repeat(' ', $this->tabExpand), rtrim($data, "\r\n")), $file->getEncoding());
             $severity = null;
             foreach (Violation::getSeverities() as $severity) {
                 if (!isset($this->limits[$severity]) || $this->limits[$severity] === null) {
                     continue;
                 }
                 if ($lineLength <= $this->limits[$severity]) {
                     continue;
                 }
                 $this->addViolation($file, $line, 0, sprintf('Line is too long. [%d/%d]', $lineLength, $this->limits[$severity]), $severity);
             }
         }
     }
 }