Exemple #1
0
 /**
  * Main worker
  *
  * @return void
  */
 public function main()
 {
     if (empty($this->args)) {
         $this->error("Require at least one file path");
         die;
     }
     foreach ($this->args as $input) {
         $path = $this->getPath($input);
         if (empty($path)) {
             $this->error("Unable to find {$input}");
             die;
         }
         if (is_file($path)) {
             $files = array($path);
         }
         if (is_dir($path)) {
             $dir = new Folder($path);
             $files = $dir->findRecursive('.*\\.php$');
         }
         if (empty($files)) {
             $this->error("Invalid file type {$path}");
             die;
         }
         foreach ($files as $file) {
             $this->out($file);
             PhpTidy::file($file);
         }
     }
 }
Exemple #2
0
 /**
  *
  */
 public function testPhpTidyFile_good_single()
 {
     // pass in a filename of PHP code to tidy up
     $noTrailingLine = '<?php /* basic */ ?>';
     $path = TMP . 'test-phptidytest-1.php';
     file_put_contents($path, $noTrailingLine);
     $output = PhpTidy::file($path);
     $this->assertFalse(empty($output));
     //$this->assertEquals('Replaced 1 files.', $output);
     $result = file_get_contents($path);
     $expect = "<?php /* basic */ ?>\n";
     $this->assertEquals($expect, $result);
 }
Exemple #3
0
 /**
  * Tidy up source code as a file
  * - executes the phptidy.php script via php CLI functionality
  *
  * @param string $path to file
  * @return void;
  * @throws OutOfBoundsException
  */
 public static function file($path)
 {
     if (is_array($path)) {
         foreach ($path as $_path) {
             PhpTidy::file($_path);
         }
         return;
     }
     if (!is_file($path)) {
         throw new OutOfBoundsException('PhpTidy::file() unable to find file (should be a full path) ' . $path);
     }
     $phpexe = exec('which php');
     if (empty($phpexe)) {
         $phpexe = 'php';
     }
     $cmd = sprintf('%s %s replace %s', $phpexe, escapeshellarg(PhpTidy::script()), escapeshellarg($path));
     return exec($cmd);
 }
 /**
  * Read in a fixture file and update it
  * - force it to use Icing.AppFastFixture
  * - update the $fields to always match what's on the current database
  * - run Icing.PhpTidy against it
  *
  * @param string $path
  * @return boolean
  */
 public function processFixture($path)
 {
     //Skip fixture update if we don't have a table definaiton, custom dbconfig
     if ($this->getUseTable($path) === false) {
         return true;
     }
     // cleanup the basics
     $appUses = "App::uses('AppFastFixture', 'Icing.Lib');";
     $body = file_get_contents($path);
     // replace old approaches
     $body = preg_replace('#App::[^\\)]*AppFastFixture[^\\)]*\\);#', $appUses, $body);
     // inject App::uses()
     if (strpos($body, $appUses) === false) {
         $body = preg_replace('#(class .* extends )#', $appUses . "\n\$1", $body);
     }
     // replace CakeTestFixture
     $body = str_replace('CakeTestFixture', 'AppFastFixture', $body);
     // remove closing php
     $body = str_replace('?>', '', $body);
     // TODO: replace the $fields array with details from the "current" schema
     try {
         $body = $this->processFixtureFields($path, $body);
     } catch (Exception $e) {
         $this->error('processFixtureFields Exception: ' . $e->getMessage());
     }
     // cleanup up formatting
     App::uses('PhpTidy', 'Icing.Lib');
     $body = PhpTidy::string($body);
     // write out the file
     if (!file_put_contents($path, $body)) {
         $this->error('Unable to write to ' . $path);
     }
     return true;
 }