Consolidate with conditions sniff.

This commit is contained in:
euromark 2014-12-09 03:17:35 +01:00
parent 11981f80fa
commit e1c128bb99
25 changed files with 41 additions and 83 deletions

View file

@ -334,8 +334,7 @@ class SchemaShell extends AppShell {
$this->out("\n" . __d('cake_console', 'The following table(s) will be dropped.'));
$this->out(array_keys($drop));
if (
!empty($this->params['yes']) ||
if (!empty($this->params['yes']) ||
$this->in(__d('cake_console', 'Are you sure you want to drop the table(s)?'), array('y', 'n'), 'n') === 'y'
) {
$this->out(__d('cake_console', 'Dropping table(s).'));
@ -345,8 +344,7 @@ class SchemaShell extends AppShell {
$this->out("\n" . __d('cake_console', 'The following table(s) will be created.'));
$this->out(array_keys($create));
if (
!empty($this->params['yes']) ||
if (!empty($this->params['yes']) ||
$this->in(__d('cake_console', 'Are you sure you want to create the table(s)?'), array('y', 'n'), 'y') === 'y'
) {
$this->out(__d('cake_console', 'Creating table(s).'));
@ -399,8 +397,7 @@ class SchemaShell extends AppShell {
$this->out("\n" . __d('cake_console', 'The following statements will run.'));
$this->out(array_map('trim', $contents));
if (
!empty($this->params['yes']) ||
if (!empty($this->params['yes']) ||
$this->in(__d('cake_console', 'Are you sure you want to alter the tables?'), array('y', 'n'), 'n') === 'y'
) {
$this->out();

View file

@ -510,8 +510,7 @@ class ConsoleOptionParser {
* @return string Generated help.
*/
public function help($subcommand = null, $format = 'text', $width = 72) {
if (
isset($this->_subcommands[$subcommand]) &&
if (isset($this->_subcommands[$subcommand]) &&
$this->_subcommands[$subcommand]->parser() instanceof self
) {
$subparser = $this->_subcommands[$subcommand]->parser();

View file

@ -161,8 +161,7 @@ class ConsoleOutput {
public function __construct($stream = 'php://stdout') {
$this->_output = fopen($stream, 'w');
if (
(DS === '\\' && !(bool)env('ANSICON')) ||
if ((DS === '\\' && !(bool)env('ANSICON')) ||
(function_exists('posix_isatty') && !posix_isatty($this->_output))
) {
$this->_outputAs = self::PLAIN;

View file

@ -240,8 +240,7 @@ class PaginatorComponent extends Component {
throw new NotFoundException();
}
if (
!in_array('Paginator', $this->Controller->helpers) &&
if (!in_array('Paginator', $this->Controller->helpers) &&
!array_key_exists('Paginator', $this->Controller->helpers)
) {
$this->Controller->helpers[] = 'Paginator';

View file

@ -415,8 +415,7 @@ class SecurityComponent extends Component {
if ($this->Session->check('_Token')) {
$tData = $this->Session->read('_Token');
if (
!empty($tData['allowedControllers']) &&
if (!empty($tData['allowedControllers']) &&
!in_array($this->request->params['controller'], $tData['allowedControllers']) ||
!empty($tData['allowedActions']) &&
!in_array($this->request->params['action'], $tData['allowedActions'])

View file

@ -197,8 +197,7 @@ class Object {
protected function _mergeVars($properties, $class, $normalize = true) {
$classProperties = get_class_vars($class);
foreach ($properties as $var) {
if (
isset($classProperties[$var]) &&
if (isset($classProperties[$var]) &&
!empty($classProperties[$var]) &&
is_array($this->{$var}) &&
$this->{$var} != $classProperties[$var]

View file

@ -48,8 +48,7 @@ class ConsoleLog extends BaseLog {
*/
public function __construct($config = array()) {
parent::__construct($config);
if (
(DS === '\\' && !(bool)env('ANSICON')) ||
if ((DS === '\\' && !(bool)env('ANSICON')) ||
(function_exists('posix_isatty') && !posix_isatty($this->_output))
) {
$outputAs = ConsoleOutput::PLAIN;

View file

@ -116,8 +116,7 @@ class AclNode extends Model {
$result = $db->read($this, $queryData, -1);
$path = array_values($path);
if (
!isset($result[0][$type]) ||
if (!isset($result[0][$type]) ||
(!empty($path) && $result[0][$type]['alias'] != $path[count($path) - 1]) ||
(empty($path) && $result[0][$type]['alias'] != $start)
) {

View file

@ -157,8 +157,7 @@ class TranslateBehavior extends ModelBehavior {
);
foreach ($fields as $key => $value) {
$field = (is_numeric($key)) ? $value : $key;
if (
$isAllFields ||
if ($isAllFields ||
in_array($Model->alias . '.' . $field, $query['fields']) ||
in_array($field, $query['fields'])
) {

View file

@ -834,9 +834,7 @@ class DboSource extends DataSource {
$matches[1] . '(' . $this->name($matches[2]) . ')'
);
}
if (
preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/i', $data, $matches
)) {
if (preg_match('/^([\w-]+(\.[\w-]+|\(.*\))*)\s+' . preg_quote($this->alias) . '\s*([\w-]+)$/i', $data, $matches)) {
return $this->cacheMethod(
__FUNCTION__, $cacheKey,
preg_replace(
@ -1313,8 +1311,7 @@ class DboSource extends DataSource {
$assocResultSet = array();
$prefetched = false;
if (
($type === 'hasOne' || $type === 'belongsTo') &&
if (($type === 'hasOne' || $type === 'belongsTo') &&
isset($row[$LinkModel->alias], $joined[$Model->alias]) &&
in_array($LinkModel->alias, $joined[$Model->alias])
) {
@ -1337,8 +1334,7 @@ class DboSource extends DataSource {
foreach ($LinkModel->{$type1} as $assoc1 => $assocData1) {
$DeepModel = $LinkModel->{$assoc1};
if (
$type1 === 'belongsTo' ||
if ($type1 === 'belongsTo' ||
($type === 'belongsTo' && $DeepModel->alias === $modelAlias) ||
($DeepModel->alias !== $modelAlias)
) {
@ -1589,8 +1585,7 @@ class DboSource extends DataSource {
$assocFields = $this->fields($Model, null, "{$Model->alias}.{$Model->primaryKey}");
$passedFields = $queryData['fields'];
if (
count($passedFields) > 1 ||
if (count($passedFields) > 1 ||
(strpos($passedFields[0], $assocFields[0]) === false && !preg_match('/^[a-z]+\(/i', $passedFields[0]))
) {
$queryData['fields'] = array_merge($passedFields, $assocFields);

View file

@ -1293,8 +1293,7 @@ class Model extends Object implements CakeEventListener {
return null;
}
if (
isset($data['hour']) &&
if (isset($data['hour']) &&
isset($data['meridian']) &&
!empty($data['hour']) &&
$data['hour'] != 12 &&

View file

@ -162,8 +162,7 @@ class CakeRequest implements ArrayAccess {
protected function _processPost() {
if ($_POST) {
$this->data = $_POST;
} elseif (
($this->is('put') || $this->is('delete')) &&
} elseif (($this->is('put') || $this->is('delete')) &&
strpos(env('CONTENT_TYPE'), 'application/x-www-form-urlencoded') === 0
) {
$data = $this->_readInput();
@ -261,8 +260,7 @@ class CakeRequest implements ArrayAccess {
}
$endsWithIndex = '/webroot/index.php';
$endsWithLength = strlen($endsWithIndex);
if (
strlen($uri) >= $endsWithLength &&
if (strlen($uri) >= $endsWithLength &&
substr($uri, -$endsWithLength) === $endsWithIndex
) {
$uri = '/';

View file

@ -464,8 +464,7 @@ class CakeResponse {
);
$charset = false;
if (
$this->_charset &&
if ($this->_charset &&
(strpos($this->_contentType, 'text/') === 0 || in_array($this->_contentType, $whitelist))
) {
$charset = true;

View file

@ -1481,8 +1481,7 @@ class CakeEmail {
$msg[] = '--' . $boundary;
$msg[] = 'Content-Type: ' . $fileInfo['mimetype'];
$msg[] = 'Content-Transfer-Encoding: base64';
if (
!isset($fileInfo['contentDisposition']) ||
if (!isset($fileInfo['contentDisposition']) ||
$fileInfo['contentDisposition']
) {
$msg[] = 'Content-Disposition: attachment; filename="' . $filename . '"';

View file

@ -311,8 +311,7 @@ class HttpSocket extends CakeSocket {
if (isset($this->request['uri']['port'])) {
$port = $this->request['uri']['port'];
}
if (
($scheme === 'http' && $port != 80) ||
if (($scheme === 'http' && $port != 80) ||
($scheme === 'https' && $port != 443) ||
($port != 80 && $port != 443)
) {

View file

@ -448,8 +448,7 @@ class CakeRoute {
}
// pull out named params if named params are greedy or a rule exists.
if (
($greedyNamed || isset($allowedNamedParams[$key])) &&
if (($greedyNamed || isset($allowedNamedParams[$key])) &&
($value !== false && $value !== null) &&
(!in_array($key, $prefixes))
) {

View file

@ -227,8 +227,7 @@ class Router {
* @throws RouterException
*/
protected static function _validateRouteClass($routeClass) {
if (
$routeClass !== 'CakeRoute' &&
if ($routeClass !== 'CakeRoute' &&
(!class_exists($routeClass) || !is_subclass_of($routeClass, 'CakeRoute'))
) {
throw new RouterException(__d('cake_dev', 'Route class not found, or route class is not a subclass of CakeRoute'));

View file

@ -139,8 +139,7 @@ class ConsoleLogTest extends CakeTestCase {
TestCakeLog::config('test_console_log', array(
'engine' => 'TestConsole',
));
if (
(DS === '\\' && !(bool)env('ANSICON')) ||
if ((DS === '\\' && !(bool)env('ANSICON')) ||
(function_exists('posix_isatty') && !posix_isatty(null))
) {
$expected = ConsoleOutput::PLAIN;

View file

@ -81,8 +81,7 @@ class FileTest extends CakeTestCase {
'filesize' => filesize($file),
'mime' => 'text/plain'
);
if (
!function_exists('finfo_open') &&
if (!function_exists('finfo_open') &&
(!function_exists('mime_content_type') ||
function_exists('mime_content_type') &&
mime_content_type($this->File->pwd()) === false)

View file

@ -296,8 +296,7 @@ class CakeTestFixture {
$nested = $db->useNestedTransactions;
$db->useNestedTransactions = false;
$result = $db->insertMulti($this->table, $fields, $values);
if (
$this->primaryKey &&
if ($this->primaryKey &&
isset($this->fields[$this->primaryKey]['type']) &&
in_array($this->fields[$this->primaryKey]['type'], array('integer', 'biginteger'))
) {

View file

@ -322,8 +322,7 @@ class CakeTime {
if (is_int($dateString) || is_numeric($dateString)) {
$date = (int)$dateString;
} elseif (
$dateString instanceof DateTime &&
} elseif ($dateString instanceof DateTime &&
$dateString->getTimezone()->getName() != date_default_timezone_get()
) {
$clone = clone $dateString;

View file

@ -220,8 +220,7 @@ class Hash {
if (!preg_match($val, $prop)) {
return false;
}
} elseif (
($op === '=' && $prop != $val) ||
} elseif (($op === '=' && $prop != $val) ||
($op === '!=' && $prop == $val) ||
($op === '>' && $prop <= $val) ||
($op === '<' && $prop >= $val) ||

View file

@ -129,8 +129,7 @@ abstract class ObjectCollection {
if ($options['collectReturn'] === true) {
$collected[] = $result;
}
if (
$options['break'] && ($result === $options['breakOn'] ||
if ($options['break'] && ($result === $options['breakOn'] ||
(is_array($options['breakOn']) && in_array($result, $options['breakOn'], true)))
) {
return $result;

View file

@ -320,8 +320,7 @@ class Helper extends Object {
if (!empty($options['pathPrefix']) && $path[0] !== '/') {
$path = $options['pathPrefix'] . $path;
}
if (
!empty($options['ext']) &&
if (!empty($options['ext']) &&
strpos($path, '?') === false &&
substr($path, -strlen($options['ext'])) !== $options['ext']
) {
@ -543,8 +542,7 @@ class Helper extends Object {
$lastPart = isset($parts[$count - 1]) ? $parts[$count - 1] : null;
// Either 'body' or 'date.month' type inputs.
if (
($count === 1 && $this->_modelScope && !$setScope) ||
if (($count === 1 && $this->_modelScope && !$setScope) ||
(
$count === 2 &&
in_array($lastPart, $this->_fieldSuffixes) &&
@ -556,8 +554,7 @@ class Helper extends Object {
}
// 0.name, 0.created.month style inputs. Excludes inputs with the modelScope in them.
if (
$count >= 2 &&
if ($count >= 2 &&
is_numeric($parts[0]) &&
!is_numeric($parts[1]) &&
$this->_modelScope &&

View file

@ -534,8 +534,7 @@ class FormHelper extends AppHelper {
}
$out .= $this->submit($submit, $submitOptions);
}
if (
$this->requestType !== 'get' &&
if ($this->requestType !== 'get' &&
isset($this->request['_Token']) &&
!empty($this->request['_Token'])
) {
@ -1199,8 +1198,7 @@ class FormHelper extends AppHelper {
if ($fieldKey === $primaryKey) {
$options['type'] = 'hidden';
}
if (
$options['type'] === 'number' &&
if ($options['type'] === 'number' &&
!isset($options['step'])
) {
if ($type === 'decimal') {
@ -1318,8 +1316,7 @@ class FormHelper extends AppHelper {
} elseif (is_array($div)) {
$divOptions = array_merge($divOptions, $div);
}
if (
$this->_extractOption('required', $options) !== false &&
if ($this->_extractOption('required', $options) !== false &&
$this->_introspectModel($this->model(), 'validates', $this->field())
) {
$divOptions = $this->addClass($divOptions, 'required');
@ -1362,8 +1359,7 @@ class FormHelper extends AppHelper {
$idKey = null;
if ($options['type'] === 'date' || $options['type'] === 'datetime') {
$firstInput = 'M';
if (
array_key_exists('dateFormat', $options) &&
if (array_key_exists('dateFormat', $options) &&
($options['dateFormat'] === null || $options['dateFormat'] === 'NONE')
) {
$firstInput = 'H';
@ -1444,8 +1440,7 @@ class FormHelper extends AppHelper {
$value = current($this->value($valueOptions));
$output = '';
if (
(!isset($options['checked']) && !empty($value) && $value == $options['value']) ||
if ((!isset($options['checked']) && !empty($value) && $value == $options['value']) ||
!empty($options['checked'])
) {
$options['checked'] = 'checked';
@ -2086,8 +2081,7 @@ class FormHelper extends AppHelper {
$hasOptions = (count($options) > 0 || $showEmpty);
// Secure the field if there are options, or its a multi select.
// Single selects with no options don't submit, but multiselects do.
if (
(!isset($secure) || $secure) &&
if ((!isset($secure) || $secure) &&
empty($attributes['disabled']) &&
(!empty($attributes['multiple']) || $hasOptions)
) {
@ -2761,8 +2755,7 @@ class FormHelper extends AppHelper {
if ($name !== null) {
$isNumeric = is_numeric($name);
if (
(!$selectedIsArray && !$selectedIsEmpty && (string)$attributes['value'] == (string)$name) ||
if ((!$selectedIsArray && !$selectedIsEmpty && (string)$attributes['value'] == (string)$name) ||
($selectedIsArray && in_array((string)$name, $attributes['value'], !$isNumeric))
) {
if ($attributes['style'] === 'checkbox') {
@ -2782,8 +2775,7 @@ class FormHelper extends AppHelper {
$disabledIsNumeric = is_numeric($name);
}
}
if (
$hasDisabled &&
if ($hasDisabled &&
$disabledIsArray &&
in_array((string)$name, $attributes['disabled'], !$disabledIsNumeric)
) {
@ -2902,8 +2894,7 @@ class FormHelper extends AppHelper {
if ($min > $max) {
list($min, $max) = array($max, $min);
}
if (
!empty($options['value']) &&
if (!empty($options['value']) &&
(int)$options['value'] < $min &&
(int)$options['value'] > 0
) {