Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rector] Apply BooleanInIfConditionRuleFixerRector #7951

Merged
merged 20 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
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;
Expand Down Expand Up @@ -140,4 +141,5 @@
$rectorConfig->rule(StringClassNameToClassConstantRector::class);
$rectorConfig->rule(PrivatizeFinalClassPropertyRector::class);
$rectorConfig->rule(CompleteDynamicPropertiesRector::class);
$rectorConfig->rule(BooleanInIfConditionRuleFixerRector::class);
};
2 changes: 1 addition & 1 deletion system/Autoloader/FileLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function search(string $path, string $ext = 'php', bool $prioritizeApp =
*/
protected function ensureExt(string $path, string $ext): string
{
if ($ext) {
if ($ext !== '') {
$ext = '.' . $ext;

if (substr($path, -strlen($ext)) !== $ext) {
Expand Down
6 changes: 4 additions & 2 deletions system/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ public function paginate(?int $perPage = null, string $group = 'default', ?int $
// Since multiple models may use the Pager, the Pager must be shared.
$pager = Services::pager();

if ($segment) {
if ($segment !== 0) {
$pager->setSegment($segment, $group);
}

Expand Down Expand Up @@ -1656,8 +1656,10 @@ protected function objectToArray($data, bool $onlyChanged = true, bool $recursiv
{
$properties = $this->objectToRawArray($data, $onlyChanged, $recursive);

assert(is_array($properties));

// Convert any Time instances to appropriate $dateFormat
if ($properties) {
if ($properties !== []) {
$properties = array_map(function ($value) {
if ($value instanceof Time) {
return $this->timeToDate($value);
Expand Down
3 changes: 2 additions & 1 deletion system/CLI/Commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ public function verifyCommand(string $command, array $commands): bool

$message = lang('CLI.commandNotFound', [$command]);

if ($alternatives = $this->getCommandAlternatives($command, $commands)) {
$alternatives = $this->getCommandAlternatives($command, $commands);
if ($alternatives !== []) {
if (count($alternatives) === 1) {
$message .= "\n\n" . lang('CLI.altCommandSingular') . "\n ";
} else {
Expand Down
2 changes: 1 addition & 1 deletion system/Cache/Handlers/PredisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function save(string $key, $value, int $ttl = 60)
return false;
}

if ($ttl) {
if ($ttl !== 0) {
$this->redis->expireat($key, Time::now()->getTimestamp() + $ttl);
}

Expand Down
2 changes: 1 addition & 1 deletion system/Cache/Handlers/RedisHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function save(string $key, $value, int $ttl = 60)
return false;
}

if ($ttl) {
if ($ttl !== 0) {
$this->redis->expireAt($key, Time::now()->getTimestamp() + $ttl);
}

Expand Down
3 changes: 2 additions & 1 deletion system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ protected function forceSecureAccess($duration = 31_536_000)
*/
public function displayCache(Cache $config)
{
if ($cachedResponse = $this->pageCache->get($this->request, $this->response)) {
$cachedResponse = $this->pageCache->get($this->request, $this->response);
if ($cachedResponse instanceof ResponseInterface) {
$this->response = $cachedResponse;

$this->totalTime = $this->benchmark->getElapsedTime('total_execution');
Expand Down
5 changes: 3 additions & 2 deletions system/Config/Factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ public static function __callStatic(string $component, array $arguments)
}

// Try to locate the class
if ($class = self::locateClass($options, $alias)) {
$class = self::locateClass($options, $alias);
if ($class !== null) {
return new $class(...$arguments);
}

Expand Down Expand Up @@ -422,7 +423,7 @@ public static function setOptions(string $component, array $values): array
*/
public static function reset(?string $component = null)
{
if ($component) {
if ($component !== null) {
unset(
static::$options[$component],
static::$aliases[$component],
Expand Down
2 changes: 1 addition & 1 deletion system/Debug/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ protected function determineView(Throwable $exception, string $templatePath): st
// 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')) !== '') {
$view = 'error_exception.php';
}

Expand Down
6 changes: 3 additions & 3 deletions system/Debug/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function errorHandler(int $severity, string $message, ?string $file = nul
return $this->handleDeprecationError($message, $file, $line);
}

if (error_reporting() & $severity) {
if ((error_reporting() & $severity) !== 0) {
throw new ErrorException($message, 0, $severity, $file, $line);
}

Expand All @@ -227,7 +227,7 @@ public function shutdownHandler()

['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"
Expand All @@ -253,7 +253,7 @@ protected function determineView(Throwable $exception, string $templatePath): st
$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')) !== '') {
$view = 'error_exception.php';
}

Expand Down
2 changes: 1 addition & 1 deletion system/Encryption/Encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function __construct(?EncryptionConfig $config = null)
*/
public function initialize(?EncryptionConfig $config = null)
{
if ($config) {
if ($config instanceof EncryptionConfig) {
$this->key = $config->key;
$this->driver = $config->driver;
$this->digest = $config->digest ?? 'SHA512';
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/CURLRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ protected function setCURLOptions(array $curlOptions = [], array $config = [])
if (! empty($config['decode_content'])) {
$accept = $this->getHeaderLine('Accept-Encoding');

if ($accept) {
if ($accept !== '') {
$curlOptions[CURLOPT_ENCODING] = $accept;
} else {
$curlOptions[CURLOPT_ENCODING] = '';
Expand Down
2 changes: 1 addition & 1 deletion system/HTTP/SiteURI.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private function setBasePath(): void

$this->baseSegments = $this->convertToSegments($this->basePathWithoutIndexPage);

if ($this->indexPage) {
if ($this->indexPage !== '') {
$this->baseSegments[] = $this->indexPage;
}
}
Expand Down
6 changes: 3 additions & 3 deletions system/HTTP/URI.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,11 +177,11 @@ public static function createURIString(
: ltrim($path, '/');
}

if ($query) {
if ($query !== null) {
$uri .= '?' . $query;
}

if ($fragment) {
if ($fragment !== null) {
$uri .= '#' . $fragment;
}

Expand Down Expand Up @@ -1106,7 +1106,7 @@ public function resolveRelativeURI(string $uri)
if ($relative->getPath() === '') {
$transformed->setPath($this->getPath());

if ($relative->getQuery()) {
if ($relative->getQuery() !== '') {
$transformed->setQuery($relative->getQuery());
} else {
$transformed->setQuery($this->getQuery());
Expand Down
2 changes: 1 addition & 1 deletion system/Helpers/test_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function fake($model, ?array $overrides = null, $persist = true)
{
$fabricator = new Fabricator($model);

if ($overrides) {
if ($overrides !== null) {
$fabricator->setOverrides($overrides);
}

Expand Down
2 changes: 1 addition & 1 deletion system/Log/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function __construct($config, bool $debug = CI_DEBUG)

// 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) {
Expand Down
4 changes: 2 additions & 2 deletions system/Pager/Pager.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected function displayLinks(string $group, string $template): string
*/
public function store(string $group, int $page, ?int $perPage, int $total, int $segment = 0)
{
if ($segment) {
if ($segment !== 0) {
$this->setSegment($segment, $group);
}

Expand Down Expand Up @@ -409,7 +409,7 @@ protected function ensureGroup(string $group, ?int $perPage = null)

$this->calculateCurrentPage($group);

if ($_GET) {
if ($_GET !== []) {
$this->groups[$group]['uri'] = $this->groups[$group]['uri']->setQueryArray($_GET);
}
}
Expand Down
2 changes: 1 addition & 1 deletion system/Test/FeatureTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function withRoutes(?array $routes = null)
{
$collection = Services::routes();

if ($routes) {
if ($routes !== null) {
$collection->resetRoutes();

foreach ($routes as $route) {
Expand Down
2 changes: 1 addition & 1 deletion system/Test/FeatureTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ protected function withRoutes(?array $routes = null)
{
$collection = Services::routes();

if ($routes) {
if ($routes !== null) {
$collection->resetRoutes();

foreach ($routes as $route) {
Expand Down
4 changes: 2 additions & 2 deletions system/Validation/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ public function setRule(string $field, ?string $label, $rules, array $errors = [
],
];

if ($errors) {
if ($errors !== []) {
$ruleSet[$field]['errors'] = $errors;
}

Expand Down Expand Up @@ -773,7 +773,7 @@ protected function fillPlaceholders(array $rules, array $data): array

// 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
);
Expand Down
4 changes: 2 additions & 2 deletions system/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public function excerpt(string $string, int $length = 20): string
*/
public function setData(array $data = [], ?string $context = null): RendererInterface
{
if ($context) {
if ($context !== null) {
$data = \esc($data, $context);
}

Expand All @@ -356,7 +356,7 @@ public function setData(array $data = [], ?string $context = null): RendererInte
*/
public function setVar(string $name, $value = null, ?string $context = null): RendererInterface
{
if ($context) {
if ($context !== null) {
$value = esc($value, $context);
}

Expand Down