From d2db5b666674a4dd678820d9eddef6ec49e10b47 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Thu, 5 Aug 2021 18:28:06 +0200 Subject: [PATCH] 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), '...', '...') ... ``` Additionally, this fixes three `preg_match(): Passing null to parameter #2 ($subject) of type string is deprecated` notices. 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..baace812e15b 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);