| Conditions | 5 |
| Paths | 10 |
| Total Lines | 27 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 22 | public function processCommand() |
||
| 23 | { |
||
| 24 | $this->name = $this->getRoute()->getMatchedParam('name'); |
||
|
|
|||
| 25 | $this->force = $this->getRoute()->getMatchedParam('force', false); |
||
| 26 | |||
| 27 | try { |
||
| 28 | $fileContent = <<<EOT |
||
| 29 | --- |
||
| 30 | title: '%s' |
||
| 31 | date: '%s' |
||
| 32 | draft: true |
||
| 33 | --- |
||
| 34 | # New page |
||
| 35 | EOT; |
||
| 36 | $filePath = $this->getPath().'/'.$this->getPHPoole()->getConfig()->get('content.dir').'/'.$this->name.'.md'; |
||
| 37 | |||
| 38 | if ($this->fs->exists($filePath) && !$this->force) { |
||
| 39 | if (!Confirm::prompt('This page already exists. Do you want to override it? [y/n]', 'y', 'n')) { |
||
| 40 | exit(0); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | $this->fs->dumpFile($filePath, sprintf($fileContent, $this->name, date('Y-m-d'))); |
||
| 44 | $this->wlDone('Done!'); |
||
| 45 | } catch (\Exception $e) { |
||
| 46 | throw new \Exception(sprintf($e->getMessage())); |
||
| 47 | } |
||
| 48 | } |
||
| 49 | } |
||
| 50 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: