Skip to content

Commit

Permalink
Merge 324a5c2 into 11805ef
Browse files Browse the repository at this point in the history
  • Loading branch information
ADmad committed Oct 1, 2019
2 parents 11805ef + 324a5c2 commit 63109e0
Show file tree
Hide file tree
Showing 145 changed files with 506 additions and 240 deletions.
1 change: 1 addition & 0 deletions config/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* @since 0.2.9
* @license https://opensource.org/licenses/mit-license.php MIT License
*/

use Cake\Routing\Router;

define('TIME_START', microtime(true));
Expand Down
3 changes: 2 additions & 1 deletion config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @license https://opensource.org/licenses/mit-license.php MIT License
*/
$versionFile = file(CORE_PATH . 'VERSION.txt');

return [
'Cake.version' => trim(array_pop($versionFile))
'Cake.version' => trim(array_pop($versionFile)),
];
17 changes: 17 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,21 @@
<config name="installed_paths" value="../../cakephp/cakephp-codesniffer" />

<rule ref="CakePHP" />

<!-- https://github.com/squizlabs/PHP_CodeSniffer/issues/2619 -->
<rule ref="PSR12.Files.FileHeader">
<exclude-pattern>*/test_app/config/bootstrap.php</exclude-pattern>
<exclude-pattern>*/test_app/config/empty.php</exclude-pattern>
<severity>0</severity>
</rule>

<rule ref="PSR2.ControlStructures.ControlStructureSpacing.SpacingAfterOpenBrace">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterSecond">
<severity>0</severity>
</rule>
<rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterFirst">
<severity>0</severity>
</rule>
</ruleset>
3 changes: 2 additions & 1 deletion src/Cache/Engine/FileEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,8 @@ protected function _setKey(string $key, bool $createKey = false): bool
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
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ protected function _setOptions(): void
);
}

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

// 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
12 changes: 8 additions & 4 deletions src/Collection/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,10 @@ public function isEmpty(): bool
public function unwrap(): Traversable
{
$iterator = $this;
while (get_class($iterator) === Collection::class
&& $iterator instanceof OuterIterator) {
while (
get_class($iterator) === Collection::class
&& $iterator instanceof OuterIterator
) {
$iterator = $iterator->getInnerIterator();
}

Expand Down Expand Up @@ -956,10 +958,12 @@ public function cartesianProduct(?callable $operation = null, ?callable $filter
$currentIndexes[$lastIndex]++;

// phpcs:ignore Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterFirst
for ($changeIndex = $lastIndex;
for (
$changeIndex = $lastIndex;
// phpcs:ignore Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterSecond
$currentIndexes[$changeIndex] === $collectionArraysCounts[$changeIndex] && $changeIndex > 0;
$changeIndex--) {
$changeIndex--
) {
$currentIndexes[$changeIndex] = 0;
$currentIndexes[$changeIndex - 1]++;
}
Expand Down
9 changes: 7 additions & 2 deletions src/Collection/ExtractTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ protected function _extract($data, array $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/Command/CompletionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ protected function shellSubcommands(Shell $shell): array
$coreShellReflection = new ReflectionClass(Shell::class);
$reflection = new ReflectionClass($shell);
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if ($shell->hasMethod($method->getName())
if (
$shell->hasMethod($method->getName())
&& !$coreShellReflection->hasMethod($method->getName())
) {
$output[] = $method->getName();
Expand Down
9 changes: 6 additions & 3 deletions src/Command/I18nExtractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,8 @@ protected function _writeFiles(Arguments $args, ConsoleIo $io): void

$filename = str_replace('/', '_', $domain) . '.pot';
$response = '';
while ($overwriteAll === false
while (
$overwriteAll === false
&& file_exists($this->_output . $filename)
&& strtoupper($response) !== 'Y'
) {
Expand Down Expand Up @@ -698,7 +699,8 @@ protected function _getStrings(int &$position, int $target): array
{
$strings = [];
$count = count($strings);
while ($count < $target
while (
$count < $target
&& ($this->_tokens[$position] === ','
|| $this->_tokens[$position][0] === T_CONSTANT_ENCAPSED_STRING
|| $this->_tokens[$position][0] === T_LNUMBER
Expand All @@ -707,7 +709,8 @@ protected function _getStrings(int &$position, int $target): array
$count = count($strings);
if ($this->_tokens[$position][0] === T_CONSTANT_ENCAPSED_STRING && $this->_tokens[$position + 1] === '.') {
$string = '';
while ($this->_tokens[$position][0] === T_CONSTANT_ENCAPSED_STRING
while (
$this->_tokens[$position][0] === T_CONSTANT_ENCAPSED_STRING
|| $this->_tokens[$position] === '.'
) {
if ($this->_tokens[$position][0] === T_CONSTANT_ENCAPSED_STRING) {
Expand Down
3 changes: 2 additions & 1 deletion src/Command/PluginAssetsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ protected function _process(array $plugins, bool $copy = false, bool $overwrite
$this->io->out('For plugin: ' . $plugin);
$this->io->hr();

if ($config['namespaced'] &&
if (
$config['namespaced'] &&
!is_dir($config['destDir']) &&
!$this->_createDirectory($config['destDir'])
) {
Expand Down
3 changes: 2 additions & 1 deletion src/Console/CommandScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ protected function scanDir(string $path, string $namespace, string $prefix, arra

$class = $namespace . $fileInfo->getBasename('.php');
/** @psalm-suppress DeprecatedClass */
if (!is_subclass_of($class, Shell::class)
if (
!is_subclass_of($class, Shell::class)
&& !is_subclass_of($class, Command::class)
) {
continue;
Expand Down
12 changes: 10 additions & 2 deletions src/Console/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,16 @@ public function __construct(string $stream = 'php://stdout')
{
$this->_output = fopen($stream, 'wb');

if ((DIRECTORY_SEPARATOR === '\\' && !(bool)env('ANSICON') && env('ConEmuANSI') !== 'ON') ||
(function_exists('posix_isatty') && !posix_isatty($this->_output))
if (
(
DIRECTORY_SEPARATOR === '\\' &&
!(bool)env('ANSICON') &&
env('ConEmuANSI') !== 'ON'
) ||
(
function_exists('posix_isatty') &&
!posix_isatty($this->_output)
)
) {
$this->_outputAs = self::PLAIN;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Controller/Component/AuthComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,8 @@ public function authCheck(EventInterface $event): ?Response
return $result;
}

if ($isLoginAction ||
if (
$isLoginAction ||
empty($this->_config['authorize']) ||
$this->isAuthorized($this->user())
) {
Expand Down Expand Up @@ -748,7 +749,8 @@ public function redirectUrl($url = null): string
if ($url !== null) {
$redirectUrl = $url;
} elseif ($redirectUrl) {
if ($this->_config['loginAction']
if (
$this->_config['loginAction']
&& Router::normalize($redirectUrl) === Router::normalize($this->_config['loginAction'])
) {
$redirectUrl = $this->_config['loginRedirect'];
Expand Down
6 changes: 4 additions & 2 deletions src/Controller/Component/RequestHandlerComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ public function beforeRender(EventInterface $event): void
$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 @@ -344,7 +345,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
6 changes: 4 additions & 2 deletions src/Controller/Component/SecurityComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public function startup(EventInterface $event): ?Response
));
}

if (!in_array($this->_action, (array)$this->_config['unlockedActions'], true) &&
if (
!in_array($this->_action, (array)$this->_config['unlockedActions'], true) &&
$hasData &&
$this->_config['validatePost']
) {
Expand Down Expand Up @@ -215,7 +216,8 @@ protected function _requireMethod(string $method, array $actions = []): void
*/
protected function _secureRequired(Controller $controller): void
{
if (is_array($this->_config['requireSecure']) &&
if (
is_array($this->_config['requireSecure']) &&
!empty($this->_config['requireSecure'])
) {
$requireSecure = $this->_config['requireSecure'];
Expand Down
3 changes: 2 additions & 1 deletion src/Controller/ErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public function beforeRender(EventInterface $event)
$builder = $this->viewBuilder();
$templatePath = 'Error';

if ($this->request->getParam('prefix') &&
if (
$this->request->getParam('prefix') &&
in_array($builder->getTemplate(), ['error400', 'error500'], true)
) {
$parts = explode(DIRECTORY_SEPARATOR, (string)$builder->getTemplatePath(), -1);
Expand Down
3 changes: 2 additions & 1 deletion src/Database/Dialect/SqlserverDialectTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ protected function _pagingSubquery(Query $original, ?int $limit, ?int $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
14 changes: 11 additions & 3 deletions src/Database/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,17 @@ public function schemaValue($value): string
return str_replace(',', '.', (string)$value);
}
/** @psalm-suppress InvalidArgument */
if ((is_int($value) || $value === '0') || (
is_numeric($value) && strpos($value, ',') === false &&
substr($value, 0, 1) !== '0' && strpos($value, 'e') === false)
if (
(
is_int($value) ||
$value === '0'
) ||
(
is_numeric($value) &&
strpos($value, ',') === false &&
substr($value, 0, 1) !== '0' &&
strpos($value, 'e') === false
)
) {
return (string)$value;
}
Expand Down
3 changes: 2 additions & 1 deletion src/Database/Expression/OrderByExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public function sql(ValueBinder $generator): string
protected function _addConditions(array $orders, array $types): void
{
foreach ($orders as $key => $val) {
if (is_string($key) &&
if (
is_string($key) &&
is_string($val) &&
!in_array(strtoupper($val), ['ASC', 'DESC'], true)
) {
Expand Down
1 change: 1 addition & 0 deletions src/Database/Expression/QueryExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ protected function _addConditions(array $conditions, array $types): void

if ($numericKey && $isArray || $isOperator) {
/** @var \Cake\Database\Expression\QueryExpression $this->_conditions[] */
// phpcs:ignore
$this->_conditions[] = new static($c, $typeMap, $numericKey ? 'AND' : $k);
continue;
}
Expand Down
11 changes: 9 additions & 2 deletions src/Database/Expression/ValuesExpression.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,15 @@ public function __construct(array $columns, TypeMap $typeMap)
*/
public function add($data): void
{
if ((count($this->_values) && $data instanceof Query) ||
($this->_query && is_array($data))
if (
(
count($this->_values) &&
$data instanceof Query
) ||
(
$this->_query &&
is_array($data)
)
) {
throw new Exception(
'You cannot mix subqueries and array data in inserts.'
Expand Down
11 changes: 9 additions & 2 deletions src/Database/QueryCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,15 @@ public function compile(Query $query, ValueBinder $generator): string
protected function _sqlCompiler(string &$sql, Query $query, ValueBinder $generator): Closure
{
return function ($parts, $name) use (&$sql, $query, $generator): ?string {
if (!isset($parts) ||
((is_array($parts) || $parts instanceof Countable) && !count($parts))
if (
!isset($parts) ||
(
(
is_array($parts) ||
$parts instanceof Countable
) &&
!count($parts)
)
) {
return null;
}
Expand Down
25 changes: 18 additions & 7 deletions src/Database/Schema/MysqlSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,12 @@ public function columnSql(TableSchema $schema, string $name): string
}

$hasPrecision = [TableSchema::TYPE_FLOAT, TableSchema::TYPE_DECIMAL];
if (in_array($data['type'], $hasPrecision, true) &&
(isset($data['length']) || isset($data['precision']))
if (
in_array($data['type'], $hasPrecision, true) &&
(
isset($data['length']) ||
isset($data['precision'])
)
) {
$out .= '(' . (int)$data['length'] . ',' . (int)$data['precision'] . ')';
}
Expand All @@ -405,8 +409,10 @@ public function columnSql(TableSchema $schema, string $name): string
TableSchema::TYPE_FLOAT,
TableSchema::TYPE_DECIMAL,
];
if (in_array($data['type'], $hasUnsigned, true) &&
isset($data['unsigned']) && $data['unsigned'] === true
if (
in_array($data['type'], $hasUnsigned, true) &&
isset($data['unsigned']) &&
$data['unsigned'] === true
) {
$out .= ' UNSIGNED';
}
Expand All @@ -427,16 +433,21 @@ public function columnSql(TableSchema $schema, string $name): string
!$schema->hasAutoincrement() &&
!isset($data['autoIncrement'])
);
if (in_array($data['type'], [TableSchema::TYPE_INTEGER, TableSchema::TYPE_BIGINTEGER]) &&
($data['autoIncrement'] === true || $addAutoIncrement)
if (
in_array($data['type'], [TableSchema::TYPE_INTEGER, TableSchema::TYPE_BIGINTEGER]) &&
(
$data['autoIncrement'] === true ||
$addAutoIncrement
)
) {
$out .= ' AUTO_INCREMENT';
}
if (isset($data['null']) && $data['null'] === true && $data['type'] === TableSchema::TYPE_TIMESTAMP) {
$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

0 comments on commit 63109e0

Please sign in to comment.