Skip to content
Permalink
Browse files

Allow help to also display 0 as short type and fix some cloaking nons…

…trict checks.
  • Loading branch information...
dereuromark committed Oct 24, 2016
1 parent f3d5e5e commit ab684b661f8583c398294a3c780a0ff5673ccb92
@@ -99,14 +99,6 @@ class Cache
*/
protected static $_groups = [];
/**
* Whether to reset the settings with the next call to Cache::set();
*
* @deprecated Not used anymore
* @var bool
*/
protected static $_reset = false;
/**
* Cache Registry used for creating and using cache adapters.
*
@@ -127,7 +119,7 @@ public static function registry(ObjectRegistry $registry = null)
static::$_registry = $registry;
}
if (empty(static::$_registry)) {
if (!static::$_registry) {
static::$_registry = new CacheRegistry();
}
@@ -245,12 +245,12 @@ public function groups()
*/
public function key($key)
{
if (empty($key)) {
if (!$key) {
return false;
}
$prefix = '';
if (!empty($this->_groupPrefix)) {
if ($this->_groupPrefix) {
$prefix = vsprintf($this->_groupPrefix, $this->groups());
}
@@ -98,7 +98,7 @@ public function init(array $config = [])
if (substr($this->_config['path'], -1) !== DIRECTORY_SEPARATOR) {
$this->_config['path'] .= DIRECTORY_SEPARATOR;
}
if (!empty($this->_groupPrefix)) {
if ($this->_groupPrefix) {
$this->_groupPrefix = str_replace('_', DIRECTORY_SEPARATOR, $this->_groupPrefix);
}
@@ -377,7 +377,7 @@ public function increment($key, $offset = 1)
protected function _setKey($key, $createKey = false)
{
$groups = null;
if (!empty($this->_groupPrefix)) {
if ($this->_groupPrefix) {
$groups = vsprintf($this->_groupPrefix, $this->groups());
}
$dir = $this->_config['path'] . $groups;
@@ -113,7 +113,7 @@ public function help($width = 0)
if (!$this->isRequired()) {
$optional = ' <comment>(optional)</comment>';
}
if (!empty($this->_choices)) {
if ($this->_choices) {
$optional .= sprintf(' <comment>(choices: %s)</comment>', implode('|', $this->_choices));
}
@@ -128,7 +128,7 @@ public function help($width = 0)
public function usage()
{
$name = $this->_name;
if (!empty($this->_choices)) {
if ($this->_choices) {
$name = implode('|', $this->_choices);
}
$name = '<' . $name . '>';
@@ -129,13 +129,13 @@ public function short()
public function help($width = 0)
{
$default = $short = '';
if (!empty($this->_default) && $this->_default !== true) {
if ($this->_default && $this->_default !== true) {
$default = sprintf(' <comment>(default: %s)</comment>', $this->_default);
}
if (!empty($this->_choices)) {
if ($this->_choices) {
$default .= sprintf(' <comment>(choices: %s)</comment>', implode('|', $this->_choices));
}
if (!empty($this->_short)) {
if (strlen($this->_short) > 0) {
$short = ', -' . $this->_short;
}
$name = sprintf('--%s%s', $this->_name, $short);
@@ -158,7 +158,7 @@ public function usage()
if (strlen($this->_default) > 0 && $this->_default !== true) {
$default = ' ' . $this->_default;
}
if (!empty($this->_choices)) {
if ($this->_choices) {
$default = ' ' . implode('|', $this->_choices);
}
@@ -123,7 +123,7 @@ public function __construct(ComponentRegistry $registry, array $config = [])
$this->config($config);
if (!empty($this->components)) {
if ($this->components) {
$this->_componentMap = $registry->normalizeArray($this->components);
}
$this->initialize($config);
@@ -57,15 +57,15 @@ class RequestHandlerComponent extends Component
/**
* Contains the file extension parsed out by the Router
*
* @var string
* @var string|null
* @see \Cake\Routing\Router::extensions()
*/
public $ext = null;
/**
* The template to use when rendering the given content type.
*
* @var string
* @var string|null
*/
protected $_renderType = null;
@@ -177,7 +177,7 @@ protected function _setExtension($request, $response)
);
foreach ($accepts as $types) {
$ext = array_intersect($extensions, $types);
if (!empty($ext)) {
if ($ext) {
$this->ext = current($ext);
break;
}
@@ -202,13 +202,13 @@ public function startup(Event $event)
if ($request->param('_ext')) {
$this->ext = $request->param('_ext');
}
if (empty($this->ext) || in_array($this->ext, ['html', 'htm'])) {
if (!$this->ext || in_array($this->ext, ['html', 'htm'])) {
$this->_setExtension($request, $this->response);
}
$request->params['isAjax'] = $request->is('ajax');
if (empty($this->ext) && $request->is('ajax')) {
if (!$this->ext && $request->is('ajax')) {
$this->ext = 'ajax';
}
@@ -323,7 +323,7 @@ public function beforeRender(Event $event)
$this->response->getMimeType($this->ext)
);
if (!empty($this->ext) && $isRecognized) {
if ($this->ext && $isRecognized) {
$this->renderAs($event->subject(), $this->ext);
} else {
$this->response->charset(Configure::read('App.encoding'));
@@ -517,15 +517,15 @@ public function prefers($type = null)
$types = (array)$type;
if (count($types) === 1) {
if (!empty($this->ext)) {
if ($this->ext) {
return in_array($this->ext, $types);
}
return in_array($types[0], $accepts);
}
$intersect = array_values(array_intersect($accepts, $types));
if (empty($intersect)) {
if (!$intersect) {
return false;
}
@@ -582,7 +582,7 @@ public function renderAs(Controller $controller, $type, array $options = [])
$controller->viewClass = $viewClass;
$builder->className($viewClass);
} else {
if (empty($this->_renderType)) {
if (!$this->_renderType) {
$builder->templatePath($builder->templatePath() . DIRECTORY_SEPARATOR . $type);
} else {
$builder->templatePath(preg_replace(
@@ -66,7 +66,7 @@ class IniConfig implements ConfigEngineInterface
/**
* The section to read, if null all sections will be read.
*
* @var string
* @var string|null
*/
protected $_section;
@@ -101,7 +101,7 @@ public function read($key)
$file = $this->_getFilePath($key, true);
$contents = parse_ini_file($file, true);
if (!empty($this->_section) && isset($contents[$this->_section])) {
if ($this->_section && isset($contents[$this->_section])) {
$values = $this->_parseNestedValues($contents[$this->_section]);
} else {
$values = [];
@@ -56,21 +56,21 @@ class FileLog extends BaseLog
/**
* Path to save log files on.
*
* @var string
* @var string|null
*/
protected $_path = null;
/**
* The name of the file to save logs into.
*
* @var string
* @var string|null
*/
protected $_file = null;
/**
* Max file size, used for log file rotation.
*
* @var int
* @var int|null
*/
protected $_size = null;
@@ -123,13 +123,13 @@ public function log($level, $message, array $context = [])
$message = $this->_format($message, $context);
$output = date('Y-m-d H:i:s') . ' ' . ucfirst($level) . ': ' . $message . "\n";
$filename = $this->_getFilename($level);
if (!empty($this->_size)) {
if ($this->_size) {
$this->_rotateFile($filename);
}
$pathname = $this->_path . $filename;
$mask = $this->_config['mask'];
if (empty($mask)) {
if (!$mask) {
return file_put_contents($pathname, $output, FILE_APPEND);
}
@@ -159,7 +159,7 @@ protected function _getFilename($level)
{
$debugTypes = ['notice', 'info', 'debug'];
if (!empty($this->_file)) {
if ($this->_file) {
$filename = $this->_file;
} elseif ($level === 'error' || $level === 'warning') {
$filename = 'error.log';
@@ -828,7 +828,7 @@ public function getHeaders(array $include = [])
}
$headers['MIME-Version'] = '1.0';
if (!empty($this->_attachments)) {
if ($this->_attachments) {
$headers['Content-Type'] = 'multipart/mixed; boundary="' . $this->_boundary . '"';
} elseif ($this->_emailFormat === 'both') {
$headers['Content-Type'] = 'multipart/alternative; boundary="' . $this->_boundary . '"';
@@ -1680,7 +1680,7 @@ protected function _wrap($message, $wrapLength = Email::LINE_LENGTH_MUST)
*/
protected function _createBoundary()
{
if (!empty($this->_attachments) || $this->_emailFormat === 'both') {
if ($this->_attachments || $this->_emailFormat === 'both') {
$this->_boundary = md5(Security::randomBytes(16));
}
}
@@ -98,7 +98,7 @@ public function setUp()
{
parent::setUp();
if (empty($this->_configure)) {
if (!$this->_configure) {
$this->_configure = Configure::read();
}
if (class_exists('Cake\Routing\Router', false)) {
@@ -116,7 +116,7 @@ public function setUp()
public function tearDown()
{
parent::tearDown();
if (!empty($this->_configure)) {
if ($this->_configure) {
Configure::clear();
Configure::write($this->_configure);
}
@@ -26,7 +26,7 @@ trait IdGeneratorTrait
/**
* Prefix for id attribute.
*
* @var string
* @var string|null
*/
protected $_idPrefix = null;
@@ -80,7 +80,7 @@ protected function _id($name, $val)
protected function _domId($value)
{
$domId = mb_strtolower(Inflector::slug($value, '-'));
if (!empty($this->_idPrefix)) {
if ($this->_idPrefix) {
$domId = $this->_idPrefix . '-' . $domId;
}
@@ -592,6 +592,7 @@ public function testHelpSubcommandHelp()
{
$subParser = new ConsoleOptionParser('method', false);
$subParser->addOption('connection', ['help' => 'Db connection.']);
$subParser->addOption('zero', ['short' => '0', 'help' => 'Zero.']);
$parser = new ConsoleOptionParser('mycommand', false);
$parser->addSubcommand('method', [
@@ -603,12 +604,13 @@ public function testHelpSubcommandHelp()
$result = $parser->help('method');
$expected = <<<TEXT
<info>Usage:</info>
cake mycommand method [--connection] [-h]
cake mycommand method [--connection] [-h] [-0]
<info>Options:</info>
--connection Db connection.
--help, -h Display this help.
--zero, -0 Zero.
TEXT;
$this->assertTextEquals($expected, $result, 'Help is not correct.');

0 comments on commit ab684b6

Please sign in to comment.
You can’t perform that action at this time.