diff --git a/phpstan-baseline.php b/phpstan-baseline.php index e8a65036bfc0..67df1ea199ca 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -12235,12 +12235,6 @@ 'count' => 1, 'path' => __DIR__ . '/tests/system/CommonFunctionsTest.php', ]; -$ignoreErrors[] = [ - // identifier: missingType.iterableValue - 'message' => '#^Method CodeIgniter\\\\CommonFunctionsTest\\:\\:provideCleanPathActuallyCleaningThePaths\\(\\) return type has no value type specified in iterable type iterable\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/tests/system/CommonFunctionsTest.php', -]; $ignoreErrors[] = [ // identifier: codeigniter.modelArgumentType 'message' => '#^Parameter \\#1 \\$name of function model expects a valid class string, \'JobModel\' given\\.$#', @@ -13071,15 +13065,15 @@ ]; $ignoreErrors[] = [ // identifier: property.notFound - 'message' => '#^Access to an undefined property CodeIgniter\\\\Database\\\\BaseConnection\\:\\:\\$numberNative\\.$#', + 'message' => '#^Access to an undefined property CodeIgniter\\\\Database\\\\BaseConnection\\:\\:\\$foundRows\\.$#', 'count' => 2, - 'path' => __DIR__ . '/tests/system/Database/Live/MySQLi/NumberNativeTest.php', + 'path' => __DIR__ . '/tests/system/Database/Live/MySQLi/FoundRowsTest.php', ]; $ignoreErrors[] = [ // identifier: property.notFound - 'message' => '#^Access to an undefined property CodeIgniter\\\\Database\\\\BaseConnection\\:\\:\\$foundRows\\.$#', + 'message' => '#^Access to an undefined property CodeIgniter\\\\Database\\\\BaseConnection\\:\\:\\$numberNative\\.$#', 'count' => 2, - 'path' => __DIR__ . '/tests/system/Database/Live/MySQLi/FoundRowsTest.php', + 'path' => __DIR__ . '/tests/system/Database/Live/MySQLi/NumberNativeTest.php', ]; $ignoreErrors[] = [ // identifier: missingType.property diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 6892d800bf5c..e960ebecdba6 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -422,11 +422,7 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa $newPaths = []; - $namespacePaths = array_map(static function (array $paths) { - return array_map(function(string $path) { - return normalize_path($path); - }, $paths); - }, $namespacePaths); + $namespacePaths = array_map(static fn (array $paths) => array_map(static fn (string $path) => normalize_path($path), $paths), $namespacePaths); foreach ($namespacePaths as $namespace => $srcPaths) { $add = false; diff --git a/system/CLI/CLI.php b/system/CLI/CLI.php index f8c6b5941952..ca6c379a6fc8 100644 --- a/system/CLI/CLI.php +++ b/system/CLI/CLI.php @@ -324,7 +324,7 @@ public static function promptByMultipleKeys(string $text, array $options): array $optsKey[] = $key; } $extraOutput = '[' . $extraOutputDefault . ', ' . implode(', ', $optsKey) . ']'; - $extraOutput = 'You can specify multiple values separated by commas.' . "/n" . $extraOutput; + $extraOutput = 'You can specify multiple values separated by commas./n' . $extraOutput; } CLI::write($text); @@ -1098,7 +1098,7 @@ public static function table(array $tbody, array $thead = []) } // Set the columns borders - $table .= '| ' . implode(' | ', $tableRows[$row]) . ' |' . "\n"; + $table .= '| ' . implode(' | ', $tableRows[$row]) . " |\n"; // Set the thead and table borders-bottom if (($row === 0 && $thead !== []) || ($row + 1 === $totalRows)) { diff --git a/system/Commands/Translation/LocalizationFinder.php b/system/Commands/Translation/LocalizationFinder.php index 8dfd27dbb39d..41705940051d 100644 --- a/system/Commands/Translation/LocalizationFinder.php +++ b/system/Commands/Translation/LocalizationFinder.php @@ -200,7 +200,7 @@ private function findTranslationsInFile($file): array } foreach ($matches[1] as $phraseKey) { - $phraseKeys = explode('.', $phraseKey); + $phraseKeys = explode('.', $phraseKey); $realPathFile = normalize_path($file->getRealPath()); // Language key not have Filename or Lang key diff --git a/system/Commands/Utilities/ConfigCheck.php b/system/Commands/Utilities/ConfigCheck.php index f54dfde58b46..7d5748649b26 100644 --- a/system/Commands/Utilities/ConfigCheck.php +++ b/system/Commands/Utilities/ConfigCheck.php @@ -18,7 +18,6 @@ use CodeIgniter\CLI\CLI; use CodeIgniter\Config\BaseConfig; use Config\Optimize; -use Ergebnis\Json\Json; use Kint\Kint; /** diff --git a/system/Helpers/filesystem_helper.php b/system/Helpers/filesystem_helper.php index 2e8a9e262b8d..ef2e5a7b5297 100644 --- a/system/Helpers/filesystem_helper.php +++ b/system/Helpers/filesystem_helper.php @@ -306,7 +306,7 @@ function get_file_info(string $file, $returnedValues = ['name', 'server_path', ' { $file = _realpath($file); - if ($file !== false && ! is_file($file)) { + if ($file === false || ! is_file($file)) { return null; } diff --git a/system/View/View.php b/system/View/View.php index cc61dff035f8..ae64cf004f3c 100644 --- a/system/View/View.php +++ b/system/View/View.php @@ -281,9 +281,9 @@ public function render(string $view, ?array $options = null, ?bool $saveData = n $this->renderVars['file'] = clean_path($this->renderVars['file']); $this->renderVars['file'] = ++$this->viewsCount . ' ' . $this->renderVars['file']; - $output = '' . "\n" + $output = '\n" . $output . "\n" - . '' . "\n"; + . '\n"; } } diff --git a/tests/system/Autoloader/FileLocatorTest.php b/tests/system/Autoloader/FileLocatorTest.php index d3b6f14e1475..1901445c0bfe 100644 --- a/tests/system/Autoloader/FileLocatorTest.php +++ b/tests/system/Autoloader/FileLocatorTest.php @@ -231,7 +231,7 @@ public function testListFilesSimple(): void { $files = $this->locator->listFiles('Config/'); - $this->assertTrue(in_array(APPPATH . 'Config/App.php', $files, true)); + $this->assertContains(APPPATH . 'Config/App.php', $files); } public function testListFilesDoesNotContainDirectories(): void diff --git a/tests/system/CLI/CLITest.php b/tests/system/CLI/CLITest.php index 6c703b71a710..afe565b1f363 100644 --- a/tests/system/CLI/CLITest.php +++ b/tests/system/CLI/CLITest.php @@ -323,7 +323,7 @@ public function testWrite(): void { CLI::write('test'); - $expected = "\n" . 'test' . "\n"; + $expected = "\ntest\n"; $this->assertSame($expected, $this->getStreamFilterBuffer()); } @@ -331,7 +331,7 @@ public function testWriteForeground(): void { CLI::write('test', 'red'); - $expected = "\033[0;31mtest\033[0m" . "\n"; + $expected = "\033[0;31mtest\033[0m\n"; $this->assertSame($expected, $this->getStreamFilterBuffer()); } @@ -339,7 +339,7 @@ public function testWriteForegroundWithColorBefore(): void { CLI::write(CLI::color('green', 'green') . ' red', 'red'); - $expected = "\033[0;32mgreen\033[0m\033[0;31m red\033[0m" . "\n"; + $expected = "\033[0;32mgreen\033[0m\033[0;31m red\033[0m\n"; $this->assertSame($expected, $this->getStreamFilterBuffer()); } @@ -347,7 +347,7 @@ public function testWriteForegroundWithColorAfter(): void { CLI::write('red ' . CLI::color('green', 'green'), 'red'); - $expected = "\033[0;31mred \033[0m\033[0;32mgreen\033[0m" . "\n"; + $expected = "\033[0;31mred \033[0m\033[0;32mgreen\033[0m\n"; $this->assertSame($expected, $this->getStreamFilterBuffer()); } @@ -361,7 +361,7 @@ public function testWriteForegroundWithColorTwice(): void 'red' ); - $expected = "\033[0;32mgreen\033[0m\033[0;31m red \033[0m\033[0;32mgreen\033[0m" . "\n"; + $expected = "\033[0;32mgreen\033[0m\033[0;31m red \033[0m\033[0;32mgreen\033[0m\n"; $this->assertSame($expected, $this->getStreamFilterBuffer()); } @@ -369,7 +369,7 @@ public function testWriteBackground(): void { CLI::write('test', 'red', 'green'); - $expected = "\033[0;31m\033[42mtest\033[0m" . "\n"; + $expected = "\033[0;31m\033[42mtest\033[0m\n"; $this->assertSame($expected, $this->getStreamFilterBuffer()); } @@ -378,7 +378,7 @@ public function testError(): void CLI::error('test'); // red expected cuz stderr - $expected = "\033[1;31mtest\033[0m" . "\n"; + $expected = "\033[1;31mtest\033[0m\n"; $this->assertSame($expected, $this->getStreamFilterBuffer()); } @@ -386,7 +386,7 @@ public function testErrorForeground(): void { CLI::error('test', 'purple'); - $expected = "\033[0;35mtest\033[0m" . "\n"; + $expected = "\033[0;35mtest\033[0m\n"; $this->assertSame($expected, $this->getStreamFilterBuffer()); } @@ -394,7 +394,7 @@ public function testErrorBackground(): void { CLI::error('test', 'purple', 'green'); - $expected = "\033[0;35m\033[42mtest\033[0m" . "\n"; + $expected = "\033[0;35m\033[42mtest\033[0m\n"; $this->assertSame($expected, $this->getStreamFilterBuffer()); } @@ -411,16 +411,16 @@ public function testShowProgress(): void CLI::write('third.'); CLI::showProgress(1, 20); - $expected = 'first.' . "\n" . - "[\033[32m#.........\033[0m] 5% Complete" . "\n" . - "\033[1A[\033[32m#####.....\033[0m] 50% Complete" . "\n" . - "\033[1A[\033[32m##########\033[0m] 100% Complete" . "\n" . - 'second.' . "\n" . - "[\033[32m#.........\033[0m] 5% Complete" . "\n" . - "\033[1A[\033[32m#####.....\033[0m] 50% Complete" . "\n" . - "\033[1A[\033[32m##########\033[0m] 100% Complete" . "\n" . - 'third.' . "\n" . - "[\033[32m#.........\033[0m] 5% Complete" . "\n"; + $expected = "first.\n" . + "[\033[32m#.........\033[0m] 5% Complete\n" . + "\033[1A[\033[32m#####.....\033[0m] 50% Complete\n" . + "\033[1A[\033[32m##########\033[0m] 100% Complete\n" . + "second.\n" . + "[\033[32m#.........\033[0m] 5% Complete\n" . + "\033[1A[\033[32m#####.....\033[0m] 50% Complete\n" . + "\033[1A[\033[32m##########\033[0m] 100% Complete\n" . + "third.\n" . + "[\033[32m#.........\033[0m] 5% Complete\n"; $this->assertSame($expected, $this->getStreamFilterBuffer()); } @@ -431,7 +431,7 @@ public function testShowProgressWithoutBar(): void CLI::showProgress(false, 20); CLI::showProgress(false, 20); - $expected = 'first.' . "\n" . "\007\007\007"; + $expected = "first.\n\007\007\007"; $this->assertSame($expected, $this->getStreamFilterBuffer()); } @@ -439,16 +439,16 @@ public function testWrap(): void { $this->assertSame('', CLI::wrap('')); $this->assertSame( - '1234' . "\n" . ' 5678' . "\n" . ' 90' . "\n" . ' abc' . "\n" . ' de' . "\n" . ' fghij' . "\n" . ' 0987654321', - CLI::wrap('1234 5678 90' . "\n" . 'abc de fghij' . "\n" . '0987654321', 5, 1) + "1234\n 5678\n 90\n abc\n de\n fghij\n 0987654321", + CLI::wrap("1234 5678 90\nabc de fghij\n0987654321", 5, 1) ); $this->assertSame( - '1234 5678 90' . "\n" . ' abc de fghij' . "\n" . ' 0987654321', - CLI::wrap('1234 5678 90' . "\n" . 'abc de fghij' . "\n" . '0987654321', 999, 2) + "1234 5678 90\n abc de fghij\n 0987654321", + CLI::wrap("1234 5678 90\nabc de fghij\n0987654321", 999, 2) ); $this->assertSame( - '1234 5678 90' . "\n" . 'abc de fghij' . "\n" . '0987654321', - CLI::wrap('1234 5678 90' . "\n" . 'abc de fghij' . "\n" . '0987654321') + "1234 5678 90\nabc de fghij\n0987654321", + CLI::wrap("1234 5678 90\nabc de fghij\n0987654321") ); } @@ -605,38 +605,38 @@ public static function provideTable(): iterable [ $oneRow, [], - '+---+-----+' . "\n" . - '| 1 | bar |' . "\n" . - '+---+-----+' . "\n" . "\n", + "+---+-----+\n" . + "| 1 | bar |\n" . + "+---+-----+\n\n", ], [ $oneRow, $head, - '+----+-------+' . "\n" . - '| ID | Title |' . "\n" . - '+----+-------+' . "\n" . - '| 1 | bar |' . "\n" . - '+----+-------+' . "\n" . "\n", + "+----+-------+\n" . + "| ID | Title |\n" . + "+----+-------+\n" . + "| 1 | bar |\n" . + "+----+-------+\n\n", ], [ $manyRows, [], - '+---+-----------------+' . "\n" . - '| 1 | bar |' . "\n" . - '| 2 | bar * 2 |' . "\n" . - '| 3 | bar + bar + bar |' . "\n" . - '+---+-----------------+' . "\n" . "\n", + "+---+-----------------+\n" . + "| 1 | bar |\n" . + "| 2 | bar * 2 |\n" . + "| 3 | bar + bar + bar |\n" . + "+---+-----------------+\n\n", ], [ $manyRows, $head, - '+----+-----------------+' . "\n" . - '| ID | Title |' . "\n" . - '+----+-----------------+' . "\n" . - '| 1 | bar |' . "\n" . - '| 2 | bar * 2 |' . "\n" . - '| 3 | bar + bar + bar |' . "\n" . - '+----+-----------------+' . "\n" . "\n", + "+----+-----------------+\n" . + "| ID | Title |\n" . + "+----+-----------------+\n" . + "| 1 | bar |\n" . + "| 2 | bar * 2 |\n" . + "| 3 | bar + bar + bar |\n" . + "+----+-----------------+\n\n", ], // Multibyte letters [ @@ -650,11 +650,11 @@ public static function provideTable(): iterable 'ID', 'タイトル', ], - '+------+----------+' . "\n" . - '| ID | タイトル |' . "\n" . - '+------+----------+' . "\n" . - '| ほげ | bar |' . "\n" . - '+------+----------+' . "\n" . "\n", + "+------+----------+\n" . + "| ID | タイトル |\n" . + "+------+----------+\n" . + "| ほげ | bar |\n" . + "+------+----------+\n\n", ], ]; } diff --git a/tests/system/Files/FileCollectionTest.php b/tests/system/Files/FileCollectionTest.php index 9ea0bade3b83..bb390b571b31 100644 --- a/tests/system/Files/FileCollectionTest.php +++ b/tests/system/Files/FileCollectionTest.php @@ -72,7 +72,11 @@ public function testResolveDirectorySymlink(): void $this->assertSame($this->directory, $method($link)); - rmdir($link); + if (is_windows() && is_dir($link)) { + rmdir($link); + } else { + unlink($link); + } } public function testResolveFileFile(): void diff --git a/tests/system/HTTP/Files/FileMovingTest.php b/tests/system/HTTP/Files/FileMovingTest.php index 5ab7925417bf..47866d7d0e8a 100644 --- a/tests/system/HTTP/Files/FileMovingTest.php +++ b/tests/system/HTTP/Files/FileMovingTest.php @@ -382,4 +382,3 @@ function rrmdir($src): void closedir($dir); rmdir($src); } - diff --git a/tests/system/Test/BootstrapFCPATHTest.php b/tests/system/Test/BootstrapFCPATHTest.php index 582a55bd39db..e254a169ca43 100644 --- a/tests/system/Test/BootstrapFCPATHTest.php +++ b/tests/system/Test/BootstrapFCPATHTest.php @@ -89,15 +89,15 @@ private function deleteFiles(): void private function fileContents() { $fileContents = ''; - $fileContents .= 'currentDir . "' . '/../../../');" . "\n"; - $fileContents .= "define('CONFIGPATH', '" . $this->currentDir . "' . '/../../../app/Config/');" . "\n"; - $fileContents .= "define('PUBLICPATH', '" . $this->currentDir . "' . '/../../../public/');" . "\n"; - $fileContents .= "include_once '" . $this->currentDir . "' . '/../../../vendor/autoload.php';" . "\n"; - $fileContents .= "include_once '" . $this->currentDir . "' . '/../../../system/Test/bootstrap.php';" . "\n"; - $fileContents .= '// return value of FCPATH' . "\n"; - - return $fileContents . ('echo FCPATH;' . "\n"); + $fileContents .= "currentDir . "' . '/../../../');\n"; + $fileContents .= "define('CONFIGPATH', '" . $this->currentDir . "' . '/../../../app/Config/');\n"; + $fileContents .= "define('PUBLICPATH', '" . $this->currentDir . "' . '/../../../public/');\n"; + $fileContents .= "include_once '" . $this->currentDir . "' . '/../../../vendor/autoload.php';\n"; + $fileContents .= "include_once '" . $this->currentDir . "' . '/../../../system/Test/bootstrap.php';\n"; + $fileContents .= "// return value of FCPATH\n"; + + return $fileContents . ("echo FCPATH;\n"); } private function readOutput(string $file) diff --git a/tests/system/Test/TestCaseTest.php b/tests/system/Test/TestCaseTest.php index 747078d01d5c..1387f0840e1d 100644 --- a/tests/system/Test/TestCaseTest.php +++ b/tests/system/Test/TestCaseTest.php @@ -70,7 +70,7 @@ public function testEventTriggering(): void public function testStreamFilter(): void { CLI::write('first.'); - $expected = "\n" . 'first.' . "\n"; + $expected = "\nfirst.\n"; $this->assertSame($expected, $this->getStreamFilterBuffer()); }