Exemplo n.º 1
0
 /**
  * Perform the requested changes
  */
 public function run()
 {
     $sniffer = $this->_sniffer;
     // If we need to, make a read-only pass to populate our type information
     if ($this->_firstPassRequired) {
         foreach ($this->getFirstPassListeners() as $listener) {
             $sniffer->addListener($listener);
         }
         $sniffer->process($this->files, false, true);
     }
     // Now call any callbacks registered to run after the first pass
     foreach ($this->_firstPassCallbacks as $cbArray) {
         $callback = $cbArray[0];
         $args = $cbArray[1];
         call_user_func_array($callback, $args);
     }
     // Clear out the first pass listeners before we run the second pass
     $sniffer->clearListeners();
     foreach ($this->_listeners as $listener) {
         $sniffer->addListener($listener);
     }
     // Run the sniffer
     $sniffer->process($this->files);
     // Get the changes that have been registered
     $changes = $this->_changeRegistry->get('storedChanges');
     if (!is_array($changes)) {
         $changes = array();
     }
     // Now make the actual changes
     $filesChanged = 0;
     $totalWarnings = 0;
     $warnings = array();
     foreach ($changes as $file) {
         $changed = $file->process($this->_mode);
         $filesChanged += $changed ? 1 : 0;
         $numWarnings = $file->getNumChangesNotProcessed();
         if ($numWarnings > 0) {
             $totalWarnings += $numWarnings;
             $warnings[$file->filename] = $file->getLinesNotProcessed();
         }
     }
     // Display a summary line
     $msg = "Changed {$filesChanged} files";
     $this->sendOutput($msg);
     // If we have any notifications, display them
     if ($totalWarnings > 0) {
         // Display a summary
         $numFiles = count($warnings);
         $msg = "Found {$totalWarnings} possible changes in {$numFiles} files that were not applied:";
         $this->sendOutput($msg);
         // Now display each line where we found changes
         foreach ($warnings as $filename => $lines) {
             foreach ($lines as $lineNo) {
                 $this->sendOutput("{$filename}:{$lineNo}");
             }
         }
     }
 }
Exemplo n.º 2
0
 public function testRenameFileAltersIncludesSwitchPlaces()
 {
     $this->populateDir(dirname(__FILE__) . '/_files/renameFileIncludesFixture', $this->test_dir);
     chdir($this->test_dir);
     $this->doRenameFile('otherfolder/stuff.php', 'stuff.php');
     // This is kinda hacky, but we need to clear out the static data since we're not creating a second process
     Scisr_ChangeRegistry::clearAll();
     $this->doRenameFile('test.php', 'otherfolder/test.php');
     $this->compareDir(dirname(__FILE__) . '/_files/renameFileIncludesFixture-after-rename-3', $this->test_dir);
 }
Exemplo n.º 3
0
 public function tearDown()
 {
     Scisr_ChangeRegistry::clearAll();
     chdir(dirname(__FILE__));
 }