From ac19c85ed001b4cbe4705271ee47128653f5d2e6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 11 Jul 2021 07:31:21 +0700 Subject: [PATCH] [Rector] Re-run InlineIfToExplicitIfRector on Latest Rector 0.11.36 --- composer.json | 4 +-- rector.php | 4 +++ system/CodeIgniter.php | 8 +++-- system/Database/BaseResult.php | 16 +++++++--- system/Database/Forge.php | 10 +++--- system/Database/MySQLi/Connection.php | 5 +-- system/Database/Postgre/Connection.php | 4 ++- system/Email/Email.php | 4 ++- system/Session/Handlers/MemcachedHandler.php | 4 ++- system/Session/Handlers/RedisHandler.php | 4 ++- .../system/Commands/CommandGeneratorTest.php | 8 +++-- tests/system/Commands/ConfigGeneratorTest.php | 4 ++- .../Commands/ConfigurableSortImportsTest.php | 20 +++++++++--- .../Commands/ControllerGeneratorTest.php | 4 ++- tests/system/Commands/EntityGeneratorTest.php | 8 +++-- tests/system/Commands/FilterGeneratorTest.php | 4 ++- tests/system/Commands/GeneratorsTest.php | 32 ++++++++++++++----- .../Commands/MigrationGeneratorTest.php | 4 ++- tests/system/Commands/ModelGeneratorTest.php | 16 +++++++--- tests/system/Commands/SeederGeneratorTest.php | 4 ++- .../system/Commands/SessionsCommandsTest.php | 4 ++- .../Commands/ValidationGeneratorTest.php | 8 +++-- tests/system/HTTP/Files/FileMovingTest.php | 24 ++++++++++---- 23 files changed, 150 insertions(+), 53 deletions(-) diff --git a/composer.json b/composer.json index 2cf15f4e86..ef116fc088 100644 --- a/composer.json +++ b/composer.json @@ -20,10 +20,10 @@ "mikey179/vfsstream": "^1.6", "nexusphp/cs-config": "^3.1", "nexusphp/tachycardia": "^1.0", - "phpstan/phpstan": "0.12.90", + "phpstan/phpstan": "0.12.91", "phpunit/phpunit": "^9.1", "predis/predis": "^1.1", - "rector/rector": "0.11.35", + "rector/rector": "0.11.36", "symplify/package-builder": "^9.3" }, "suggest": { diff --git a/rector.php b/rector.php index ec64a2c382..bc01a45eb1 100644 --- a/rector.php +++ b/rector.php @@ -61,6 +61,10 @@ return static function (ContainerConfigurator $containerConfigurator): void { PassStrictParameterToFunctionParameterRector::class => [__DIR__ . '/tests/system/Database/Live/SelectTest.php'], JsonThrowOnErrorRector::class, StringifyStrNeedlesRector::class, + InlineIfToExplicitIfRector::class => [ + __DIR__ . '/app/Config', + __DIR__ . '/system/Test/bootstrap.php', + ], ]); // auto import fully qualified class names diff --git a/system/CodeIgniter.php b/system/CodeIgniter.php index a9b23821a7..57857bc63e 100644 --- a/system/CodeIgniter.php +++ b/system/CodeIgniter.php @@ -239,7 +239,9 @@ class CodeIgniter $file = SYSTEMPATH . 'ThirdParty/Kint/' . implode('/', $class) . '.php'; - file_exists($file) && require_once $file; + if (file_exists($file)) { + require_once $file; + } }); require_once SYSTEMPATH . 'ThirdParty/Kint/init.php'; @@ -476,7 +478,9 @@ class CodeIgniter protected function detectEnvironment() { // Make sure ENVIRONMENT isn't already set by other means. - defined('ENVIRONMENT') || define('ENVIRONMENT', $_SERVER['CI_ENVIRONMENT'] ?? 'production'); // @codeCoverageIgnore + if (!defined('ENVIRONMENT')) { + define('ENVIRONMENT', $_SERVER['CI_ENVIRONMENT'] ?? 'production'); + } // @codeCoverageIgnore } //-------------------------------------------------------------------- diff --git a/system/Database/BaseResult.php b/system/Database/BaseResult.php index b7de79e394..7b558886cb 100644 --- a/system/Database/BaseResult.php +++ b/system/Database/BaseResult.php @@ -151,7 +151,9 @@ abstract class BaseResult implements ResultInterface return $this->customResultObject[$className]; } - $this->rowData === null || $this->dataSeek(); + if ($this->rowData !== null) { + $this->dataSeek(); + } $this->customResultObject[$className] = []; while ($row = $this->fetchObject($className)) { @@ -196,7 +198,9 @@ abstract class BaseResult implements ResultInterface return $this->resultArray; } - $this->rowData === null || $this->dataSeek(); + if ($this->rowData !== null) { + $this->dataSeek(); + } while ($row = $this->fetchAssoc()) { $this->resultArray[] = $row; @@ -235,7 +239,9 @@ abstract class BaseResult implements ResultInterface return $this->resultObject; } - $this->rowData === null || $this->dataSeek(); + if ($this->rowData !== null) { + $this->dataSeek(); + } while ($row = $this->fetchObject()) { if (! is_subclass_of($row, Entity::class) && method_exists($row, 'syncOriginal')) { @@ -303,7 +309,9 @@ abstract class BaseResult implements ResultInterface */ public function getCustomRowObject(int $n, string $className) { - isset($this->customResultObject[$className]) || $this->getCustomResultObject($className); + if (!isset($this->customResultObject[$className])) { + $this->getCustomResultObject($className); + } if (empty($this->customResultObject[$className])) { return null; diff --git a/system/Database/Forge.php b/system/Database/Forge.php index 31b45498b1..62efaf9720 100644 --- a/system/Database/Forge.php +++ b/system/Database/Forge.php @@ -905,8 +905,9 @@ class Forge continue; } - // @phpstan-ignore-next-line - isset($attributes['TYPE']) && $this->_attributeType($attributes); + if (isset($attributes['TYPE'])) { + $this->_attributeType($attributes); + } $field = [ 'name' => $key, @@ -921,8 +922,9 @@ class Forge '_literal' => false, ]; - // @phpstan-ignore-next-line - isset($attributes['TYPE']) && $this->_attributeUnsigned($attributes, $field); + if (isset($attributes['TYPE'])) { + $this->_attributeUnsigned($attributes, $field); + } if ($createTable === false) { if (isset($attributes['AFTER'])) { diff --git a/system/Database/MySQLi/Connection.php b/system/Database/MySQLi/Connection.php index 37d3f38b0f..cb7bff2efd 100644 --- a/system/Database/MySQLi/Connection.php +++ b/system/Database/MySQLi/Connection.php @@ -136,8 +136,9 @@ class Connection extends BaseConnection if (! empty($ssl)) { if (isset($this->encrypt['ssl_verify'])) { if ($this->encrypt['ssl_verify']) { - defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT') - && $this->mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, 1); + if (defined('MYSQLI_OPT_SSL_VERIFY_SERVER_CERT')) { + $this->mysqli->options(MYSQLI_OPT_SSL_VERIFY_SERVER_CERT, 1); + } } // Apparently (when it exists), setting MYSQLI_OPT_SSL_VERIFY_SERVER_CERT // to FALSE didn't do anything, so PHP 5.6.16 introduced yet another diff --git a/system/Database/Postgre/Connection.php b/system/Database/Postgre/Connection.php index 3012a76949..dda54ca0bd 100644 --- a/system/Database/Postgre/Connection.php +++ b/system/Database/Postgre/Connection.php @@ -75,7 +75,9 @@ class Connection extends BaseConnection return false; } - empty($this->schema) || $this->simpleQuery("SET search_path TO {$this->schema},public"); + if (!empty($this->schema)) { + $this->simpleQuery("SET search_path TO {$this->schema},public"); + } if ($this->setClientEncoding($this->charset) === false) { return false; diff --git a/system/Email/Email.php b/system/Email/Email.php index 87b4a0cd40..788400c987 100644 --- a/system/Email/Email.php +++ b/system/Email/Email.php @@ -2256,7 +2256,9 @@ class Email */ public function __destruct() { - is_resource($this->SMTPConnect) && $this->sendCommand('quit'); + if (is_resource($this->SMTPConnect)) { + $this->sendCommand('quit'); + } } /** diff --git a/system/Session/Handlers/MemcachedHandler.php b/system/Session/Handlers/MemcachedHandler.php index 8bdc68f554..475a1efde3 100644 --- a/system/Session/Handlers/MemcachedHandler.php +++ b/system/Session/Handlers/MemcachedHandler.php @@ -219,7 +219,9 @@ class MemcachedHandler extends BaseHandler public function close(): bool { if (isset($this->memcached)) { - isset($this->lockKey) && $this->memcached->delete($this->lockKey); + if (isset($this->lockKey)) { + $this->memcached->delete($this->lockKey); + } if (! $this->memcached->quit()) { return false; diff --git a/system/Session/Handlers/RedisHandler.php b/system/Session/Handlers/RedisHandler.php index e937fd83eb..eec6fb3079 100644 --- a/system/Session/Handlers/RedisHandler.php +++ b/system/Session/Handlers/RedisHandler.php @@ -231,7 +231,9 @@ class RedisHandler extends BaseHandler $pingReply = $this->redis->ping(); // @phpstan-ignore-next-line if (($pingReply === true) || ($pingReply === '+PONG')) { - isset($this->lockKey) && $this->redis->del($this->lockKey); + if (isset($this->lockKey)) { + $this->redis->del($this->lockKey); + } if (! $this->redis->close()) { return false; diff --git a/tests/system/Commands/CommandGeneratorTest.php b/tests/system/Commands/CommandGeneratorTest.php index 3dbfcdb96d..231914487a 100644 --- a/tests/system/Commands/CommandGeneratorTest.php +++ b/tests/system/Commands/CommandGeneratorTest.php @@ -28,8 +28,12 @@ final class CommandGeneratorTest extends CIUnitTestCase $file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14))); $dir = dirname($file); - is_file($file) && unlink($file); - is_dir($dir) && strpos($dir, 'Commands') !== false && rmdir($dir); + if (is_file($file)) { + unlink($file); + } + if (is_dir($dir) && strpos($dir, 'Commands') !== false) { + rmdir($dir); + } } protected function getFileContents(string $filepath): string diff --git a/tests/system/Commands/ConfigGeneratorTest.php b/tests/system/Commands/ConfigGeneratorTest.php index 1469ff7e72..8cb991e7e4 100644 --- a/tests/system/Commands/ConfigGeneratorTest.php +++ b/tests/system/Commands/ConfigGeneratorTest.php @@ -26,7 +26,9 @@ final class ConfigGeneratorTest extends CIUnitTestCase $result = str_replace(["\033[0;32m", "\033[0m", "\n"], '', CITestStreamFilter::$buffer); $file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14))); - is_file($file) && unlink($file); + if (is_file($file)) { + unlink($file); + } } public function testGenerateConfig() diff --git a/tests/system/Commands/ConfigurableSortImportsTest.php b/tests/system/Commands/ConfigurableSortImportsTest.php index 1c4cceeb45..788738899c 100644 --- a/tests/system/Commands/ConfigurableSortImportsTest.php +++ b/tests/system/Commands/ConfigurableSortImportsTest.php @@ -35,7 +35,9 @@ final class ConfigurableSortImportsTest extends CIUnitTestCase $this->assertStringContainsString('File created: ', CITestStreamFilter::$buffer); $this->assertFileExists($file); $this->assertNotSame(sha1_file(SUPPORTPATH . 'Commands/Foobar.php'), sha1_file($file)); - is_file($file) && unlink($file); + if (is_file($file)) { + unlink($file); + } } public function testEnabledSortImportsWillDisruptLanguageFilePublish() @@ -46,9 +48,13 @@ final class ConfigurableSortImportsTest extends CIUnitTestCase $this->assertStringContainsString('File created: ', CITestStreamFilter::$buffer); $this->assertFileExists($file); $this->assertNotSame(sha1_file(SUPPORTPATH . 'Commands/Foobar.php'), sha1_file($file)); - is_file($file) && unlink($file); + if (is_file($file)) { + unlink($file); + } $dir = dirname($file); - is_dir($dir) && rmdir($dir); + if (is_dir($dir)) { + rmdir($dir); + } } public function testDisabledSortImportsWillNotAffectLanguageFilesPublish() @@ -59,8 +65,12 @@ final class ConfigurableSortImportsTest extends CIUnitTestCase $this->assertStringContainsString('File created: ', CITestStreamFilter::$buffer); $this->assertFileExists($file); $this->assertSame(sha1_file(SUPPORTPATH . 'Commands/Foobar.php'), sha1_file($file)); - is_file($file) && unlink($file); + if (is_file($file)) { + unlink($file); + } $dir = dirname($file); - is_dir($dir) && rmdir($dir); + if (is_dir($dir)) { + rmdir($dir); + } } } diff --git a/tests/system/Commands/ControllerGeneratorTest.php b/tests/system/Commands/ControllerGeneratorTest.php index 2221ae95ca..06780051c5 100644 --- a/tests/system/Commands/ControllerGeneratorTest.php +++ b/tests/system/Commands/ControllerGeneratorTest.php @@ -26,7 +26,9 @@ final class ControllerGeneratorTest extends CIUnitTestCase $result = str_replace(["\033[0;32m", "\033[0m", "\n"], '', CITestStreamFilter::$buffer); $file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14))); - is_file($file) && unlink($file); + if (is_file($file)) { + unlink($file); + } } protected function getFileContents(string $filepath): string diff --git a/tests/system/Commands/EntityGeneratorTest.php b/tests/system/Commands/EntityGeneratorTest.php index 9489a8c9e5..267cfa0c68 100644 --- a/tests/system/Commands/EntityGeneratorTest.php +++ b/tests/system/Commands/EntityGeneratorTest.php @@ -27,8 +27,12 @@ final class EntityGeneratorTest extends CIUnitTestCase $result = str_replace(["\033[0;32m", "\033[0m", "\n"], '', CITestStreamFilter::$buffer); $file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14))); $dir = dirname($file); - is_file($file) && unlink($file); - is_dir($dir) && rmdir($dir); + if (is_file($file)) { + unlink($file); + } + if (is_dir($dir)) { + rmdir($dir); + } } public function testGenerateEntity() diff --git a/tests/system/Commands/FilterGeneratorTest.php b/tests/system/Commands/FilterGeneratorTest.php index 2f53aba8a0..c8a55b282e 100644 --- a/tests/system/Commands/FilterGeneratorTest.php +++ b/tests/system/Commands/FilterGeneratorTest.php @@ -26,7 +26,9 @@ final class FilterGeneratorTest extends CIUnitTestCase $result = str_replace(["\033[0;32m", "\033[0m", "\n"], '', CITestStreamFilter::$buffer); $file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14))); - is_file($file) && unlink($file); + if (is_file($file)) { + unlink($file); + } } public function testGenerateFilter() diff --git a/tests/system/Commands/GeneratorsTest.php b/tests/system/Commands/GeneratorsTest.php index e6ae7bdec5..3adb0fe978 100644 --- a/tests/system/Commands/GeneratorsTest.php +++ b/tests/system/Commands/GeneratorsTest.php @@ -30,7 +30,9 @@ final class GeneratorsTest extends CIUnitTestCase command('make:seeder categories'); $this->assertStringContainsString('File created: ', CITestStreamFilter::$buffer); $file = APPPATH . 'Database/Seeds/Categories.php'; - is_file($file) && unlink($file); + if (is_file($file)) { + unlink($file); + } } public function testGenerateFileExists() @@ -41,7 +43,9 @@ final class GeneratorsTest extends CIUnitTestCase command('make:filter items'); $this->assertStringContainsString('File exists: ', CITestStreamFilter::$buffer); $file = APPPATH . 'Filters/Items.php'; - is_file($file) && unlink($file); + if (is_file($file)) { + unlink($file); + } } public function testGenerateFileOverwritten() @@ -52,7 +56,9 @@ final class GeneratorsTest extends CIUnitTestCase command('make:controller products -force'); $this->assertStringContainsString('File overwritten: ', CITestStreamFilter::$buffer); $file = APPPATH . 'Controllers/Products.php'; - is_file($file) && unlink($file); + if (is_file($file)) { + unlink($file); + } } public function testGenerateFileFailsOnUnwritableDirectory() @@ -82,8 +88,12 @@ final class GeneratorsTest extends CIUnitTestCase $dir = dirname($file); $this->assertFileExists($file); $this->assertDirectoryExists($dir); - is_file($file) && unlink($file); - is_dir($dir) && rmdir($dir); + if (is_file($file)) { + unlink($file); + } + if (is_dir($dir)) { + rmdir($dir); + } } public function testSuffixingHasNoEffect(): void @@ -96,8 +106,14 @@ final class GeneratorsTest extends CIUnitTestCase $this->assertFileExists($file1); $this->assertFileDoesNotExist($file2); - is_file($file1) && unlink($file1); - is_file($file2) && unlink($file2); - is_dir($dir) && rmdir($dir); + if (is_file($file1)) { + unlink($file1); + } + if (is_file($file2)) { + unlink($file2); + } + if (is_dir($dir)) { + rmdir($dir); + } } } diff --git a/tests/system/Commands/MigrationGeneratorTest.php b/tests/system/Commands/MigrationGeneratorTest.php index 00e67ecf92..59b501c19d 100644 --- a/tests/system/Commands/MigrationGeneratorTest.php +++ b/tests/system/Commands/MigrationGeneratorTest.php @@ -26,7 +26,9 @@ final class MigrationGeneratorTest extends CIUnitTestCase $result = str_replace(["\033[0;32m", "\033[0m", "\n"], '', CITestStreamFilter::$buffer); $file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14))); - file_exists($file) && unlink($file); + if (file_exists($file)) { + unlink($file); + } } public function testGenerateMigration() diff --git a/tests/system/Commands/ModelGeneratorTest.php b/tests/system/Commands/ModelGeneratorTest.php index c57d1f2aea..dc58f6a863 100644 --- a/tests/system/Commands/ModelGeneratorTest.php +++ b/tests/system/Commands/ModelGeneratorTest.php @@ -26,7 +26,9 @@ final class ModelGeneratorTest extends CIUnitTestCase $result = str_replace(["\033[0;32m", "\033[0m", "\n"], '', CITestStreamFilter::$buffer); $file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14))); - is_file($file) && unlink($file); + if (is_file($file)) { + unlink($file); + } } protected function getFileContent(string $filepath): string @@ -93,12 +95,18 @@ final class ModelGeneratorTest extends CIUnitTestCase $file = APPPATH . 'Models/User.php'; $this->assertFileExists($file); $this->assertStringContainsString('protected $returnType = \'App\Entities\User\';', $this->getFileContent($file)); - is_file($file) && unlink($file); + if (is_file($file)) { + unlink($file); + } $file = APPPATH . 'Entities/User.php'; $this->assertFileExists($file); $dir = dirname($file); - is_file($file) && unlink($file); - is_dir($dir) && rmdir($dir); + if (is_file($file)) { + unlink($file); + } + if (is_dir($dir)) { + rmdir($dir); + } } public function testGenerateModelWithOptionSuffix() diff --git a/tests/system/Commands/SeederGeneratorTest.php b/tests/system/Commands/SeederGeneratorTest.php index d6be637fe7..fb9ecfd378 100644 --- a/tests/system/Commands/SeederGeneratorTest.php +++ b/tests/system/Commands/SeederGeneratorTest.php @@ -26,7 +26,9 @@ final class SeederGeneratorTest extends CIUnitTestCase $result = str_replace(["\033[0;32m", "\033[0m", "\n"], '', CITestStreamFilter::$buffer); $file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14))); - file_exists($file) && unlink($file); + if (file_exists($file)) { + unlink($file); + } } public function testGenerateSeeder() diff --git a/tests/system/Commands/SessionsCommandsTest.php b/tests/system/Commands/SessionsCommandsTest.php index d218911df8..1ffd447af6 100644 --- a/tests/system/Commands/SessionsCommandsTest.php +++ b/tests/system/Commands/SessionsCommandsTest.php @@ -28,7 +28,9 @@ final class SessionsCommandsTest extends CIUnitTestCase $result = str_replace(["\033[0;32m", "\033[0m", "\n"], '', CITestStreamFilter::$buffer); $file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14))); - file_exists($file) && unlink($file); + if (file_exists($file)) { + unlink($file); + } } public function testCreateMigrationCommand() diff --git a/tests/system/Commands/ValidationGeneratorTest.php b/tests/system/Commands/ValidationGeneratorTest.php index 32c9b12e6e..9f21ac97f9 100644 --- a/tests/system/Commands/ValidationGeneratorTest.php +++ b/tests/system/Commands/ValidationGeneratorTest.php @@ -27,8 +27,12 @@ final class ValidationGeneratorTest extends CIUnitTestCase $result = str_replace(["\033[0;32m", "\033[0m", "\n"], '', CITestStreamFilter::$buffer); $file = str_replace('APPPATH' . DIRECTORY_SEPARATOR, APPPATH, trim(substr($result, 14))); $dir = dirname($file); - is_file($file) && unlink($file); - is_dir($dir) && rmdir($dir); + if (is_file($file)) { + unlink($file); + } + if (is_dir($dir)) { + rmdir($dir); + } } public function testGenerateValidation() diff --git a/tests/system/HTTP/Files/FileMovingTest.php b/tests/system/HTTP/Files/FileMovingTest.php index 94ec312f00..29b19018dd 100644 --- a/tests/system/HTTP/Files/FileMovingTest.php +++ b/tests/system/HTTP/Files/FileMovingTest.php @@ -71,7 +71,9 @@ final class FileMovingTest extends CIUnitTestCase $destination = $this->destination; // Create the destination if not exists - is_dir($destination) || mkdir($destination, 0777, true); + if (!is_dir($destination)) { + mkdir($destination, 0777, true); + } foreach ($collection->all() as $file) { $this->assertInstanceOf(UploadedFile::class, $file); @@ -121,7 +123,9 @@ final class FileMovingTest extends CIUnitTestCase $destination = $this->destination; // Create the destination if not exists - is_dir($destination) || mkdir($destination, 0777, true); + if (!is_dir($destination)) { + mkdir($destination, 0777, true); + } foreach ($collection->all() as $file) { $this->assertInstanceOf(UploadedFile::class, $file); @@ -157,7 +161,9 @@ final class FileMovingTest extends CIUnitTestCase $destination = $this->destination; // Create the destination if not exists - is_dir($destination) || mkdir($destination, 0777, true); + if (!is_dir($destination)) { + mkdir($destination, 0777, true); + } $file = $collection->getFile('userfile1'); @@ -190,7 +196,9 @@ final class FileMovingTest extends CIUnitTestCase $destination = $this->destination; // Create the destination if not exists - is_dir($destination) || mkdir($destination, 0777, true); + if (!is_dir($destination)) { + mkdir($destination, 0777, true); + } $file = $collection->getFile('userfile1'); @@ -222,7 +230,9 @@ final class FileMovingTest extends CIUnitTestCase $destination = $this->destination; // Create the destination if not exists - is_dir($destination) || mkdir($destination, 0777, true); + if (!is_dir($destination)) { + mkdir($destination, 0777, true); + } $this->expectException(HTTPException::class); @@ -272,7 +282,9 @@ final class FileMovingTest extends CIUnitTestCase $destination = $this->destination; // Create the destination and make it read only - is_dir($destination) || mkdir($destination, 0400, true); + if (!is_dir($destination)) { + mkdir($destination, 0400, true); + } $collection = new FileCollection(); $file = $collection->getFile('userfile');