[Rector] Apply BooleanInIfConditionRuleFixerRector

This commit is contained in:
Abdul Malik Ikhsan 2023-09-18 14:49:59 +07:00
parent 08458d3ca5
commit 83ebb79d20
No known key found for this signature in database
GPG Key ID: 89B60A24AF686D41
21 changed files with 31 additions and 29 deletions

View File

@ -41,6 +41,7 @@ use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Set\ValueObject\LevelSetList;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
use Utils\Rector\PassStrictParameterToFunctionParameterRector;
use Utils\Rector\RemoveErrorSuppressInTryCatchStmtsRector;
use Utils\Rector\RemoveVarTagFromClassConstantRector;
@ -140,4 +141,5 @@ return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(StringClassNameToClassConstantRector::class);
$rectorConfig->rule(PrivatizeFinalClassPropertyRector::class);
$rectorConfig->rule(CompleteDynamicPropertiesRector::class);
$rectorConfig->rule(BooleanInIfConditionRuleFixerRector::class);
};

View File

@ -205,7 +205,7 @@ class FileLocator
*/
protected function ensureExt(string $path, string $ext): string
{
if ($ext) {
if ($ext !== '') {
$ext = '.' . $ext;
if (substr($path, -strlen($ext)) !== $ext) {

View File

@ -1194,7 +1194,7 @@ abstract class BaseModel
// Since multiple models may use the Pager, the Pager must be shared.
$pager = Services::pager();
if ($segment) {
if ($segment !== 0) {
$pager->setSegment($segment, $group);
}
@ -1657,7 +1657,7 @@ abstract class BaseModel
$properties = $this->objectToRawArray($data, $onlyChanged, $recursive);
// Convert any Time instances to appropriate $dateFormat
if ($properties) {
if ($properties !== null && $properties !== []) {
$properties = array_map(function ($value) {
if ($value instanceof Time) {
return $this->timeToDate($value);

View File

@ -146,7 +146,7 @@ class Commands
$message = lang('CLI.commandNotFound', [$command]);
if ($alternatives = $this->getCommandAlternatives($command, $commands)) {
if (($alternatives = $this->getCommandAlternatives($command, $commands)) !== []) {
if (count($alternatives) === 1) {
$message .= "\n\n" . lang('CLI.altCommandSingular') . "\n ";
} else {

View File

@ -133,7 +133,7 @@ class PredisHandler extends BaseHandler
return false;
}
if ($ttl) {
if ($ttl !== 0) {
$this->redis->expireat($key, Time::now()->getTimestamp() + $ttl);
}

View File

@ -159,7 +159,7 @@ class RedisHandler extends BaseHandler
return false;
}
if ($ttl) {
if ($ttl !== 0) {
$this->redis->expireAt($key, Time::now()->getTimestamp() + $ttl);
}

View File

@ -708,7 +708,7 @@ class CodeIgniter
*/
public function displayCache(Cache $config)
{
if ($cachedResponse = $this->pageCache->get($this->request, $this->response)) {
if (($cachedResponse = $this->pageCache->get($this->request, $this->response)) instanceof ResponseInterface) {
$this->response = $cachedResponse;
$this->totalTime = $this->benchmark->getElapsedTime('total_execution');

View File

@ -145,7 +145,7 @@ class Factories
}
// Try to locate the class
if ($class = self::locateClass($options, $alias)) {
if (($class = self::locateClass($options, $alias)) !== null && ($class = self::locateClass($options, $alias)) !== '') {
return new $class(...$arguments);
}
@ -422,7 +422,7 @@ class Factories
*/
public static function reset(?string $component = null)
{
if ($component) {
if ($component !== null && $component !== '') {
unset(
static::$options[$component],
static::$aliases[$component],

View File

@ -129,7 +129,7 @@ final class ExceptionHandler extends BaseExceptionHandler implements ExceptionHa
// Production environments should have a custom exception file.
$view = 'production.php';
if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors'))) {
if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== '' && str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== []) {
$view = 'error_exception.php';
}

View File

@ -201,7 +201,7 @@ class Exceptions
return $this->handleDeprecationError($message, $file, $line);
}
if (error_reporting() & $severity) {
if ((error_reporting() & $severity) !== 0) {
throw new ErrorException($message, 0, $severity, $file, $line);
}
@ -227,7 +227,7 @@ class Exceptions
['type' => $type, 'message' => $message, 'file' => $file, 'line' => $line] = $error;
if ($this->exceptionCaughtByExceptionHandler) {
if ($this->exceptionCaughtByExceptionHandler instanceof Throwable) {
$message .= "\n【Previous Exception】\n"
. get_class($this->exceptionCaughtByExceptionHandler) . "\n"
. $this->exceptionCaughtByExceptionHandler->getMessage() . "\n"
@ -253,7 +253,7 @@ class Exceptions
$view = 'production.php';
$templatePath = rtrim($templatePath, '\\/ ') . DIRECTORY_SEPARATOR;
if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors'))) {
if (str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== [] && str_ireplace(['off', 'none', 'no', 'false', 'null'], '', ini_get('display_errors')) !== '') {
$view = 'error_exception.php';
}

View File

@ -108,7 +108,7 @@ class Encryption
*/
public function initialize(?EncryptionConfig $config = null)
{
if ($config) {
if ($config instanceof \Config\Encryption) {
$this->key = $config->key;
$this->driver = $config->driver;
$this->digest = $config->digest ?? 'SHA512';

View File

@ -578,7 +578,7 @@ class CURLRequest extends OutgoingRequest
if (! empty($config['decode_content'])) {
$accept = $this->getHeaderLine('Accept-Encoding');
if ($accept) {
if ($accept !== '') {
$curlOptions[CURLOPT_ENCODING] = $accept;
} else {
$curlOptions[CURLOPT_ENCODING] = '';

View File

@ -213,7 +213,7 @@ class SiteURI extends URI
$this->baseSegments = $this->convertToSegments($this->basePathWithoutIndexPage);
if ($this->indexPage) {
if ($this->indexPage !== '') {
$this->baseSegments[] = $this->indexPage;
}
}

View File

@ -177,11 +177,11 @@ class URI
: ltrim($path, '/');
}
if ($query) {
if ($query !== null && $query !== '') {
$uri .= '?' . $query;
}
if ($fragment) {
if ($fragment !== null && $fragment !== '') {
$uri .= '#' . $fragment;
}
@ -1106,7 +1106,7 @@ class URI
if ($relative->getPath() === '') {
$transformed->setPath($this->getPath());
if ($relative->getQuery()) {
if ($relative->getQuery() !== '') {
$transformed->setQuery($relative->getQuery());
} else {
$transformed->setQuery($this->getQuery());

View File

@ -30,7 +30,7 @@ if (! function_exists('fake')) {
{
$fabricator = new Fabricator($model);
if ($overrides) {
if ($overrides !== null && $overrides !== []) {
$fabricator->setOverrides($overrides);
}

View File

@ -125,7 +125,7 @@ class Logger implements LoggerInterface
// Now convert loggable levels to strings.
// We only use numbers to make the threshold setting convenient for users.
if ($this->loggableLevels) {
if ($this->loggableLevels !== []) {
$temp = [];
foreach ($this->loggableLevels as $level) {

View File

@ -136,7 +136,7 @@ class Pager implements PagerInterface
*/
public function store(string $group, int $page, ?int $perPage, int $total, int $segment = 0)
{
if ($segment) {
if ($segment !== 0) {
$this->setSegment($segment, $group);
}
@ -409,7 +409,7 @@ class Pager implements PagerInterface
$this->calculateCurrentPage($group);
if ($_GET) {
if ($_GET !== []) {
$this->groups[$group]['uri'] = $this->groups[$group]['uri']->setQueryArray($_GET);
}
}

View File

@ -55,7 +55,7 @@ class FeatureTestCase extends CIUnitTestCase
{
$collection = Services::routes();
if ($routes) {
if ($routes !== null && $routes !== []) {
$collection->resetRoutes();
foreach ($routes as $route) {

View File

@ -47,7 +47,7 @@ trait FeatureTestTrait
{
$collection = Services::routes();
if ($routes) {
if ($routes !== null && $routes !== []) {
$collection->resetRoutes();
foreach ($routes as $route) {

View File

@ -525,7 +525,7 @@ class Validation implements ValidationInterface
],
];
if ($errors) {
if ($errors !== []) {
$ruleSet[$field]['errors'] = $errors;
}
@ -773,7 +773,7 @@ class Validation implements ValidationInterface
// Check if the rule does not have placeholders
foreach ($placeholderRules as $placeholderRule) {
if ($this->retrievePlaceholders($placeholderRule, $data)) {
if ($this->retrievePlaceholders($placeholderRule, $data) !== []) {
throw new LogicException(
'The placeholder field cannot use placeholder: ' . $field
);

View File

@ -336,7 +336,7 @@ class View implements RendererInterface
*/
public function setData(array $data = [], ?string $context = null): RendererInterface
{
if ($context) {
if ($context !== null && $context !== '') {
$data = \esc($data, $context);
}
@ -356,7 +356,7 @@ class View implements RendererInterface
*/
public function setVar(string $name, $value = null, ?string $context = null): RendererInterface
{
if ($context) {
if ($context !== null && $context !== '') {
$value = esc($value, $context);
}