コード例 #1
0
ファイル: FormatJob.php プロジェクト: nochso/phormat
 public function run()
 {
     $this->progressStatusMap = array_fill_keys(array_keys(FormatJobFile::STATUS_STYLES), 0);
     $startTime = microtime(true);
     $formatter = new Formatter();
     $formatter->setOrderClassElements($this->order);
     foreach ($this->files as $key => $file) {
         if ($file->getStatus() === FormatJobFile::STATUS_MISSING) {
             continue;
         }
         try {
             $before = file_get_contents($file->getPath());
             $after = $formatter->format($before);
             $file->setSources($before, $after, $this->print);
             if ($this->diff) {
                 $file->setDiff($before, $after);
             }
             if ($this->output && !$this->diff && !$this->print) {
                 file_put_contents($file->getPath(), $after);
             }
         } catch (TemplateSkippedException $e) {
             $file->setSkipped();
         } catch (\Exception $e) {
             $file->setError($e->getMessage());
         }
         $this->showProgress($key, $file);
     }
     $duration = microtime(true) - $startTime;
     $this->stdio->out("\r" . str_repeat(' ', 80) . "\r");
     $this->showDiffs();
     $this->showOutput();
     $this->showFileSummary();
     $this->showSummary($duration);
 }
コード例 #2
0
ファイル: FormatterTest.php プロジェクト: nochso/phormat
 /**
  * @dataProvider orderClassElementsProvider
  */
 public function testOrderClassElements_OutputMustNotChange($expectedSource, $inputSource)
 {
     $formatter = new Formatter();
     $this->assertSame($expectedSource, $formatter->format($expectedSource));
 }