From 72ebce79e9ee8ee1cb11be04e835794d033d8999 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 5 Aug 2021 03:21:00 +0200 Subject: [PATCH 1/4] PHP 8.1/Tests: fix some deprecation warnings The default value for the `preg_split()` `$limit` parameter is `-1`, not `null`. Fixes numerous `preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated` notices when running the test suite. Ref: https://www.php.net/manual/en/function.preg-split.php --- tests/Composer/Test/AllFunctionalTest.php | 2 +- tests/Composer/Test/DependencyResolver/PoolBuilderTest.php | 2 +- tests/Composer/Test/InstallerTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Composer/Test/AllFunctionalTest.php b/tests/Composer/Test/AllFunctionalTest.php index 86e03f9e83bf..1cbf16ecc584 100644 --- a/tests/Composer/Test/AllFunctionalTest.php +++ b/tests/Composer/Test/AllFunctionalTest.php @@ -181,7 +181,7 @@ public function getTestFiles() private function parseTestFile($file) { - $tokens = preg_split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file), null, PREG_SPLIT_DELIM_CAPTURE); + $tokens = preg_split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file), -1, PREG_SPLIT_DELIM_CAPTURE); $data = array(); $section = null; diff --git a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php index 88ea4c029e2a..afa39e532b96 100644 --- a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php @@ -175,7 +175,7 @@ public function getIntegrationTests() protected function readTestFile(\SplFileInfo $file, $fixturesDir) { - $tokens = preg_split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), null, PREG_SPLIT_DELIM_CAPTURE); + $tokens = preg_split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), -1, PREG_SPLIT_DELIM_CAPTURE); $sectionInfo = array( 'TEST' => true, diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 3732941f0dfe..8be80420683e 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -484,7 +484,7 @@ public function loadIntegrationTests($path) protected function readTestFile(\SplFileInfo $file, $fixturesDir) { - $tokens = preg_split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), null, PREG_SPLIT_DELIM_CAPTURE); + $tokens = preg_split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), -1, PREG_SPLIT_DELIM_CAPTURE); $sectionInfo = array( 'TEST' => true, From 9eefb21f7becfb6934997116649e1588d584dfbe Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 5 Aug 2021 05:04:23 +0200 Subject: [PATCH 2/4] PHP 8.1/NoProxyPattern: fix deprecation warning The default value for the `preg_split()` `$limit` parameter is `-1`, not `null`. Fixes some `preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated` notices when running the test suite. ``` Deprecation triggered by Composer\Test\Util\Http\ProxyManagerTest::testGetProxyForRequest: preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated Stack trace: 0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 42) 1 src/Composer/Util/NoProxyPattern.php(42): preg_split('...', '...', NULL, 1) 2 src/Composer/Util/Http/ProxyManager.php(148): Composer\Util\NoProxyPattern->__construct('...') 3 src/Composer/Util/Http/ProxyManager.php(50): Composer\Util\Http\ProxyManager->initProxyData() 4 src/Composer/Util/Http/ProxyManager.php(59): Composer\Util\Http\ProxyManager->__construct() 5 tests/Composer/Test/Util/Http/ProxyManagerTest.php(75): Composer\Util\Http\ProxyManager::getInstance() ... ``` Ref: https://www.php.net/manual/en/function.preg-split.php --- src/Composer/Util/NoProxyPattern.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer/Util/NoProxyPattern.php b/src/Composer/Util/NoProxyPattern.php index c391a7535cd5..b8175f3c96e8 100644 --- a/src/Composer/Util/NoProxyPattern.php +++ b/src/Composer/Util/NoProxyPattern.php @@ -39,7 +39,7 @@ class NoProxyPattern */ public function __construct($pattern) { - $this->hostNames = preg_split('{[\s,]+}', $pattern, null, PREG_SPLIT_NO_EMPTY); + $this->hostNames = preg_split('{[\s,]+}', $pattern, -1, PREG_SPLIT_NO_EMPTY); $this->noproxy = empty($this->hostNames) || '*' === $this->hostNames[0]; } From d45cc34df9e51821e94f7bc030441b7dc4419793 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 5 Aug 2021 05:11:24 +0200 Subject: [PATCH 3/4] PHP 8.1: fix deprecation warnings / http_build_query() This fixes all relevant calls to the PHP native `http_build_query()` function. The second parameter of which is the _optional_ `$numeric_prefix` parameter which expects a `string`. A parameter being optional, however, does not automatically make it nullable. As of PHP 8.1, passing `null` to a non-nullable PHP native function will generate a deprecation notice. In this case, these function calls yielded a `http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated` notice. Changing the `null` to an empty string fixes this without BC-break. Fixes a few deprecation warnings found when running the tests. Refs: * https://www.php.net/manual/en/function.http-build-query.php * https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg --- src/Composer/Repository/Vcs/BitbucketDriver.php | 6 +++--- src/Composer/Util/GitLab.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Composer/Repository/Vcs/BitbucketDriver.php b/src/Composer/Repository/Vcs/BitbucketDriver.php index e1c45acdef10..1a9a8f6d8bb9 100644 --- a/src/Composer/Repository/Vcs/BitbucketDriver.php +++ b/src/Composer/Repository/Vcs/BitbucketDriver.php @@ -86,7 +86,7 @@ protected function getRepoData() $this->repository, http_build_query( array('fields' => '-project,-owner'), - null, + '', '&' ) ); @@ -286,7 +286,7 @@ public function getTags() 'fields' => 'values.name,values.target.hash,next', 'sort' => '-target.date', ), - null, + '', '&' ) ); @@ -330,7 +330,7 @@ public function getBranches() 'fields' => 'values.name,values.target.hash,values.heads,next', 'sort' => '-target.date', ), - null, + '', '&' ) ); diff --git a/src/Composer/Util/GitLab.php b/src/Composer/Util/GitLab.php index 1ff2fbb96e61..1345eaff3844 100644 --- a/src/Composer/Util/GitLab.php +++ b/src/Composer/Util/GitLab.php @@ -172,7 +172,7 @@ private function createToken($scheme, $originUrl) 'username' => $username, 'password' => $password, 'grant_type' => 'password', - ), null, '&'); + ), '', '&'); $options = array( 'retry-auth-failure' => false, 'http' => array( From 487ed92e371d54a86237534994f7f6b7f6f31cb5 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 5 Aug 2021 18:28:06 +0200 Subject: [PATCH 4/4] PHP 8.1: fix deprecation notices / PharData::__construct() This fixes all relevant calls to the PHP native `PharData::__construct()` method. The second parameter of this method is the _optional_ `$flags` parameter which expects an `int` of flags to be passed to the `Phar` parent class `RecursiveDirectoryIterator`. Fixed by passing the default value for the `$flags` parameter as per the `RecursiveDirectoryIterator::__construct()` method. The third parameter of the method is the _optional_ `$alias` parameter which expects an `string`. Fixed by passing an empty string. Fixes various notices along the lines of: ``` Deprecation triggered by Composer\Test\Package\Archiver\ArchiveManagerTest::testArchiveTar: PharData::__construct(): Passing null to parameter #2 ($flags) of type int is deprecated Stack trace: 0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 55) 1 src/Composer/Package/Archiver/PharArchiver.php(55): PharData->__construct('...', NULL, NULL, 2) 2 src/Composer/Package/Archiver/ArchiveManager.php(193): Composer\Package\Archiver\PharArchiver->archive('...', '...', '...', Array, false) 3 tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php(65): Composer\Package\Archiver\ArchiveManager->archive(Object(Composer\Package\CompletePackage), '...', '...') ... ``` Refs: * https://www.php.net/manual/en/phardata.construct.php * https://www.php.net/manual/en/recursivedirectoryiterator.construct.php --- src/Composer/Package/Archiver/PharArchiver.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Composer/Package/Archiver/PharArchiver.php b/src/Composer/Package/Archiver/PharArchiver.php index f9a392353e8c..955d1b3c93e9 100644 --- a/src/Composer/Package/Archiver/PharArchiver.php +++ b/src/Composer/Package/Archiver/PharArchiver.php @@ -52,7 +52,12 @@ public function archive($sources, $target, $format, array $excludes = array(), $ $target = $filename . '.tar'; } - $phar = new \PharData($target, null, null, static::$formats[$format]); + $phar = new \PharData( + $target, + \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO, + '', + static::$formats[$format] + ); $files = new ArchivableFilesFinder($sources, $excludes, $ignoreFilters); $filesOnly = new ArchivableFilesFilter($files); $phar->buildFromIterator($filesOnly, $sources);