for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of the PHPoole package.
*
* Copyright (c) Arnaud Ligny <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPoole\Command;
use Zend\Console\Prompt\Confirm;
class NewPage extends AbstractCommand
{
/**
* @var bool
protected $force;
public function processCommand()
$this->name = $this->getRoute()->getMatchedParam('name');
name
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$this->force = $this->getRoute()->getMatchedParam('force', false);
try {
$fileContent = <<<EOT
---
title: '%s'
date: '%s'
draft: true
# New page
EOT;
$filePath = $this->getPath().'/'.$this->getPHPoole()->getConfig()->get('content.dir').'/'.$this->name.'.md';
if ($this->fs->exists($filePath) && !$this->force) {
if (!Confirm::prompt('This page already exists. Do you want to override it? [y/n]', 'y', 'n')) {
exit(0);
}
$this->fs->dumpFile($filePath, sprintf($fileContent, $this->name, date('Y-m-d')));
$this->wlDone('Done!');
} catch (\Exception $e) {
throw new \Exception(sprintf($e->getMessage()));
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: