| Conditions | 6 |
| Paths | 32 |
| Total Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 33 | public function processCommand() |
||
| 34 | { |
||
| 35 | $this->open = $this->getRoute()->getMatchedParam('open', false); |
||
| 36 | |||
| 37 | $this->setUpServer(); |
||
| 38 | $command = sprintf( |
||
| 39 | 'php -S %s:%d -t %s %s', |
||
| 40 | 'localhost', |
||
| 41 | '8000', |
||
| 42 | $this->getPath().'/'.$this->getPHPoole()->getConfig()->get('output.dir'), |
||
| 43 | sprintf('%s/%s/router.php', $this->getPath(), self::$tmpDir) |
||
| 44 | ); |
||
| 45 | $process = new Process($command); |
||
| 46 | |||
| 47 | // (re)build before serve |
||
| 48 | $callable = new Build(); |
||
| 49 | $callable($this->getRoute(), $this->getConsole()); |
||
| 50 | |||
| 51 | // handle process |
||
| 52 | if (!$process->isStarted()) { |
||
| 53 | // write changes cache |
||
| 54 | $finder = new Finder(); |
||
| 55 | $finder->files() |
||
| 56 | ->name('*.md') |
||
| 57 | ->name('*.twig') |
||
| 58 | ->name('*.yml') |
||
| 59 | ->name('*.css') |
||
| 60 | ->name('*.scss') |
||
| 61 | ->name('*.js') |
||
| 62 | ->in($this->getPath()) |
||
| 63 | ->exclude($this->getPHPoole()->getConfig()->get('output.dir')); |
||
| 64 | $hashContent = new Crc32ContentHash(); |
||
| 65 | $resourceCache = new ResourceCacheMemory(); |
||
| 66 | $resourceWatcher = new ResourceWatcher($resourceCache, $finder, $hashContent); |
||
| 67 | $resourceWatcher->initialize(); |
||
| 68 | // start server |
||
| 69 | try { |
||
| 70 | $this->wlAnnonce(sprintf('Starting server (http://%s:%d)...', 'localhost', '8000')); |
||
| 71 | $process->start(); |
||
| 72 | if ($this->open) { |
||
| 73 | Plateform::openBrowser('http://localhost:8000'); |
||
| 74 | } |
||
| 75 | while ($process->isRunning()) { |
||
| 76 | $result = $resourceWatcher->findChanges(); |
||
| 77 | if ($result->hasChanges()) { |
||
| 78 | // re-build |
||
| 79 | $this->wlAlert('Changes detected!'); |
||
| 80 | $callable($this->getRoute(), $this->getConsole()); |
||
| 81 | } |
||
| 82 | usleep(1000000); // wait 1s |
||
| 83 | } |
||
| 84 | } catch (ProcessFailedException $e) { |
||
| 85 | $this->tearDownServer(); |
||
| 86 | |||
| 87 | throw new \Exception(sprintf($e->getMessage())); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 122 |