diff --git a/bin/composer b/bin/composer index 9bb3559a4..55391b9b6 100755 --- a/bin/composer +++ b/bin/composer @@ -67,7 +67,7 @@ if (function_exists('ini_set')) { // Workaround PHP bug on Windows where env vars containing Unicode chars are mangled in $_SERVER // see https://github.com/php/php-src/issues/7896 -if (PHP_VERSION_ID >= 70113 && Platform::isWindows()) { +if (PHP_VERSION_ID >= 70113 && (PHP_VERSION_ID < 80016 || (PHP_VERSION_ID >= 80100 && PHP_VERSION_ID < 80103)) && Platform::isWindows()) { foreach ($_SERVER as $serverVar => $serverVal) { if (($serverVal = getenv($serverVar)) !== false) { $_SERVER[$serverVar] = $serverVal; diff --git a/phpstan/baseline-8.1.neon b/phpstan/baseline-8.1.neon index 4766c40fe..204c842c7 100644 --- a/phpstan/baseline-8.1.neon +++ b/phpstan/baseline-8.1.neon @@ -1,402 +1,7 @@ parameters: ignoreErrors: - - message: "#^Parameter \\#1 \\$callback of function spl_autoload_register expects \\(callable\\(string\\)\\: void\\)\\|null, array\\{\\$this\\(Composer\\\\Autoload\\\\ClassLoader\\), 'loadClass'\\} given\\.$#" - count: 1 - path: ../src/Composer/Autoload/ClassLoader.php - - - - message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, array\\\\|null given\\.$#" - count: 2 - path: ../src/Composer/Command/BaseDependencyCommand.php - - - - message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Command/ConfigCommand.php - - - - message: "#^Parameter \\#1 \\$callback of function call_user_func expects callable\\(\\)\\: mixed, array\\{Composer\\\\Config\\\\JsonConfigSource, string\\} given\\.$#" - count: 2 - path: ../src/Composer/Command/ConfigCommand.php - - - - message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Command/DiagnoseCommand.php - - - - message: "#^Parameter \\#1 \\.\\.\\.\\$arrays of function array_merge expects array, array\\\\|false given\\.$#" - count: 1 - path: ../src/Composer/Command/ExecCommand.php - - - - message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, int\\<0, max\\>\\|false given\\.$#" - count: 1 - path: ../src/Composer/Command/InitCommand.php - - - - message: "#^Parameter \\#1 \\$from of function rename expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Command/SelfUpdateCommand.php - - - - message: "#^Parameter \\#1 \\$user_id of function posix_getpwuid expects int, int\\|false given\\.$#" - count: 1 - path: ../src/Composer/Command/SelfUpdateCommand.php - - - - message: "#^Parameter \\#2 \\$permissions of function chmod expects int, int\\|false given\\.$#" - count: 1 - path: ../src/Composer/Command/SelfUpdateCommand.php - - - - message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, array\\\\>\\|string given\\.$#" - count: 1 - path: ../src/Composer/Command/ShowCommand.php - - - - message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, array\\|string given\\.$#" - count: 1 - path: ../src/Composer/Command/ShowCommand.php - - - - message: "#^Parameter \\#2 \\$callback of function uasort expects callable\\(string, string\\)\\: int, 'version_compare' given\\.$#" - count: 1 - path: ../src/Composer/Command/ShowCommand.php - - - - message: "#^Parameter \\#1 \\$callback of function call_user_func expects callable\\(\\)\\: mixed, array\\{Composer\\\\Package\\\\RootPackageInterface, 'getDevRequires'\\|'getRequires'\\} given\\.$#" - count: 1 - path: ../src/Composer/Command/ValidateCommand.php - - - - message: "#^Parameter \\#1 \\$string of function substr_replace expects array\\|string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Compiler.php - - - - message: "#^Parameter \\#1 \\$string of function rtrim expects string, int\\|string\\|null given\\.$#" - count: 1 - path: ../src/Composer/Config.php - - - - message: "#^Parameter \\#1 \\$string of function rtrim expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Config.php - - - - message: "#^Parameter \\#1 \\$callback of function call_user_func_array expects callable\\(\\)\\: mixed, array\\{Composer\\\\Json\\\\JsonManipulator, string\\} given\\.$#" - count: 1 - path: ../src/Composer/Config/JsonConfigSource.php - - - - message: "#^Parameter \\#2 \\$callback of function uksort expects callable\\(string, string\\)\\: int, 'version_compare' given\\.$#" - count: 2 - path: ../src/Composer/DependencyResolver/Problem.php - - - - message: "#^Parameter \\#1 \\$string of function trim expects string, array\\\\>\\|string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Downloader/FileDownloader.php - - - - message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/Downloader/GzipDownloader.php - - - - message: "#^Parameter \\#1 \\$stream of function fwrite expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/Downloader/GzipDownloader.php - - - - message: "#^Parameter \\#1 \\$stream of function gzclose expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/Downloader/GzipDownloader.php - - - - message: "#^Parameter \\#1 \\$stream of function gzread expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/Downloader/GzipDownloader.php - - - - message: "#^Parameter \\#3 \\$length of function fwrite expects int\\<0, max\\>\\|null, int given\\.$#" - count: 1 - path: ../src/Composer/Downloader/GzipDownloader.php - - - - message: "#^Parameter \\#1 \\$string of function rawurldecode expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Downloader/VcsDownloader.php - - - - message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, int\\<0, max\\>\\|false given\\.$#" - count: 1 - path: ../src/Composer/EventDispatcher/EventDispatcher.php - - - - message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Factory.php - - - - message: "#^Parameter \\#1 \\$stream of function fwrite expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/IO/BufferIO.php - - - - message: "#^Parameter \\#1 \\$stream of function rewind expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/IO/BufferIO.php - - - - message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/Installer/BinaryInstaller.php - - - - message: "#^Parameter \\#1 \\$stream of function fgets expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/Installer/BinaryInstaller.php - - - - message: "#^Parameter \\#1 \\$callback of function call_user_func expects callable\\(\\)\\: mixed, int\\\\|int\\<2, max\\>\\|string given\\.$#" - count: 1 - path: ../src/Composer/Installer/InstallationManager.php - - - - message: "#^Parameter \\#2 \\$handler of function pcntl_signal expects \\(callable\\(\\)\\: mixed\\)\\|int, int\\|string given\\.$#" - count: 2 - path: ../src/Composer/Installer/InstallationManager.php - - - - message: "#^Only numeric types are allowed in \\-, int\\|false given on the left side\\.$#" - count: 1 - path: ../src/Composer/Package/Archiver/PharArchiver.php - - - - message: "#^Parameter \\#2 \\$baseDirectory of method Phar\\:\\:buildFromIterator\\(\\) expects string\\|null, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Package/Archiver/PharArchiver.php - - - - message: "#^Parameter \\#1 \\$array of function ksort expects array, array\\\\|string given\\.$#" - count: 1 - path: ../src/Composer/Package/Dumper/ArrayDumper.php - - - - message: "#^Only booleans are allowed in an if condition, int\\|false given\\.$#" - count: 1 - path: ../src/Composer/Plugin/PluginManager.php - - - - message: "#^Parameter \\#1 \\$array of function array_splice expects array, array\\\\|null given\\.$#" - count: 1 - path: ../src/Composer/Repository/ArrayRepository.php - - - - message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, array\\\\|null given\\.$#" - count: 1 - path: ../src/Composer/Repository/ArrayRepository.php - - - - message: "#^Parameter \\#1 \\$array of function array_keys expects array, array\\\\>\\|null given\\.$#" - count: 1 - path: ../src/Composer/Repository/ComposerRepository.php - - - - message: "#^Parameter \\#1 \\$array of function array_values expects array, array\\\\|null given\\.$#" - count: 1 - path: ../src/Composer/Repository/ComposerRepository.php - - - - message: "#^Parameter \\#1 \\$value of function count expects array\\|Countable, array\\\\|null given\\.$#" - count: 1 - path: ../src/Composer/Repository/ComposerRepository.php - - - - message: "#^Parameter \\#2 \\$string of function explode expects string, string\\|null given\\.$#" - count: 1 - path: ../src/Composer/Repository/Vcs/GitLabDriver.php - - - - message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/SelfUpdate/Versions.php - - - - message: "#^Parameter \\#2 \\$string of function explode expects string, string\\|false\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/AuthHelper.php - - - - message: "#^Parameter \\#1 \\$from of function stream_copy_to_stream expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/Util/Filesystem.php - - - - message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#" - count: 4 - path: ../src/Composer/Util/Filesystem.php - - - - message: "#^Parameter \\#1 \\$stream of function feof expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/Util/Filesystem.php - - - - message: "#^Parameter \\#1 \\$stream of function fread expects resource, resource\\|false given\\.$#" - count: 2 - path: ../src/Composer/Util/Filesystem.php - - - - message: "#^Parameter \\#2 \\$to of function stream_copy_to_stream expects resource, resource\\|false given\\.$#" - count: 1 - path: ../src/Composer/Util/Filesystem.php - - - - message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, string\\|null given\\.$#" - count: 17 - path: ../src/Composer/Util/Git.php - - - - message: "#^Parameter \\#1 \\$string of function trim expects string, string\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/GitHub.php - - - - message: "#^Parameter \\#1 \\$string of function rawurlencode expects string, string\\|null given\\.$#" - count: 2 - path: ../src/Composer/Util/Hg.php - - - - message: "#^Parameter \\#1 \\$handle of function curl_close expects CurlHandle, resource given\\.$#" + message: "#^Property Composer\\\\Util\\\\Http\\\\CurlDownloader\\:\\:\\$jobs \\(array\\\\) does not accept non\\-empty\\-array\\, options\\: array, progress\\: array, curlHandle\\: CurlHandle\\|resource, filename\\: string\\|false\\|null, headerHandle\\: resource, \\.\\.\\.\\}\\>\\.$#" count: 1 path: ../src/Composer/Util/Http/CurlDownloader.php - - - message: "#^Parameter \\#1 \\$handle of function curl_getinfo expects CurlHandle, resource given\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Parameter \\#1 \\$haystack of function strpos expects string, string\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Parameter \\#1 \\$multi_handle of function curl_multi_add_handle expects CurlMultiHandle, resource\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Parameter \\#1 \\$multi_handle of function curl_multi_exec expects CurlMultiHandle, resource\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Parameter \\#1 \\$multi_handle of function curl_multi_info_read expects CurlMultiHandle, resource\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Parameter \\#1 \\$multi_handle of function curl_multi_remove_handle expects CurlMultiHandle, resource\\|null given\\.$#" - count: 2 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Parameter \\#1 \\$multi_handle of function curl_multi_select expects CurlMultiHandle, resource\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Parameter \\#1 \\$string of function rtrim expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Parameter \\#1 \\$string of function strtolower expects string, string\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Parameter \\#2 \\$handle of function curl_multi_remove_handle expects CurlHandle, resource given\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Property Composer\\\\Util\\\\Http\\\\CurlDownloader\\:\\:\\$jobs \\(array\\\\) does not accept non\\-empty\\-array\\, options\\: array, progress\\: array, curlHandle\\: CurlHandle\\|resource, filename\\: string\\|false\\|null, headerHandle\\: resource\\|false, \\.\\.\\.\\}\\>\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Property Composer\\\\Util\\\\Http\\\\CurlDownloader\\:\\:\\$multiHandle \\(resource\\|null\\) does not accept CurlMultiHandle\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Property Composer\\\\Util\\\\Http\\\\CurlDownloader\\:\\:\\$shareHandle \\(resource\\|null\\) does not accept CurlShareHandle\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, int\\<0, max\\>\\|false given\\.$#" - count: 1 - path: ../src/Composer/Util/NoProxyPattern.php - - - - message: "#^Parameter \\#1 \\$stream of function fclose expects resource, resource\\|false given\\.$#" - count: 2 - path: ../src/Composer/Util/Perforce.php - - - - message: "#^Parameter \\#1 \\$stream of function fwrite expects resource, resource\\|false given\\.$#" - count: 13 - path: ../src/Composer/Util/Perforce.php - - - - message: "#^Parameter \\#1 \\$string1 of function strcmp expects string, string\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/Perforce.php - - - - message: "#^Parameter \\#2 \\$needle of function strpos expects string, string\\|null given\\.$#" - count: 1 - path: ../src/Composer/Util/Perforce.php - - - - message: "#^Parameter \\#3 \\$length of function substr expects int\\|null, int\\<0, max\\>\\|false given\\.$#" - count: 1 - path: ../src/Composer/Util/Perforce.php - - - - message: "#^Parameter \\#1 \\$string of function base64_encode expects string, string\\|false given\\.$#" - count: 1 - path: ../src/Composer/Util/RemoteFilesystem.php - - - - message: "#^Parameter \\#5 \\$length of function file_get_contents expects int\\<0, max\\>\\|null, int given\\.$#" - count: 1 - path: ../src/Composer/Util/RemoteFilesystem.php - - - - message: "#^Parameter \\#1 \\$include_path of function set_include_path expects string, string\\|false given\\.$#" - count: 2 - path: ../tests/Composer/Test/Autoload/AutoloadGeneratorTest.php - - - - message: "#^Parameter \\#1 \\$string of function rtrim expects string, string\\|false given\\.$#" - count: 2 - path: ../tests/Composer/Test/ConfigTest.php - - - - message: "#^Parameter \\#1 \\$callback of function call_user_func_array expects callable\\(\\)\\: mixed, array\\{Composer\\\\Repository\\\\CompositeRepository, string\\} given\\.$#" - count: 1 - path: ../tests/Composer/Test/Repository/CompositeRepositoryTest.php - - - - message: "#^Parameter \\#1 \\$object of method ReflectionProperty\\:\\:getValue\\(\\) expects object\\|null, object\\|string given\\.$#" - count: 1 - path: ../tests/Composer/Test/Util/RemoteFilesystemTest.php - diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index 4ade76930..03cf82999 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -2450,11 +2450,6 @@ parameters: count: 1 path: ../src/Composer/Config.php - - - message: "#^Property Composer\\\\Config\\:\\:\\$warnedHosts \\(array\\\\) does not accept non\\-empty\\-array\\<0\\|string, true\\>\\.$#" - count: 1 - path: ../src/Composer/Config.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 2 @@ -2925,11 +2920,6 @@ parameters: count: 1 path: ../src/Composer/DependencyResolver/RuleSet.php - - - message: "#^Property Composer\\\\DependencyResolver\\\\RuleSet\\:\\:\\$rulesByHash \\(array\\\\|Composer\\\\DependencyResolver\\\\Rule\\>\\) does not accept array\\\\|Composer\\\\DependencyResolver\\\\Rule\\>\\.$#" - count: 3 - path: ../src/Composer/DependencyResolver/RuleSet.php - - message: "#^Only booleans are allowed in a negated boolean, Composer\\\\DependencyResolver\\\\Rule\\|null given\\.$#" count: 1 @@ -2980,16 +2970,6 @@ parameters: count: 1 path: ../src/Composer/DependencyResolver/Solver.php - - - message: "#^Casting to int something that's already int\\.$#" - count: 1 - path: ../src/Composer/DependencyResolver/Solver.php - - - - message: "#^Casting to int\\\\|int\\<2, max\\> something that's already int\\\\|int\\<2, max\\>\\.$#" - count: 1 - path: ../src/Composer/DependencyResolver/Solver.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 2 @@ -3005,11 +2985,6 @@ parameters: count: 1 path: ../src/Composer/DependencyResolver/Solver.php - - - message: "#^Only booleans are allowed in &&, int\\<0, max\\> given on the left side\\.$#" - count: 1 - path: ../src/Composer/DependencyResolver/Solver.php - - message: "#^Only booleans are allowed in &&, int\\<0, max\\> given on the right side\\.$#" count: 2 @@ -3032,11 +3007,6 @@ parameters: - message: "#^Only booleans are allowed in a negated boolean, int given\\.$#" - count: 2 - path: ../src/Composer/DependencyResolver/Solver.php - - - - message: "#^Only booleans are allowed in a negated boolean, int\\<0, max\\> given\\.$#" count: 1 path: ../src/Composer/DependencyResolver/Solver.php @@ -3875,11 +3845,6 @@ parameters: count: 1 path: ../src/Composer/IO/BaseIO.php - - - message: "#^Property Composer\\\\IO\\\\BaseIO\\:\\:\\$authentications \\(array\\\\) does not accept non\\-empty\\-array\\\\.$#" - count: 1 - path: ../src/Composer/IO/BaseIO.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 6 @@ -4030,11 +3995,6 @@ parameters: count: 1 path: ../src/Composer/Installer.php - - - message: "#^Only booleans are allowed in an if condition, int\\<0, max\\> given\\.$#" - count: 1 - path: ../src/Composer/Installer.php - - message: "#^Only booleans are allowed in \\|\\|, array\\\\|null given on the left side\\.$#" count: 2 @@ -4110,11 +4070,6 @@ parameters: count: 2 path: ../src/Composer/Installer/InstallationManager.php - - - message: "#^Constant PHP_WINDOWS_EVENT_CTRL_C not found\\.$#" - count: 1 - path: ../src/Composer/Installer/InstallationManager.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 @@ -4125,11 +4080,6 @@ parameters: count: 2 path: ../src/Composer/Installer/InstallationManager.php - - - message: "#^Function sapi_windows_set_ctrl_handler not found\\.$#" - count: 3 - path: ../src/Composer/Installer/InstallationManager.php - - message: "#^Only booleans are allowed in &&, Composer\\\\EventDispatcher\\\\EventDispatcher\\|null given on the right side\\.$#" count: 2 @@ -4325,11 +4275,6 @@ parameters: count: 1 path: ../src/Composer/Json/JsonFile.php - - - message: "#^Only booleans are allowed in an if condition, int\\ given\\.$#" - count: 1 - path: ../src/Composer/Json/JsonFile.php - - message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#" count: 1 @@ -4480,11 +4425,6 @@ parameters: count: 1 path: ../src/Composer/Package/BasePackage.php - - - message: "#^Offset 'string' does not exist on array\\{added\\?\\: array\\, changed\\?\\: array\\, removed\\?\\: array\\, string\\?\\: non\\-empty\\-array\\\\}\\.$#" - count: 1 - path: ../src/Composer/Package/Comparer/Comparer.php - - message: "#^Only booleans are allowed in &&, int\\<0, max\\>\\|false given on the right side\\.$#" count: 1 @@ -5040,31 +4980,16 @@ parameters: count: 1 path: ../src/Composer/Plugin/PluginManager.php - - - message: "#^Parameter \\#1 \\$installer of method Composer\\\\Installer\\\\InstallationManager\\:\\:addInstaller\\(\\) expects Composer\\\\Installer\\\\InstallerInterface, object given\\.$#" - count: 1 - path: ../src/Composer/Plugin/PluginManager.php - - message: "#^Parameter \\#1 \\$path of function dirname expects string, string\\|false given\\.$#" count: 1 path: ../src/Composer/Plugin/PluginManager.php - - - message: "#^Parameter \\#1 \\$plugin of method Composer\\\\Plugin\\\\PluginManager\\:\\:addPlugin\\(\\) expects Composer\\\\Plugin\\\\PluginInterface, object given\\.$#" - count: 1 - path: ../src/Composer/Plugin/PluginManager.php - - message: "#^Parameter \\#3 \\$subject of static method Composer\\\\Pcre\\\\Preg\\:\\:replace\\(\\) expects string, string\\|false given\\.$#" count: 1 path: ../src/Composer/Plugin/PluginManager.php - - - message: "#^Property Composer\\\\Plugin\\\\PluginManager\\:\\:\\$registeredPlugins \\(array\\\\) does not accept array\\\\.$#" - count: 2 - path: ../src/Composer/Plugin/PluginManager.php - - message: "#^Property Composer\\\\Plugin\\\\PostFileDownloadEvent\\:\\:\\$fileName \\(string\\) does not accept string\\|null\\.$#" count: 1 @@ -5105,11 +5030,6 @@ parameters: count: 1 path: ../src/Composer/Repository/ArrayRepository.php - - - message: "#^Property Composer\\\\Repository\\\\ArrayRepository\\:\\:\\$packages \\(array\\\\|null\\) does not accept array\\\\.$#" - count: 1 - path: ../src/Composer/Repository/ArrayRepository.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 1 @@ -5125,11 +5045,6 @@ parameters: count: 1 path: ../src/Composer/Repository/ArtifactRepository.php - - - message: "#^Argument of an invalid type array\\\\|null supplied for foreach, only iterables are supported\\.$#" - count: 1 - path: ../src/Composer/Repository/ComposerRepository.php - - message: "#^Cannot access offset 'path' on array\\{scheme\\?\\: string, host\\?\\: string, port\\?\\: int, user\\?\\: string, pass\\?\\: string, path\\?\\: string, query\\?\\: string, fragment\\?\\: string\\}\\|false\\.$#" count: 1 @@ -5270,11 +5185,6 @@ parameters: count: 1 path: ../src/Composer/Repository/ComposerRepository.php - - - message: "#^Only booleans are allowed in an if condition, int\\ given\\.$#" - count: 1 - path: ../src/Composer/Repository/ComposerRepository.php - - message: "#^Only booleans are allowed in an if condition, string\\|false given\\.$#" count: 3 @@ -5295,11 +5205,6 @@ parameters: count: 1 path: ../src/Composer/Repository/ComposerRepository.php - - - message: "#^Parameter \\#1 \\$input of function array_values expects array, array\\\\|null given\\.$#" - count: 1 - path: ../src/Composer/Repository/ComposerRepository.php - - message: "#^Parameter \\#1 \\$json of function json_decode expects string, string\\|false given\\.$#" count: 3 @@ -5310,11 +5215,6 @@ parameters: count: 1 path: ../src/Composer/Repository/ComposerRepository.php - - - message: "#^Property Composer\\\\Repository\\\\ComposerRepository\\:\\:\\$partialPackagesByName \\(array\\\\|null\\) does not accept array\\\\|Composer\\\\Package\\\\PackageInterface\\>\\.$#" - count: 1 - path: ../src/Composer/Repository/ComposerRepository.php - - message: "#^Only booleans are allowed in a ternary operator condition, array\\\\> given\\.$#" count: 3 @@ -5775,16 +5675,6 @@ parameters: count: 1 path: ../src/Composer/Repository/Vcs/GitDriver.php - - - message: "#^Property Composer\\\\Repository\\\\Vcs\\\\GitDriver\\:\\:\\$branches \\(array\\\\) does not accept array\\\\.$#" - count: 1 - path: ../src/Composer/Repository/Vcs/GitDriver.php - - - - message: "#^Property Composer\\\\Repository\\\\Vcs\\\\GitDriver\\:\\:\\$tags \\(array\\\\) does not accept array\\\\.$#" - count: 1 - path: ../src/Composer/Repository/Vcs/GitDriver.php - - message: "#^Call to function array_search\\(\\) requires parameter \\#3 to be set\\.$#" count: 2 @@ -5965,11 +5855,6 @@ parameters: count: 1 path: ../src/Composer/Repository/Vcs/GitLabDriver.php - - - message: "#^Property Composer\\\\Repository\\\\Vcs\\\\GitLabDriver\\:\\:\\$commits \\(array\\\\) does not accept array\\\\.$#" - count: 1 - path: ../src/Composer/Repository/Vcs/GitLabDriver.php - - message: "#^Property Composer\\\\Repository\\\\Vcs\\\\VcsDriver\\:\\:\\$originUrl \\(string\\) does not accept string\\|false\\.$#" count: 1 @@ -6590,16 +6475,6 @@ parameters: count: 2 path: ../src/Composer/Util/Http/CurlDownloader.php - - - message: "#^Constant CURLOPT_PROXY_CAINFO not found\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - - - message: "#^Constant CURLOPT_PROXY_CAPATH not found\\.$#" - count: 1 - path: ../src/Composer/Util/Http/CurlDownloader.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 3 @@ -6776,7 +6651,7 @@ parameters: path: ../src/Composer/Util/Http/CurlDownloader.php - - message: "#^Property Composer\\\\Util\\\\Http\\\\CurlDownloader\\:\\:\\$jobs \\(array\\\\) does not accept non\\-empty\\-array\\, options\\: array, progress\\: array, curlHandle\\: resource, filename\\: string\\|false\\|null, headerHandle\\: resource\\|false, \\.\\.\\.\\}\\>\\.$#" + message: "#^Property Composer\\\\Util\\\\Http\\\\CurlDownloader\\:\\:\\$jobs \\(array\\\\) does not accept non\\-empty\\-array\\, options\\: array, progress\\: array, curlHandle\\: resource, filename\\: string\\|false\\|null, headerHandle\\: resource, \\.\\.\\.\\}\\>\\.$#" count: 1 path: ../src/Composer/Util/Http/CurlDownloader.php @@ -7005,11 +6880,6 @@ parameters: count: 2 path: ../src/Composer/Util/Loop.php - - - message: "#^Cannot access offset int\\<1, 16\\> on array\\|false\\.$#" - count: 6 - path: ../src/Composer/Util/NoProxyPattern.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 2 @@ -7415,36 +7285,6 @@ parameters: count: 1 path: ../src/Composer/Util/Svn.php - - - message: "#^Property Composer\\\\Util\\\\Svn\\:\\:\\$credentials \\(array\\{username\\: string, password\\: string\\}\\|null\\) does not accept array\\{username\\: mixed, password\\?\\: string\\}\\.$#" - count: 1 - path: ../src/Composer/Util/Svn.php - - - - message: "#^Property Composer\\\\Util\\\\Svn\\:\\:\\$credentials \\(array\\{username\\: string, password\\: string\\}\\|null\\) does not accept array\\{username\\: non\\-empty\\-string, password\\?\\: string\\}\\.$#" - count: 1 - path: ../src/Composer/Util/Svn.php - - - - message: "#^Property Composer\\\\Util\\\\Svn\\:\\:\\$credentials \\(array\\{username\\: string, password\\: string\\}\\|null\\) does not accept array\\{username\\: string\\|null, password\\?\\: string\\}\\.$#" - count: 1 - path: ../src/Composer/Util/Svn.php - - - - message: "#^Property Composer\\\\Util\\\\Svn\\:\\:\\$credentials \\(array\\{username\\: string, password\\: string\\}\\|null\\) does not accept array\\{username\\?\\: string, password\\: mixed\\}\\.$#" - count: 1 - path: ../src/Composer/Util/Svn.php - - - - message: "#^Property Composer\\\\Util\\\\Svn\\:\\:\\$credentials \\(array\\{username\\: string, password\\: string\\}\\|null\\) does not accept array\\{username\\?\\: string, password\\: string\\|null\\}\\.$#" - count: 1 - path: ../src/Composer/Util/Svn.php - - - - message: "#^Property Composer\\\\Util\\\\Svn\\:\\:\\$credentials \\(array\\{username\\: string, password\\: string\\}\\|null\\) does not accept array\\{username\\?\\: string, password\\: string\\}\\.$#" - count: 1 - path: ../src/Composer/Util/Svn.php - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 1 @@ -7965,11 +7805,6 @@ parameters: count: 1 path: ../tests/Composer/Test/EventDispatcher/EventDispatcherTest.php - - - message: "#^Call to function is_array\\(\\) with array\\ will always evaluate to true\\.$#" - count: 1 - path: ../tests/Composer/Test/IO/NullIOTest.php - - message: """ #^Call to deprecated method getRawData\\(\\) of class Composer\\\\InstalledVersions\\: @@ -8353,11 +8188,6 @@ parameters: count: 2 path: ../tests/Composer/Test/Plugin/PluginInstallerTest.php - - - message: "#^Property Composer\\\\Test\\\\Plugin\\\\PluginInstallerTest\\:\\:\\$packages \\(array\\\\) does not accept array\\\\.$#" - count: 1 - path: ../tests/Composer/Test/Plugin/PluginInstallerTest.php - - message: "#^Unable to resolve the template type CapabilityClass in call to method Composer\\\\Plugin\\\\PluginManager\\:\\:getPluginCapability\\(\\)$#" count: 2 diff --git a/src/Composer/Command/SelfUpdateCommand.php b/src/Composer/Command/SelfUpdateCommand.php index 424940e30..59f8ef416 100644 --- a/src/Composer/Command/SelfUpdateCommand.php +++ b/src/Composer/Command/SelfUpdateCommand.php @@ -472,6 +472,7 @@ TAGSPUBKEY return $this->tryAsWindowsAdmin($localFilename, $newFilename); } + @unlink($newFilename); $action = 'Composer '.($backupTarget ? 'update' : 'rollback'); throw new FilesystemException($action.' failed: "'.$localFilename.'" could not be written.'.PHP_EOL.$e->getMessage()); } @@ -624,7 +625,7 @@ EOT; exec('"'.$script.'"'); @unlink($script); - // see if the file was moved and is still accessible + // see if the file was copied and is still accessible if ($result = Filesystem::isReadable($localFilename) && (hash_file('sha256', $localFilename) === $checksum)) { $io->writeError('Operation succeeded.'); @unlink($newFilename); diff --git a/src/Composer/Config.php b/src/Composer/Config.php index af2b2edc3..06abf6ad0 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -604,10 +604,12 @@ class Config } if ($io) { $host = parse_url($url, PHP_URL_HOST); - if (!isset($this->warnedHosts[$host])) { - $io->writeError("Warning: Accessing $host over $scheme which is an insecure protocol."); + if (is_string($host)) { + if (!isset($this->warnedHosts[$host])) { + $io->writeError("Warning: Accessing $host over $scheme which is an insecure protocol."); + } + $this->warnedHosts[$host] = true; } - $this->warnedHosts[$host] = true; } } } diff --git a/src/Composer/DependencyResolver/RuleSet.php b/src/Composer/DependencyResolver/RuleSet.php index 47868178f..d83320c52 100644 --- a/src/Composer/DependencyResolver/RuleSet.php +++ b/src/Composer/DependencyResolver/RuleSet.php @@ -45,7 +45,7 @@ class RuleSet implements \IteratorAggregate, \Countable /** @var int */ protected $nextRuleId = 0; - /** @var array */ + /** @var array */ protected $rulesByHash = array(); public function __construct() diff --git a/src/Composer/DependencyResolver/Solver.php b/src/Composer/DependencyResolver/Solver.php index 28b9e40da..b0a3eb00f 100644 --- a/src/Composer/DependencyResolver/Solver.php +++ b/src/Composer/DependencyResolver/Solver.php @@ -324,7 +324,7 @@ class Solver if ($newLevel <= 0 || $newLevel >= $level) { throw new SolverBugException( - "Trying to revert to invalid level ".(int) $newLevel." from level ".(int) $level."." + "Trying to revert to invalid level ".$newLevel." from level ".$level."." ); } @@ -423,7 +423,7 @@ class Solver while ($l1retry) { $l1retry = false; - if (!$num && !--$l1num) { + if (0 === $num && 0 === --$l1num) { // all level 1 literals done break 2; } @@ -447,7 +447,7 @@ class Solver unset($seen[abs($literal)]); - if ($num && 0 === --$num) { + if (0 !== $num && 0 === --$num) { if ($literal < 0) { $this->testFlagLearnedPositiveLiteral = true; } diff --git a/src/Composer/IO/BaseIO.php b/src/Composer/IO/BaseIO.php index 33cc14eef..7c951f2c6 100644 --- a/src/Composer/IO/BaseIO.php +++ b/src/Composer/IO/BaseIO.php @@ -19,7 +19,7 @@ use Psr\Log\LogLevel; abstract class BaseIO implements IOInterface { - /** @var array */ + /** @var array */ protected $authentications = array(); /** diff --git a/src/Composer/IO/IOInterface.php b/src/Composer/IO/IOInterface.php index cf19321c2..4650e1ed9 100644 --- a/src/Composer/IO/IOInterface.php +++ b/src/Composer/IO/IOInterface.php @@ -198,7 +198,7 @@ interface IOInterface extends LoggerInterface /** * Get all authentication information entered. * - * @return array The map of authentication data + * @return array The map of authentication data */ public function getAuthentications(); diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index c4571ef85..8bd88e5b9 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -354,7 +354,7 @@ class Installer $fundingCount++; } } - if ($fundingCount) { + if ($fundingCount > 0) { $this->io->writeError(array( sprintf( "%d package%s you are using %s looking for funding.", diff --git a/src/Composer/Installer/BinaryInstaller.php b/src/Composer/Installer/BinaryInstaller.php index 03bd0839f..7d5db0d2b 100644 --- a/src/Composer/Installer/BinaryInstaller.php +++ b/src/Composer/Installer/BinaryInstaller.php @@ -77,6 +77,10 @@ class BinaryInstaller $this->io->writeError(' Skipped installation of bin '.$bin.' for package '.$package->getName().': file not found in package'); continue; } + if (is_dir($binPath)) { + $this->io->writeError(' Skipped installation of bin '.$bin.' for package '.$package->getName().': found a directory at that path'); + continue; + } if (!$this->filesystem->isAbsolutePath($binPath)) { // in case a custom installer returned a relative path for the // $package, we can now safely turn it into a absolute path (as we @@ -333,6 +337,16 @@ if (PHP_VERSION_ID < 80000) { return \$operation ? flock(\$this->handle, \$operation) : true; } + public function stream_seek(\$offset, \$whence) + { + if (0 === fseek(\$this->handle, \$offset, \$whence)) { + \$this->position = ftell(\$this->handle); + return true; + } + + return false; + } + public function stream_tell() { return \$this->position; diff --git a/src/Composer/Json/JsonFile.php b/src/Composer/Json/JsonFile.php index 9171048e9..35661c925 100644 --- a/src/Composer/Json/JsonFile.php +++ b/src/Composer/Json/JsonFile.php @@ -152,7 +152,7 @@ class JsonFile $this->filePutContentsIfModified($this->path, static::encode($hash, $options). ($options & JSON_PRETTY_PRINT ? "\n" : '')); break; } catch (\Exception $e) { - if ($retries) { + if ($retries > 0) { usleep(500000); continue; } diff --git a/src/Composer/Package/Comparer/Comparer.php b/src/Composer/Package/Comparer/Comparer.php index 06ebf7daa..b24661ad3 100644 --- a/src/Composer/Package/Comparer/Comparer.php +++ b/src/Composer/Package/Comparer/Comparer.php @@ -67,12 +67,13 @@ class Comparer } if ($toString) { + $strings = array(); foreach ($changed as $sectionKey => $itemSection) { foreach ($itemSection as $itemKey => $item) { - $changed['string'][] = $item."\r\n"; + $strings[] = $item."\r\n"; } } - $changed = implode("\r\n", $changed['string']); + $changed = implode("\r\n", $strings); } return $changed; diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index f7f677e1b..bc4a14139 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -113,12 +113,15 @@ class ArrayLoader implements LoaderInterface if (!isset($config['name'])) { throw new \UnexpectedValueException('Unknown package has no name defined ('.json_encode($config).').'); } - if (!isset($config['version'])) { + if (!isset($config['version']) || !is_scalar($config['version'])) { throw new \UnexpectedValueException('Package '.$config['name'].' has no version defined.'); } + if (!is_string($config['version'])) { + $config['version'] = (string) $config['version']; + } // handle already normalized versions - if (isset($config['version_normalized'])) { + if (isset($config['version_normalized']) && is_string($config['version_normalized'])) { $version = $config['version_normalized']; // handling of existing repos which need to remain composer v1 compatible, in case the version_normalized contained VersionParser::DEFAULT_BRANCH_ALIAS, we renormalize it diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 3b180139d..7fb2c3b79 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -71,11 +71,18 @@ class ValidatingArrayLoader implements LoaderInterface } if (!empty($this->config['version'])) { - try { - $this->versionParser->normalize($this->config['version']); - } catch (\Exception $e) { - $this->errors[] = 'version : invalid value ('.$this->config['version'].'): '.$e->getMessage(); - unset($this->config['version']); + if (!is_scalar($this->config['version'])) { + $this->validateString('version'); + } else { + if (!is_string($this->config['version'])) { + $this->config['version'] = (string) $this->config['version']; + } + try { + $this->versionParser->normalize($this->config['version']); + } catch (\Exception $e) { + $this->errors[] = 'version : invalid value ('.$this->config['version'].'): '.$e->getMessage(); + unset($this->config['version']); + } } } diff --git a/src/Composer/Package/Version/VersionGuesser.php b/src/Composer/Package/Version/VersionGuesser.php index fbf695a36..7927fa726 100644 --- a/src/Composer/Package/Version/VersionGuesser.php +++ b/src/Composer/Package/Version/VersionGuesser.php @@ -251,7 +251,7 @@ class VersionGuesser // re-use the HgDriver to fetch branches (this properly includes bookmarks) $io = new NullIO(); $driver = new HgDriver(array('url' => $path), $io, $this->config, new HttpDownloader($io, $this->config), $this->process); - $branches = array_keys($driver->getBranches()); + $branches = array_map('strval', array_keys($driver->getBranches())); // try to find the best (nearest) version branch to assume this feature's version $result = $this->guessFeatureVersion($packageConfig, $version, $branches, 'hg log -r "not ancestors(\'%candidate%\') and ancestors(\'%branch%\')" --template "{node}\\n"', $path); diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index 3f05d97bd..2950479ef 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -14,6 +14,7 @@ namespace Composer\Plugin; use Composer\Composer; use Composer\EventDispatcher\EventSubscriberInterface; +use Composer\Installer\InstallerInterface; use Composer\IO\IOInterface; use Composer\Package\BasePackage; use Composer\Package\CompletePackage; @@ -50,7 +51,7 @@ class PluginManager /** @var array */ protected $plugins = array(); - /** @var array */ + /** @var array */ protected $registeredPlugins = array(); /** @@ -284,11 +285,17 @@ class PluginManager } if ($oldInstallerPlugin) { + if (!is_a($class, 'Composer\Installer\InstallerInterface', true)) { + throw new \RuntimeException('Could not activate plugin "'.$package->getName().'" as "'.$class.'" does not implement Composer\Installer\InstallerInterface'); + } $this->io->writeError('Loading "'.$package->getName() . '" '.($isGlobalPlugin ? '(installed globally) ' : '').'which is a legacy composer-installer built for Composer 1.x, it is likely to cause issues as you are running Composer 2.x.'); $installer = new $class($this->io, $this->composer); $this->composer->getInstallationManager()->addInstaller($installer); $this->registeredPlugins[$package->getName()] = $installer; } elseif (class_exists($class)) { + if (!is_a($class, 'Composer\Plugin\PluginInterface', true)) { + throw new \RuntimeException('Could not activate plugin "'.$package->getName().'" as "'.$class.'" does not implement Composer\Plugin\PluginInterface'); + } $plugin = new $class(); $this->addPlugin($plugin, $isGlobalPlugin, $package); $this->registeredPlugins[$package->getName()] = $plugin; @@ -316,20 +323,15 @@ class PluginManager return; } - $oldInstallerPlugin = ($package->getType() === 'composer-installer'); - if (!isset($this->registeredPlugins[$package->getName()])) { return; } - if ($oldInstallerPlugin) { - /** @var \Composer\Installer\InstallerInterface $installer */ - $installer = $this->registeredPlugins[$package->getName()]; - unset($this->registeredPlugins[$package->getName()]); - $this->composer->getInstallationManager()->removeInstaller($installer); + $plugin = $this->registeredPlugins[$package->getName()]; + unset($this->registeredPlugins[$package->getName()]); + if ($plugin instanceof InstallerInterface) { + $this->composer->getInstallationManager()->removeInstaller($plugin); } else { - $plugin = $this->registeredPlugins[$package->getName()]; - unset($this->registeredPlugins[$package->getName()]); $this->removePlugin($plugin); } } @@ -352,16 +354,14 @@ class PluginManager return; } - $oldInstallerPlugin = ($package->getType() === 'composer-installer'); - if (!isset($this->registeredPlugins[$package->getName()])) { return; } - if ($oldInstallerPlugin) { + $plugin = $this->registeredPlugins[$package->getName()]; + if ($plugin instanceof InstallerInterface) { $this->deactivatePackage($package); } else { - $plugin = $this->registeredPlugins[$package->getName()]; unset($this->registeredPlugins[$package->getName()]); $this->removePlugin($plugin); $this->uninstallPlugin($plugin); @@ -699,6 +699,10 @@ class PluginManager } } + if ($package === 'composer/package-versions-deprecated') { + return false; + } + if (!isset($warned[$package])) { if ($this->io->isInteractive()) { $composer = $isGlobalPlugin && $this->globalComposer !== null ? $this->globalComposer : $this->composer; diff --git a/src/Composer/Repository/ArrayRepository.php b/src/Composer/Repository/ArrayRepository.php index 03e5fd819..518616445 100644 --- a/src/Composer/Repository/ArrayRepository.php +++ b/src/Composer/Repository/ArrayRepository.php @@ -210,12 +210,13 @@ class ArrayRepository implements RepositoryInterface /** * Adds a new package to the repository * - * @param PackageInterface $package - * * @return void */ public function addPackage(PackageInterface $package) { + if (!$package instanceof BasePackage) { + throw new \InvalidArgumentException('Only subclasses of BasePackage are supported'); + } if (null === $this->packages) { $this->initialize(); } diff --git a/src/Composer/Repository/ArtifactRepository.php b/src/Composer/Repository/ArtifactRepository.php index 715075dea..e8140162c 100644 --- a/src/Composer/Repository/ArtifactRepository.php +++ b/src/Composer/Repository/ArtifactRepository.php @@ -79,7 +79,7 @@ class ArtifactRepository extends ArrayRepository implements ConfigurableReposito $directory = new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS); $iterator = new \RecursiveIteratorIterator($directory); - $regex = new \RegexIterator($iterator, '/^.+\.(zip|phar|tar|gz|tgz)$/i'); + $regex = new \RegexIterator($iterator, '/^.+\.(zip|tar|gz|tgz)$/i'); foreach ($regex as $file) { /* @var $file \SplFileInfo */ if (!$file->isFile()) { diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index ede56e3ed..cefa2044e 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -102,7 +102,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito private $rootData; /** @var bool */ private $hasPartialPackages = false; - /** @var ?array */ + /** @var ?array */ private $partialPackagesByName = null; /** @@ -318,7 +318,10 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito } if ($this->hasPartialPackages()) { - return array_values($this->partialPackagesByName); + if (!is_array($this->partialPackagesByName)) { + throw new \LogicException('hasPartialPackages failed to initialize $this->partialPackagesByName'); + } + return $this->createPackages($this->partialPackagesByName, 'packages.json inline packages'); } throw new \LogicException('Composer repositories that have lazy providers and no available-packages list can not load the complete list of packages, use getPackageNames instead.'); @@ -609,6 +612,9 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito } if ($this->hasPartialPackages()) { + if (!is_array($this->partialPackagesByName)) { + throw new \LogicException('hasPartialPackages failed to initialize $this->partialPackagesByName'); + } foreach ($this->partialPackagesByName as $versions) { foreach ($versions as $candidate) { if (isset($result[$candidate['name']]) || !isset($candidate['provide'][$packageName])) { @@ -1314,7 +1320,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito $filename = str_replace('http://', 'https://', $filename); } - if ($retries) { + if ($retries > 0) { usleep(100000); continue; diff --git a/src/Composer/Repository/Vcs/GitDriver.php b/src/Composer/Repository/Vcs/GitDriver.php index 6b5cb2420..b91508acd 100644 --- a/src/Composer/Repository/Vcs/GitDriver.php +++ b/src/Composer/Repository/Vcs/GitDriver.php @@ -26,9 +26,9 @@ use Composer\Config; */ class GitDriver extends VcsDriver { - /** @var array Map of tag name to identifier */ + /** @var array Map of tag name (can be turned to an int by php if it is a numeric name) to identifier */ protected $tags; - /** @var array Map of branch name to identifier */ + /** @var array Map of branch name (can be turned to an int by php if it is a numeric name) to identifier */ protected $branches; /** @var string */ protected $rootIdentifier; @@ -172,7 +172,7 @@ class GitDriver extends VcsDriver $this->process->execute('git show-ref --tags --dereference', $output, $this->repoDir); foreach ($output = $this->process->splitLines($output) as $tag) { if ($tag && Preg::isMatch('{^([a-f0-9]{40}) refs/tags/(\S+?)(\^\{\})?$}', $tag, $match)) { - $this->tags[$match[2]] = $match[1]; + $this->tags[$match[2]] = (string) $match[1]; } } } diff --git a/src/Composer/Repository/Vcs/GitLabDriver.php b/src/Composer/Repository/Vcs/GitLabDriver.php index dd7cb65b2..3c45b4e73 100644 --- a/src/Composer/Repository/Vcs/GitLabDriver.php +++ b/src/Composer/Repository/Vcs/GitLabDriver.php @@ -46,7 +46,7 @@ class GitLabDriver extends VcsDriver private $project; /** - * @var array Keeps commits returned by GitLab API + * @var array Keeps commits returned by GitLab API as commit id => info */ private $commits = array(); diff --git a/src/Composer/Repository/Vcs/VcsDriverInterface.php b/src/Composer/Repository/Vcs/VcsDriverInterface.php index cdddd022b..b8c5e842d 100644 --- a/src/Composer/Repository/Vcs/VcsDriverInterface.php +++ b/src/Composer/Repository/Vcs/VcsDriverInterface.php @@ -62,14 +62,14 @@ interface VcsDriverInterface /** * Return list of branches in the repository * - * @return array Branch names as keys, identifiers as values + * @return array Branch names as keys, identifiers as values */ public function getBranches(); /** * Return list of tags in the repository * - * @return array Tag names as keys, identifiers as values + * @return array Tag names as keys, identifiers as values */ public function getTags(); diff --git a/src/Composer/Repository/VcsRepository.php b/src/Composer/Repository/VcsRepository.php index 993343188..65b4dc281 100644 --- a/src/Composer/Repository/VcsRepository.php +++ b/src/Composer/Repository/VcsRepository.php @@ -223,6 +223,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt } foreach ($driver->getTags() as $tag => $identifier) { + $tag = (string) $tag; $msg = 'Reading composer.json of ' . ($this->packageName ?: $this->url) . ' (' . $tag . ')'; if ($isVeryVerbose) { $this->io->writeError($msg); @@ -330,6 +331,7 @@ class VcsRepository extends ArrayRepository implements ConfigurableRepositoryInt } foreach ($branches as $branch => $identifier) { + $branch = (string) $branch; $msg = 'Reading composer.json of ' . ($this->packageName ?: $this->url) . ' (' . $branch . ')'; if ($isVeryVerbose) { $this->io->writeError($msg); diff --git a/src/Composer/Util/AuthHelper.php b/src/Composer/Util/AuthHelper.php index f49373397..28c4aba68 100644 --- a/src/Composer/Util/AuthHelper.php +++ b/src/Composer/Util/AuthHelper.php @@ -96,10 +96,7 @@ class AuthHelper if ($requiresSso) { $ssoUrl = $gitHubUtil->getSsoUrl($headers); - $message = sprintf( - 'GitHub API token requires SSO authorization. Authorize this token at ' . $ssoUrl, - $ssoUrl - ) . "\n"; + $message = 'GitHub API token requires SSO authorization. Authorize this token at ' . $ssoUrl . "\n"; $this->io->writeError($message); if (!$this->io->isInteractive()) { throw new TransportException('Could not authenticate against ' . $origin, 403); diff --git a/src/Composer/Util/Http/CurlDownloader.php b/src/Composer/Util/Http/CurlDownloader.php index b5d4f35d9..4a2a0d0c3 100644 --- a/src/Composer/Util/Http/CurlDownloader.php +++ b/src/Composer/Util/Http/CurlDownloader.php @@ -174,6 +174,9 @@ class CurlDownloader $curlHandle = curl_init(); $headerHandle = fopen('php://temp/maxmemory:32768', 'w+b'); + if (false === $headerHandle) { + throw new \RuntimeException('Failed to open a temp stream to store curl headers'); + } if ($copyTo) { $errorMessage = ''; diff --git a/src/Composer/Util/NoProxyPattern.php b/src/Composer/Util/NoProxyPattern.php index d06529eed..e8f14997b 100644 --- a/src/Composer/Util/NoProxyPattern.php +++ b/src/Composer/Util/NoProxyPattern.php @@ -159,6 +159,15 @@ class NoProxyPattern $net = unpack('C*', $network->ip); $mask = unpack('C*', $network->netmask); $ip = unpack('C*', $target->ip); + if (false === $net) { + throw new \RuntimeException('Could not parse network IP '.$network->ip); + } + if (false === $mask) { + throw new \RuntimeException('Could not parse netmask '.$network->netmask); + } + if (false === $ip) { + throw new \RuntimeException('Could not parse target IP '.$target->ip); + } for ($i = 1; $i < 17; ++$i) { if (($net[$i] & $mask[$i]) !== ($ip[$i] & $mask[$i])) { @@ -304,6 +313,12 @@ class NoProxyPattern $mask = unpack('C*', $netmask); $ip = unpack('C*', $rangeIp); $net = ''; + if (false === $mask) { + throw new \RuntimeException('Could not parse netmask '.$netmask); + } + if (false === $ip) { + throw new \RuntimeException('Could not parse range IP '.$rangeIp); + } for ($i = 1; $i < 17; ++$i) { $net .= chr($ip[$i] & $mask[$i]); diff --git a/src/Composer/Util/Svn.php b/src/Composer/Util/Svn.php index 562cf5fd2..865479e9a 100644 --- a/src/Composer/Util/Svn.php +++ b/src/Composer/Util/Svn.php @@ -217,8 +217,10 @@ class Svn $this->io->writeError("The Subversion server ({$this->url}) requested credentials:"); $this->hasAuth = true; - $this->credentials['username'] = $this->io->ask("Username: "); - $this->credentials['password'] = $this->io->askAndHideAnswer("Password: "); + $this->credentials = array( + 'username' => (string) $this->io->ask("Username: ", ''), + 'password' => (string) $this->io->askAndHideAnswer("Password: "), + ); $this->cacheCredentials = $this->io->askConfirmation("Should Subversion cache these credentials? (yes/no) "); @@ -345,8 +347,10 @@ class Svn $host = parse_url($this->url, PHP_URL_HOST); if (isset($authConfig[$host])) { - $this->credentials['username'] = $authConfig[$host]['username']; - $this->credentials['password'] = $authConfig[$host]['password']; + $this->credentials = array( + 'username' => $authConfig[$host]['username'], + 'password' => $authConfig[$host]['password'], + ); return $this->hasAuth = true; } @@ -366,8 +370,10 @@ class Svn return $this->hasAuth = false; } - $this->credentials['username'] = $uri['user']; - $this->credentials['password'] = !empty($uri['pass']) ? $uri['pass'] : ''; + $this->credentials = array( + 'username' => $uri['user'], + 'password' => !empty($uri['pass']) ? $uri['pass'] : '', + ); return $this->hasAuth = true; } diff --git a/tests/Composer/Test/IO/NullIOTest.php b/tests/Composer/Test/IO/NullIOTest.php index 18c5b8361..eecdc0aec 100644 --- a/tests/Composer/Test/IO/NullIOTest.php +++ b/tests/Composer/Test/IO/NullIOTest.php @@ -42,7 +42,7 @@ class NullIOTest extends TestCase { $io = new NullIO(); - $this->assertTrue(is_array($io->getAuthentications())); + $this->assertTrue(is_array($io->getAuthentications())); // @phpstan-ignore-line $this->assertEmpty($io->getAuthentications()); $this->assertEquals(array('username' => null, 'password' => null), $io->getAuthentication('foo')); } diff --git a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php index e20abaad5..86a016e55 100644 --- a/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php +++ b/tests/Composer/Test/Package/Loader/ArrayLoaderTest.php @@ -314,4 +314,15 @@ class ArrayLoaderTest extends TestCase $this->assertArrayHasKey('composer-plugin-api', $links); $this->assertSame('6.6.6', $links['composer-plugin-api']->getConstraint()->getPrettyString()); } + + public function testNoneStringVersion() + { + $config = array( + 'name' => 'acme/package', + 'version' => 1, + ); + + $package = $this->loader->load($config); + $this->assertSame('1', $package->getPrettyVersion()); + } } diff --git a/tests/Composer/Test/Plugin/PluginInstallerTest.php b/tests/Composer/Test/Plugin/PluginInstallerTest.php index b1db2df42..43022a20d 100644 --- a/tests/Composer/Test/Plugin/PluginInstallerTest.php +++ b/tests/Composer/Test/Plugin/PluginInstallerTest.php @@ -15,6 +15,7 @@ namespace Composer\Test\Plugin; use Composer\Composer; use Composer\Config; use Composer\Installer\PluginInstaller; +use Composer\Package\CompleteAliasPackage; use Composer\Package\CompletePackage; use Composer\Package\Loader\JsonLoader; use Composer\Package\Loader\ArrayLoader; @@ -44,7 +45,7 @@ class PluginInstallerTest extends TestCase protected $autoloadGenerator; /** - * @var CompletePackage[] + * @var array */ protected $packages; @@ -275,7 +276,7 @@ class PluginInstallerTest extends TestCase /** * @param string $newPluginApiVersion - * @param CompletePackage[] $plugins + * @param array $plugins * * @return void */