Skip to content

Commit

Permalink
Merge pull request #13908 from cakephp/master-cs-psr12
Browse files Browse the repository at this point in the history
Master cs psr12
  • Loading branch information
dereuromark committed Nov 20, 2019
2 parents cec761e + d397fbd commit c24643b
Show file tree
Hide file tree
Showing 73 changed files with 210 additions and 122 deletions.
3 changes: 2 additions & 1 deletion src/Cache/Engine/FileEngine.php
Expand Up @@ -394,7 +394,8 @@ protected function _setKey($key, $createKey = false)
if (!$createKey && !$path->isFile()) {
return false;
}
if (empty($this->_File) ||
if (
empty($this->_File) ||
$this->_File->getBasename() !== $key ||
$this->_File->valid() === false
) {
Expand Down
6 changes: 4 additions & 2 deletions src/Cache/Engine/MemcachedEngine.php
Expand Up @@ -204,7 +204,8 @@ protected function _setOptions()
);
}

if ($serializer !== 'php' &&
if (
$serializer !== 'php' &&
!constant('Memcached::HAVE_' . strtoupper($serializer))
) {
throw new InvalidArgumentException(
Expand All @@ -218,7 +219,8 @@ protected function _setOptions()
);

// Check for Amazon ElastiCache instance
if (defined('Memcached::OPT_CLIENT_MODE') &&
if (
defined('Memcached::OPT_CLIENT_MODE') &&
defined('Memcached::DYNAMIC_CLIENT_MODE')
) {
$this->_Memcached->setOption(
Expand Down
6 changes: 4 additions & 2 deletions src/Collection/ExtractTrait.php
Expand Up @@ -70,8 +70,10 @@ protected function _extract($data, $path)
continue;
}

if ($collectionTransform &&
!($data instanceof Traversable || is_array($data))) {
if (
$collectionTransform &&
!($data instanceof Traversable || is_array($data))
) {
return null;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Console/ConsoleOutput.php
Expand Up @@ -164,7 +164,8 @@ public function __construct($stream = 'php://stdout')
{
$this->_output = fopen($stream, 'wb');

if ((DIRECTORY_SEPARATOR === '\\' && !(bool)env('ANSICON') && env('ConEmuANSI') !== 'ON') ||
if (
(DIRECTORY_SEPARATOR === '\\' && !(bool)env('ANSICON') && env('ConEmuANSI') !== 'ON') ||
(function_exists('posix_isatty') && !posix_isatty($this->_output))
) {
$this->_outputAs = self::PLAIN;
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/Component/AuthComponent.php
Expand Up @@ -320,7 +320,8 @@ public function authCheck(Event $event)
return $result;
}

if ($isLoginAction ||
if (
$isLoginAction ||
empty($this->_config['authorize']) ||
$this->isAuthorized($this->user())
) {
Expand Down
6 changes: 4 additions & 2 deletions src/Controller/Component/RequestHandlerComponent.php
Expand Up @@ -342,7 +342,8 @@ public function beforeRender(Event $event)
$response = $response->withCharset(Configure::read('App.encoding'));
}

if ($this->_config['checkHttpCache'] &&
if (
$this->_config['checkHttpCache'] &&
$response->checkNotModified($request)
) {
$controller->setResponse($response);
Expand Down Expand Up @@ -497,7 +498,8 @@ public function requestedWith($type = null)
$request = $controller->getRequest();
$response = $controller->getResponse();

if (!$request->is('post') &&
if (
!$request->is('post') &&
!$request->is('put') &&
!$request->is('patch') &&
!$request->is('delete')
Expand Down
18 changes: 12 additions & 6 deletions src/Controller/Component/SecurityComponent.php
Expand Up @@ -115,7 +115,8 @@ public function startup(Event $event)
throw new AuthSecurityException(sprintf('Action %s is defined as the blackhole callback.', $this->_action));
}

if (!in_array($this->_action, (array)$this->_config['unlockedActions']) &&
if (
!in_array($this->_action, (array)$this->_config['unlockedActions']) &&
$hasData &&
$isNotRequestAction &&
$this->_config['validatePost']
Expand Down Expand Up @@ -236,7 +237,8 @@ protected function _requireMethod($method, $actions = [])
*/
protected function _secureRequired(Controller $controller)
{
if (is_array($this->_config['requireSecure']) &&
if (
is_array($this->_config['requireSecure']) &&
!empty($this->_config['requireSecure'])
) {
$requireSecure = $this->_config['requireSecure'];
Expand All @@ -263,7 +265,8 @@ protected function _secureRequired(Controller $controller)
protected function _authRequired(Controller $controller)
{
$request = $controller->getRequest();
if (is_array($this->_config['requireAuth']) &&
if (
is_array($this->_config['requireAuth']) &&
!empty($this->_config['requireAuth']) &&
$request->getData()
) {
Expand All @@ -278,8 +281,10 @@ protected function _authRequired(Controller $controller)
if ($this->session->check('_Token')) {
$tData = $this->session->read('_Token');

if (!empty($tData['allowedControllers']) &&
!in_array($request->getParam('controller'), $tData['allowedControllers'])) {
if (
!empty($tData['allowedControllers']) &&
!in_array($request->getParam('controller'), $tData['allowedControllers'])
) {
throw new AuthSecurityException(
sprintf(
'Controller \'%s\' was not found in allowed controllers: \'%s\'.',
Expand All @@ -288,7 +293,8 @@ protected function _authRequired(Controller $controller)
)
);
}
if (!empty($tData['allowedActions']) &&
if (
!empty($tData['allowedActions']) &&
!in_array($request->getParam('action'), $tData['allowedActions'])
) {
throw new AuthSecurityException(
Expand Down
3 changes: 2 additions & 1 deletion src/Database/Dialect/SqlserverDialectTrait.php
Expand Up @@ -115,7 +115,8 @@ protected function _pagingSubquery($original, $limit, $offset)
->clause('order')
->iterateParts(function ($direction, $orderBy) use ($select, $order) {
$key = $orderBy;
if (isset($select[$orderBy]) &&
if (
isset($select[$orderBy]) &&
$select[$orderBy] instanceof ExpressionInterface
) {
$key = $select[$orderBy]->sql(new ValueBinder());
Expand Down
3 changes: 2 additions & 1 deletion src/Database/Driver.php
Expand Up @@ -302,7 +302,8 @@ public function schemaValue($value)
if (is_float($value)) {
return str_replace(',', '.', (string)$value);
}
if ((is_int($value) || $value === '0') || (
if (
(is_int($value) || $value === '0') || (
is_numeric($value) && strpos($value, ',') === false &&
$value[0] !== '0' && strpos($value, 'e') === false)
) {
Expand Down
3 changes: 2 additions & 1 deletion src/Database/Expression/ValuesExpression.php
Expand Up @@ -83,7 +83,8 @@ public function __construct(array $columns, $typeMap)
*/
public function add($data)
{
if ((count($this->_values) && $data instanceof Query) ||
if (
(count($this->_values) && $data instanceof Query) ||
($this->_query && is_array($data))
) {
throw new Exception(
Expand Down
3 changes: 2 additions & 1 deletion src/Database/QueryCompiler.php
Expand Up @@ -124,7 +124,8 @@ public function compile(Query $query, ValueBinder $generator)
protected function _sqlCompiler(&$sql, $query, $generator)
{
return function ($parts, $name) use (&$sql, $query, $generator) {
if (!isset($parts) ||
if (
!isset($parts) ||
((is_array($parts) || $parts instanceof \Countable) && !count($parts))
) {
return;
Expand Down
9 changes: 6 additions & 3 deletions src/Database/Schema/MysqlSchema.php
Expand Up @@ -405,7 +405,8 @@ public function columnSql(TableSchema $schema, $name)
TableSchema::TYPE_FLOAT,
TableSchema::TYPE_DECIMAL,
];
if (in_array($data['type'], $hasUnsigned, true) &&
if (
in_array($data['type'], $hasUnsigned, true) &&
isset($data['unsigned']) && $data['unsigned'] === true
) {
$out .= ' UNSIGNED';
Expand All @@ -427,7 +428,8 @@ public function columnSql(TableSchema $schema, $name)
!$schema->hasAutoincrement() &&
!isset($data['autoIncrement'])
);
if (in_array($data['type'], [TableSchema::TYPE_INTEGER, TableSchema::TYPE_BIGINTEGER]) &&
if (
in_array($data['type'], [TableSchema::TYPE_INTEGER, TableSchema::TYPE_BIGINTEGER]) &&
($data['autoIncrement'] === true || $addAutoIncrement)
) {
$out .= ' AUTO_INCREMENT';
Expand All @@ -436,7 +438,8 @@ public function columnSql(TableSchema $schema, $name)
$out .= ' NULL';
unset($data['default']);
}
if (isset($data['default']) &&
if (
isset($data['default']) &&
in_array($data['type'], [TableSchema::TYPE_TIMESTAMP, TableSchema::TYPE_DATETIME]) &&
in_array(strtolower($data['default']), ['current_timestamp', 'current_timestamp()'])
) {
Expand Down
15 changes: 10 additions & 5 deletions src/Database/Schema/PostgresSchema.php
Expand Up @@ -115,7 +115,8 @@ protected function _convertColumn($column)
}
// money is 'string' as it includes arbitrary text content
// before the number value.
if (strpos($col, 'char') !== false ||
if (
strpos($col, 'char') !== false ||
strpos($col, 'money') !== false
) {
return ['type' => TableSchema::TYPE_STRING, 'length' => $length];
Expand All @@ -129,7 +130,8 @@ protected function _convertColumn($column)
if ($col === 'real' || strpos($col, 'double') !== false) {
return ['type' => TableSchema::TYPE_FLOAT, 'length' => null];
}
if (strpos($col, 'numeric') !== false ||
if (
strpos($col, 'numeric') !== false ||
strpos($col, 'decimal') !== false
) {
return ['type' => TableSchema::TYPE_DECIMAL, 'length' => null];
Expand Down Expand Up @@ -389,7 +391,8 @@ public function columnSql(TableSchema $schema, $name)
$out .= ' BYTEA';
}

if ($data['type'] === TableSchema::TYPE_STRING ||
if (
$data['type'] === TableSchema::TYPE_STRING ||
($data['type'] === TableSchema::TYPE_TEXT && $data['length'] === TableSchema::LENGTH_TINY)
) {
$isFixed = !empty($data['fixed']);
Expand All @@ -412,7 +415,8 @@ public function columnSql(TableSchema $schema, $name)
$out .= '(' . (int)$data['precision'] . ')';
}

if ($data['type'] === TableSchema::TYPE_DECIMAL &&
if (
$data['type'] === TableSchema::TYPE_DECIMAL &&
(isset($data['length']) || isset($data['precision']))
) {
$out .= '(' . (int)$data['length'] . ',' . (int)$data['precision'] . ')';
Expand All @@ -422,7 +426,8 @@ public function columnSql(TableSchema $schema, $name)
$out .= ' NOT NULL';
}

if (isset($data['default']) &&
if (
isset($data['default']) &&
in_array($data['type'], [TableSchema::TYPE_TIMESTAMP, TableSchema::TYPE_DATETIME]) &&
strtolower($data['default']) === 'current_timestamp'
) {
Expand Down
15 changes: 10 additions & 5 deletions src/Database/Schema/SqliteSchema.php
Expand Up @@ -317,7 +317,8 @@ public function columnSql(TableSchema $schema, $name)
TableSchema::TYPE_DECIMAL,
];

if (in_array($data['type'], $hasUnsigned, true) &&
if (
in_array($data['type'], $hasUnsigned, true) &&
isset($data['unsigned']) && $data['unsigned'] === true
) {
if ($data['type'] !== TableSchema::TYPE_INTEGER || [$name] !== (array)$schema->primaryKey()) {
Expand All @@ -333,7 +334,8 @@ public function columnSql(TableSchema $schema, $name)
$out .= ' TEXT';
}

if ($data['type'] === TableSchema::TYPE_STRING ||
if (
$data['type'] === TableSchema::TYPE_STRING ||
($data['type'] === TableSchema::TYPE_TEXT && $data['length'] === TableSchema::LENGTH_TINY)
) {
$out .= ' VARCHAR';
Expand All @@ -356,14 +358,16 @@ public function columnSql(TableSchema $schema, $name)
TableSchema::TYPE_SMALLINTEGER,
TableSchema::TYPE_INTEGER,
];
if (in_array($data['type'], $integerTypes, true) &&
if (
in_array($data['type'], $integerTypes, true) &&
isset($data['length']) && [$name] !== (array)$schema->primaryKey()
) {
$out .= '(' . (int)$data['length'] . ')';
}

$hasPrecision = [TableSchema::TYPE_FLOAT, TableSchema::TYPE_DECIMAL];
if (in_array($data['type'], $hasPrecision, true) &&
if (
in_array($data['type'], $hasPrecision, true) &&
(isset($data['length']) || isset($data['precision']))
) {
$out .= '(' . (int)$data['length'] . ',' . (int)$data['precision'] . ')';
Expand Down Expand Up @@ -397,7 +401,8 @@ public function columnSql(TableSchema $schema, $name)
public function constraintSql(TableSchema $schema, $name)
{
$data = $schema->getConstraint($name);
if ($data['type'] === TableSchema::CONSTRAINT_PRIMARY &&
if (
$data['type'] === TableSchema::CONSTRAINT_PRIMARY &&
count($data['columns']) === 1 &&
$schema->getColumn($data['columns'][0])['type'] === TableSchema::TYPE_INTEGER
) {
Expand Down
18 changes: 12 additions & 6 deletions src/Database/Schema/SqlserverSchema.php
Expand Up @@ -106,7 +106,8 @@ protected function _convertColumn($col, $length = null, $precision = null, $scal
if ($col === 'bit') {
return ['type' => TableSchema::TYPE_BOOLEAN, 'length' => null];
}
if (strpos($col, 'numeric') !== false ||
if (
strpos($col, 'numeric') !== false ||
strpos($col, 'money') !== false ||
strpos($col, 'decimal') !== false
) {
Expand Down Expand Up @@ -375,8 +376,10 @@ public function columnSql(TableSchema $schema, $name)
}

if ($data['type'] === TableSchema::TYPE_BINARY) {
if (!isset($data['length'])
|| in_array($data['length'], [TableSchema::LENGTH_MEDIUM, TableSchema::LENGTH_LONG], true)) {
if (
!isset($data['length'])
|| in_array($data['length'], [TableSchema::LENGTH_MEDIUM, TableSchema::LENGTH_LONG], true)
) {
$data['length'] = 'MAX';
}

Expand All @@ -389,7 +392,8 @@ public function columnSql(TableSchema $schema, $name)
}
}

if ($data['type'] === TableSchema::TYPE_STRING ||
if (
$data['type'] === TableSchema::TYPE_STRING ||
($data['type'] === TableSchema::TYPE_TEXT && $data['length'] === TableSchema::LENGTH_TINY)
) {
$type = ' NVARCHAR';
Expand All @@ -414,7 +418,8 @@ public function columnSql(TableSchema $schema, $name)
$out .= '(' . (int)$data['precision'] . ')';
}

if ($data['type'] === TableSchema::TYPE_DECIMAL &&
if (
$data['type'] === TableSchema::TYPE_DECIMAL &&
(isset($data['length']) || isset($data['precision']))
) {
$out .= '(' . (int)$data['length'] . ',' . (int)$data['precision'] . ')';
Expand All @@ -424,7 +429,8 @@ public function columnSql(TableSchema $schema, $name)
$out .= ' NOT NULL';
}

if (isset($data['default']) &&
if (
isset($data['default']) &&
in_array($data['type'], [TableSchema::TYPE_TIMESTAMP, TableSchema::TYPE_DATETIME]) &&
strtolower($data['default']) === 'current_timestamp'
) {
Expand Down
3 changes: 2 additions & 1 deletion src/Database/SqlDialectTrait.php
Expand Up @@ -225,7 +225,8 @@ protected function _removeAliasesFromConditions($query)
$conditions->traverse(function ($expression) {
if ($expression instanceof Comparison) {
$field = $expression->getField();
if (is_string($field) &&
if (
is_string($field) &&
strpos($field, '.') !== false
) {
list(, $unaliasedField) = explode('.', $field, 2);
Expand Down
3 changes: 2 additions & 1 deletion src/Database/Type/BinaryType.php
Expand Up @@ -79,7 +79,8 @@ public function toPHP($value, Driver $driver)
if ($value === null) {
return null;
}
if (is_string($value)
if (
is_string($value)
&& $driver instanceof Sqlserver
&& version_compare(PHP_VERSION, '7.0', '<')
) {
Expand Down
6 changes: 4 additions & 2 deletions src/Database/Type/DateTimeType.php
Expand Up @@ -139,7 +139,8 @@ public function toDatabase($value, Driver $driver)

$format = (array)$this->_format;

if ($this->dbTimezone !== null
if (
$this->dbTimezone !== null
&& $this->dbTimezone->getName() !== $value->getTimezone()->getName()
) {
if (!$value instanceof DateTimeImmutable) {
Expand Down Expand Up @@ -267,7 +268,8 @@ public function marshal($value)
$value += ['hour' => 0, 'minute' => 0, 'second' => 0];

$format = '';
if (isset($value['year'], $value['month'], $value['day']) &&
if (
isset($value['year'], $value['month'], $value['day']) &&
(is_numeric($value['year']) && is_numeric($value['month']) && is_numeric($value['day']))
) {
$format .= sprintf('%d-%02d-%02d', $value['year'], $value['month'], $value['day']);
Expand Down

0 comments on commit c24643b

Please sign in to comment.