Пример #1
0
 /**
  * Print the results from the tests
  */
 private function printResults()
 {
     // Write a empty line
     $this->output->writeLn('');
     $found_msg = ' ';
     $found_msg .= 'Fatal: ' . $this->output->getMessageCount(Output::FATAL);
     $found_msg .= ', Error: ' . $this->output->getMessageCount(Output::ERROR);
     $found_msg .= ', Warning: ' . $this->output->getMessageCount(Output::WARNING);
     $found_msg .= ', Notice: ' . $this->output->getMessageCount(Output::NOTICE);
     $found_msg .= ' ';
     if ($this->output->getMessageCount(Output::FATAL) > 0 || $this->output->getMessageCount(Output::ERROR) > 0 || $this->output->getMessageCount(Output::WARNING) > 0) {
         $this->output->writeln('<fatal>' . str_repeat(' ', strlen($found_msg)) . '</fatal>');
         $this->output->writeln('<fatal> Validation: FAILED' . str_repeat(' ', strlen($found_msg) - 19) . '</fatal>');
         $this->output->writeln('<fatal>' . $found_msg . '</fatal>');
         $this->output->writeln('<fatal>' . str_repeat(' ', strlen($found_msg)) . '</fatal>');
         $this->output->writeln('');
     } else {
         $this->output->writeln('<success>PASSED: ' . $found_msg . '</success>');
     }
     // Write debug messages.
     if ($this->debug) {
         foreach ($this->output->getDebugMessages() as $msg) {
             $this->output->writeln((string) $msg);
         }
     }
     $this->output->writeln("<info>Test results for extension:</info>");
     foreach ($this->output->getMessages() as $msg) {
         $this->output->writeln((string) $msg);
     }
     if (sizeof($this->output->getMessages()) == 0) {
         $this->output->writeln("<success>No issues found </success>");
     }
 }
Пример #2
0
 /**
  * Find the name of the event inside the dispatch() line
  *
  * @param int  $event_line
  * @param bool $is_dispatch Do we look for dispatch() or trigger_event() ?
  *
  * @return string    Name of the event
  * @throws \LogicException
  */
 public function get_event_name($event_line, $is_dispatch)
 {
     $event_text_line = $this->file_lines[$event_line];
     $event_text_line = ltrim($event_text_line, " \t");
     if ($is_dispatch) {
         $regex = '#\\$([a-z](?:[a-z0-9_]|->)*)';
         $regex .= '->dispatch\\(';
         $regex .= '\'%s\'';
         $regex .= '\\);#';
     } else {
         $regex = '#extract\\(\\$([a-z](?:[a-z0-9_]|->)*)';
         $regex .= '->trigger_event\\(';
         $regex .= '\'%s\'';
         $regex .= ', compact\\(\\$vars\\)\\)\\);#';
     }
     $match = array();
     preg_match(sprintf($regex, $this->preg_match_event_name()), $event_text_line, $match);
     if (!isset($match[2])) {
         $match = array();
         preg_match(sprintf($regex, $this->preg_match_event_name_uppercase()), $event_text_line, $match);
         if (isset($match[2])) {
             $this->output->addMessage(Output::ERROR, sprintf('Event names should be all lowercase in %s for event %s', $this->current_clean_file, $match[2]));
         } else {
             throw new \LogicException("Can not find event name in line '{$event_text_line}' " . "in file '{$this->current_clean_file}:{$event_line}'", 1);
         }
     }
     return $match[2];
 }
Пример #3
0
 /**
  * Attempts to load a file based on extension.
  *
  * In case of plaintext files, contents are also checked to see if it isn't a php file.
  *
  * @param $fileName
  * @param $extension
  *
  * @return BinaryFile|ComposerFile|CssFile|HTMLFile|JavascriptFile|JsonFile|PHPFile|PlainFile|XmlFile|YmlFile|ImageFile|null
  */
 private function tryLoadFile($fileName, $extension)
 {
     $this->output->writelnIfDebug("<info>Attempting to load {$fileName} with extension {$extension}</info>");
     $this->loadError = false;
     switch (strtolower($extension)) {
         case 'php':
             // First, check if this file is a lang file.
             $file = basename($fileName);
             $dir = str_replace($file, '', $fileName);
             $dir = str_replace($this->basedir, '', $fileName);
             $dir = explode('/', $dir);
             if (trim(strtolower($dir[0])) == 'language') {
                 return new LangFile($this->debug, $fileName, $this->rundir);
             }
             return new PHPFile($this->debug, $fileName, $this->rundir);
         case 'html':
         case 'htm':
             return new HTMLFile($this->debug, $fileName, $this->rundir);
         case 'json':
             if (strtolower(basename($fileName)) == 'composer.json') {
                 return new ComposerFile($this->debug, $fileName, $this->rundir);
             } else {
                 return new JsonFile($this->debug, $fileName, $this->rundir);
             }
         case 'yml':
             if (strtolower(basename($fileName)) == 'services.yml') {
                 return new ServiceFile($this->debug, $fileName, $this->rundir);
             }
             if (strtolower(basename($fileName)) == 'routing.yml') {
                 return new RoutingFile($this->debug, $fileName, $this->rundir);
             }
             return new YmlFile($this->debug, $fileName, $this->rundir);
         case 'txt':
         case 'md':
         case 'htaccess':
         case 'gitattributes':
         case 'gitignore':
         case 'map':
         case 'sh':
             // Decide if we want a special file type for shell files!
             return new PlainFile($this->debug, $fileName, $this->rundir);
         case 'xml':
             return new XmlFile($this->debug, $fileName, $this->rundir);
         case 'js':
             return new JavascriptFile($this->debug, $fileName, $this->rundir);
         case 'css':
             return new CssFile($this->debug, $fileName, $this->rundir);
         case 'gif':
         case 'png':
         case 'jpg':
         case 'jpeg':
         case 'svg':
             return new ImageFile($this->debug, $fileName, $this->rundir);
         case 'swf':
             $this->output->addMessage(Output::NOTICE, sprintf("Found an SWF file (%s), please make sure to include the source files for it, as required by the GPL.", basename($fileName)));
             return new BinaryFile($this->debug, $fileName, $this->rundir);
         case 'ds_store':
             $this->output->addMessage(Output::ERROR, sprintf("Found an OS X specific file at %s, please make sure to remove it prior to submission.", $fileName));
             return new BinaryFile($this->debug, $fileName, $this->rundir);
         case 'lock':
             return new LockFile($this->debug, $fileName, $this->rundir);
         default:
             $file = basename($fileName);
             $this->output->addMessage(Output::WARNING, "Can't detect the file type for {$file}, handling it as a binary file.");
             return new BinaryFile($this->debug, $fileName, $this->rundir);
     }
 }